POST
/
v1beta
/
models
/
{model}
:generateContent
curl -X POST "https://api.example.com/v1beta/models/gemini-2.5-pro:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Summarize the content from these URLs"
          }
        ]
      }
    ],
    "tools": [
      {
        "urlContext": {
          "urls": [
            "https://example.com/article1",
            "https://example.com/article2"
          ]
        }
      }
    ]
  }'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Based on the provided URLs, here is a summary: The first article discusses recent developments in AI technology, while the second article covers the impact of machine learning on healthcare..."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}
Official documentation: https://ai.google.dev/gemini-api/docs/url-context
The URL context tool allows you to provide additional context to the model in the form of URLs. By adding URLs to your request, the model will access the content from those web pages to inform and improve the quality of its responses.

Use Cases

  • Extract data: Extract specific information like prices, names, or key findings from multiple URLs
  • Compare documents: Analyze multiple reports, articles, or PDFs to find differences and track trends
  • Synthesize content: Combine information from multiple source URLs to generate accurate summaries, blog posts, or reports
  • Analyze code: Point to GitHub repositories or technical documentation to explain code, generate setup instructions, or answer questions

Request Parameters

key
string
required
API key.
contents
array
required
Content array.Each content object contains:
  • role (string): Role (user or model)
  • parts (array): Content parts array
tools
array
Tools configuration including URL context.
  • urlContext (object): Enable URL context capability
    • urls (array): Array of URLs to use as context
generationConfig
object
Generation configuration.
  • temperature (number): Sampling temperature
  • topP (number): Nucleus sampling parameter

Response

Returns generated content informed by the provided URL context.
curl -X POST "https://api.example.com/v1beta/models/gemini-2.5-pro:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Summarize the content from these URLs"
          }
        ]
      }
    ],
    "tools": [
      {
        "urlContext": {
          "urls": [
            "https://example.com/article1",
            "https://example.com/article2"
          ]
        }
      }
    ]
  }'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Based on the provided URLs, here is a summary: The first article discusses recent developments in AI technology, while the second article covers the impact of machine learning on healthcare..."
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}