◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
Articles/API / SDK
◈ API / SDK/2026-04-29Intermediate

When Gemini API URL Context Returns Nothing: A Diagnostic Walkthrough

You passed a URL and got a generic answer, an empty retrieval record, or failures on one particular site. A walkthrough for isolating why Gemini API URL Context isn't working, based on the official docs as of December 2026: the Interactions API form, the retrieval result step, and the documented limits.

gemini-api291url-contexttroubleshooting98tools

"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.

ItemWhat the docs say (December 2026)
URLs per requestUp to 20
Content size per URLUp to 34 MB
Supported contentText (HTML, JSON, plain text, XML, CSS, JavaScript, CSV, RTF), images (PNG, JPEG, BMP, WebP), PDF
Not supportedPaywalled content, YouTube videos, Google Workspace files such as Docs or Sheets, video and audio files
AccessMust 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 followingOnly the URLs you provide; nested links are not followed
BillingRetrieved 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:

SymptomLikely causeHow to checkFix
Generic answer and no retrieval recordTool not called: weak instruction, or the URL isn't plain text in the promptCheck whether the url_context_result step (or url_context_metadata) is emptySay "retrieve this URL before answering" explicitly; write the URL as plain text including the protocol (https)
Retrieval recorded but failedLogin required, blocked by robots.txt or a firewall, paywalledOpen the URL in a logged-out browserPublish the content publicly or switch to passing it as a file
Status is unsafeFailed the safety checkRead the status in the retrieval recordDon't pass that URL; if you need the content, verify it yourself and pass it another way
Retrieval succeeded but content is staleA copy from the internal index was usedCompare the page's update time with what the answer saysIf freshness matters, fetch it yourself and pass the text
Summary of an almost empty pageBody rendered later by JavaScript; initial HTML is nearly emptyView source and see whether the body is thereSave the rendered HTML yourself and pass it as text or a file
Very slow or timing outToo many URLs, and one slow page drags the whole requestSplit into single URLs and compare response timesConfirm 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.

ApproachGood fitPoor fit
URL ContextYou know which public pages to readBehind a login, must be current, JavaScript-rendered
Grounding with Google SearchYou want the model to find which pages matterYou want answers grounded only in specific pages
URL Context plus SearchSearch finds candidates, then URL Context reads them closelyYou need strict control over sources
Fetch yourself and pass the textFreshness matters, you manage an allowlist, you need rendered HTMLYou 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_result or url_context_metadata) logged on every call
  • Retrieved-content tokens in usage checked 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_instruction and 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.

Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

◈ API / SDK2026-10-19
When 404 and 429 Show Up in the Same Gemini API Log, Check the Model Name Before the Quota
A triage order for Gemini API logs that mix 404 NOT_FOUND and 429 RESOURCE_EXHAUSTED, plus a small Python script that separates a bad model name from a real quota limit without generating anything.
◈ API / SDK2026-10-16
The Day /models Returns 200 but generateContent Returns 403 — Decide Your Triage Order Before It Happens
A triage order for the case where listing models succeeds with 200 but generation fails with 403 permission_denied. Includes a small diagnostic script that checks key, project, and billing in turn, why you should not retry a 403, and how to assemble what support needs.
◈ API / SDK2026-05-20
Gemini API Streaming Works Locally but Buffers in Production — Fixing Cloud Run, Vercel, and Cloudflare
Streaming responses flow token-by-token in local dev, then arrive as one big blob in production. A walkthrough of the five most common causes — Cloud Run timeouts, Vercel runtime mismatch, Cloudflare Workers proxying, server-side text() pitfalls, and client-side decoding — with the fixes I use on my own sites.