"I gave it the URL, and it answered with something you could find anywhere." I spent one evening staring at that result over and over while testing a summarizer built on URL Context. No exception. HTTP 200. A plausible-looking answer. And none of the actual page content anywhere in it.
At first I kept rewording the prompt. It didn't help. The cause was never the prompt — either the tool wasn't being called, or it was called and the fetch failed.
Check the fact of retrieval before you question the quality of the answer. That's the order I work in now. Below: where to see that fact, likely causes by symptom, and when to drop URL Context in favor of something else. The limits quoted here come from re-reading the official URL context page in December 2026.
Start with the documented limits
Ruling out what the tool simply can't read saves a lot of wasted investigation.
| Item | What the docs say (December 2026) |
|---|---|
| URLs per request | Up to 20 |
| Content size per URL | Up to 34 MB |
| Supported content | Text (HTML, JSON, plain text, XML, CSS, JavaScript, CSV, RTF), images (PNG, JPEG, BMP, WebP), PDF |
| Not supported | Paywalled content, YouTube videos, Google Workspace files such as Docs or Sheets, video and audio files |
| Access | Must be publicly accessible. No localhost or 127.0.0.1, private networks, or tunneling services like ngrok. Pages behind a login can't be fetched |
| Link following | Only the URLs you provide; nested links are not followed |
| Billing | Retrieved content counts as input tokens |
This table settles about half the cases. A localhost URL during development, a page exposed through ngrok, a screen that only exists after login — no amount of code changes will make those work. What sits outside the spec has to be brought inside it. For YouTube, the docs point you to video understanding rather than URL Context.
Where to see whether retrieval happened
The current docs lead with the Interactions API. You enable the tool with tools=[{"type": "url_context"}], and the response carries two kinds of evidence: url_citation annotations on the text blocks (which segment came from which URL), and a url_context_result step recording each retrieval attempt (status and retrieved URL). The docs describe the latter as "mainly useful for debugging" — which is exactly what we're doing.
This snippet gets the summary while always printing the retrieval record and citations. It assumes Python google-genai 2.0.0 or newer.
# Use URL Context and always print the retrieval record and citations
from google import genai
client = genai.Client()
url = "https://ai.google.dev/gemini-api/docs/url-context"
interaction = client.interactions.create(
model="gemini-4-hydrogen",
input=f"Retrieve the page below first, then give me its three main points: {url}",
tools=[{"type": "url_context"}],
)
saw_retrieval = False
for step in interaction.steps:
if step.type == "url_context_result":
saw_retrieval = True
print("retrieval record:", step) # status (e.g. unsafe) and retrieved URL
elif step.type == "model_output":
for block in step.content:
if block.type == "text":
print(block.text)
for a in (block.annotations or []):
if a.type == "url_citation":
print(" source:", a.title, a.url)
if not saw_retrieval:
print("No retrieval record — the tool may not have been called")
print("usage:", interaction.usage)The docs only say the retrieval step contains "status, retrieved URL," so the code prints the whole step. For the first few runs, read that output by eye to learn the exact field names in your SDK version, then settle on how to extract them for logging.
Also look at usage. In the official example, retrieved page content is counted separately as tool_use_input_tokens. If that's zero or tiny, the page body wasn't read. And when a bill comes in higher than expected, this is the first place to look.
If you're still on generate_content, the tool goes in config as types.Tool(url_context=types.UrlContext()), and per-URL retrieved_url and url_retrieval_status values (such as URL_RETRIEVAL_STATUS_SUCCESS) appear under candidates[0].url_context_metadata.url_metadata. That metadata can come back as None, so check for empty first — otherwise you'll hit an AttributeError at exactly the wrong moment.
Symptom-by-symptom triage
With the retrieval record in hand, narrow it down:
| Symptom | Likely cause | How to check | Fix |
|---|---|---|---|
| Generic answer and no retrieval record | Tool not called: weak instruction, or the URL isn't plain text in the prompt | Check whether the url_context_result step (or url_context_metadata) is empty | Say "retrieve this URL before answering" explicitly; write the URL as plain text including the protocol (https) |
| Retrieval recorded but failed | Login required, blocked by robots.txt or a firewall, paywalled | Open the URL in a logged-out browser | Publish the content publicly or switch to passing it as a file |
Status is unsafe | Failed the safety check | Read the status in the retrieval record | Don't pass that URL; if you need the content, verify it yourself and pass it another way |
| Retrieval succeeded but content is stale | A copy from the internal index was used | Compare the page's update time with what the answer says | If freshness matters, fetch it yourself and pass the text |
| Summary of an almost empty page | Body rendered later by JavaScript; initial HTML is nearly empty | View source and see whether the body is there | Save the rendered HTML yourself and pass it as text or a file |
| Very slow or timing out | Too many URLs, and one slow page drags the whole request | Split into single URLs and compare response times | Confirm success with a few, then scale up and send in batches |
On the first row: in my own code I once had a system_instruction saying "do not consult external resources," and the tool quietly stopped being called. Check that your system instruction and your tool configuration aren't contradicting each other. Shortened URLs may not be followed to their destination, so expand them beforehand.
The stale-content row only made sense to me after I read how the tool works. That's next.
A common misconception: URL Context always fetches the live page
According to the docs, URL Context retrieves in two steps. It first looks for a copy in an internal index, and only if the page isn't there — a very new page, for example — does it fall back to a live fetch. The docs frame this as balancing speed, cost and freshness.
Which means a page you updated a few minutes ago can still be answered from its older version. I ran into this summarizing a pricing page and getting pre-revision numbers back. I rewrote the prompt three times before I found the explanation in the docs; had I read it first, I might have kept that evening.
For anything where you need the current value — prices, stock, an announcement that just went up — fetch the page in your own code and pass the body as text.
The other misconception is that it follows links on the page. The docs state it retrieves only the URLs you provide, not nested links. Handing it a table of contents won't get you every chapter; list each page URL you want read.
URL Context, search, or fetching it yourself
Before forcing something to work, it's worth asking whether it's the right tool.
| Approach | Good fit | Poor fit |
|---|---|---|
| URL Context | You know which public pages to read | Behind a login, must be current, JavaScript-rendered |
| Grounding with Google Search | You want the model to find which pages matter | You want answers grounded only in specific pages |
| URL Context plus Search | Search finds candidates, then URL Context reads them closely | You need strict control over sources |
| Fetch yourself and pass the text | Freshness matters, you manage an allowlist, you need rendered HTML | You don't want the implementation and upkeep |
In one sentence: known pages, URL Context; unknown pages, Search; current values, fetch it yourself. Both tools can sit in the same tools array, and the docs say Gemini 3 and later models support combining built-in tools with function calling.
If you read the same URLs over and over, your own cache layer is faster and saves input tokens. And information whose automated retrieval is restricted by law or terms of service shouldn't be pulled in at all.
A defensive wrapper for production
In production I always return to the caller which URLs made it and which didn't, by checking the requested URLs against the citations and keeping the raw retrieval records.
# Compare requested URLs against citations and keep retrieval records
from google import genai
def summarize_with_sources(client: genai.Client, prompt: str, urls: list[str]) -> dict:
full = prompt + "\n\nRetrieve these URLs before answering:\n" + "\n".join(urls)
it = client.interactions.create(
model="gemini-4-hydrogen",
input=full,
tools=[{"type": "url_context"}],
)
records, text, cited = [], [], set()
for step in it.steps:
if step.type == "url_context_result":
records.append(str(step)) # keep it whole until you know the field names
elif step.type == "model_output":
for b in step.content:
if b.type == "text":
text.append(b.text)
cited |= {a.url for a in (b.annotations or []) if a.type == "url_citation"}
not_cited = [u for u in urls if u not in cited]
return {"text": "\n".join(text), "records": records, "not_cited": not_cited}The field to watch is not_cited. Pass five URLs, get citations for three, and you'll never notice by reading the answer alone. An uncited URL isn't necessarily a failed fetch, but being able to show "this source wasn't used" in the UI already prevents a lot of misunderstanding. Two out of five silently dropping is the scariest state to be in.
I use URL Context in my own indie app work to summarize store policy updates and SDK release pages. Early on I threw the retrieval records away — and only noticed weeks later that one policy page had been redirecting to a login screen the entire time, so its changes never reached the summaries. Since then I aggregate retrieval records by domain, and a domain that keeps failing either comes off the allowlist or moves to self-fetching.
Checklist
Go top to bottom; fix the first item that applies.
- Retrieval record (
url_context_resultorurl_context_metadata) logged on every call - Retrieved-content tokens in
usagechecked to confirm the page was read - URLs written as plain text including the protocol (https)
- No shortened URLs
- No localhost, private network, tunneling service or login-only pages
- No paywalled pages, YouTube, Workspace files, video or audio
- No conflict between
system_instructionand the tool configuration - No pages whose body is rendered only by JavaScript
- No reliance on the index copy where freshness matters
I don't touch prompt wording or switch models until all nine are clear.
Where you'll likely get stuck next
Once retrieval is stable, the next snags tend to be response time and file handling. For the timeouts themselves, see what to check first when DEADLINE_EXCEEDED keeps happening. If you end up passing login-only content or rendered HTML as files, mind the storage window described in why your Gemini File URI stops working the next day. And if you want to show retrieved content as evidence in your UI, the approach in building citations into a Gemini RAG pipeline carries over directly.
One thing you can do today: add a single log line for when the retrieval record comes back empty. What lands in that log will tell you half the story.