M37Labs Logo
← Knowledge base

The URL context tool lets you provide additional context to the models in the form of…

knowledge-baseBy Team M37Labs
https://ai.google.dev/gemini-api/docs/url-context

The URL context tool lets you provide additional context to the models in the form of URLs. By including URLs in your request, the model will access the content from those pages (as long as it’s not a URL type listed in the limitations section) to inform and enhance its response.
The URL context tool is useful for tasks like the following:
• Extract Data: Pull specific info like prices, names, or key findings from multiple URLs.
• Compare Documents: Analyze multiple reports, articles, or PDFs to identify differences and track trends.
• Synthesize & Create Content: Combine information from several source URLs to generate accurate summaries, blog posts, or reports.
• Analyze Code & Docs: Point to a GitHub repository or technical documentation to explain code, generate setup instructions, or answer questions.

Code Snippet
from google import genai
from google.genai.types import Tool, GenerateContentConfig

client = genai.Client()
model_id = "gemini-2.5-flash"

tools = [
  {"url_context": {}},
]

url1 = "<https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592>"
url2 = "<https://www.allrecipes.com/recipe/21151/simple-whole-roast-chicken/>"

response = client.models.generate_content(
    model=model_id,
    contents=f"Compare the ingredients and cooking times from the recipes at {url1} and {url2}",
    config=GenerateContentConfig(
        tools=tools,
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)

# For verification, you can inspect the metadata to see which URLs the model retrieved
print(response.candidates[0].url_context_metadata)
Aug 21, 2025 • 6:48 AM