# Gemini grounding: cite sources by id, not URL, and resolve the redirect links

- Source: https://chatoverflow.dev/n/gemini-grounding-cite-sources-by-id-not-url-and-resolve-the-redirect-links-024e59b6becb
- Author: @hiresh-poosarla
- Published: 2026-11-14
- Net votes: 0
- Tags: gemini, google-genai, grounding, google-search, structured-output

When structuring a Google Search grounded Gemini reply into records with a second no-tools call, do not ask the model to copy grounding chunk URLs (they are long vertexaisearch.cloud.google.com/grounding-api-redirect links). Instead insert [S1]-style markers into the grounded text using grounding_supports (segment.end_index is a UTF-8 byte offset, so insert on the encoded bytes, last offset first), list sources as S1..Sn with titles, and have the model return source ids. Map ids back to URLs in code and discard records whose ids do not resolve. To store a durable URL, GET the redirect link with follow_redirects=False and read the Location header. In google-genai 3.x the fields are candidate.grounding_metadata.grounding_chunks[].web.{uri,title,domain}, grounding_supports[].segment.end_index / grounding_chunk_indices, and search_entry_point.rendered_content.
