AI Engineer Guide

Automatically fetch URL content on Google's Gemini Models

Google’s Gemini LLM can now have support for automatically fetching contents from URL using their URL context tool

It’s similar to the web search tool provided by OpenAI and other providers but here you give the explicit URL and the AI model will fetch it on its end.

By doing so, you avoid having to fetch the content on your end (saving network bandwidth) and having to pass it to AI models manually.

Use Cases

Example

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "What are the recent posts in https://aiengineerguide.com in markdown format with link to it ?"}
              ]
          }
      ],
      "tools": [
          {
              "url_context": {}
          }
      ]
      }'

Make sure to replace this with your GEMINI_API_KEY

Response
{
"candidates": [
  {
    "content": {
      "parts": [
        {
          "text": "Here are the recent posts from AIEngineerGuide.com:\n\n*   [OpenAI's Cheatsheet for Coding with GPT-5](https://aiengineerguide.com) (August 18, 2025)\n*   [Perplexity Pro Users Get $5 Free LLM API Credits Every Month](https://aiengineerguide.com) (August 17, 2025)\n*   [Gemini CLI Custom Slash Commands](https://aiengineerguide.com) (August 16, 2025)\n*   [Gemma 3 270M - Google's Lightweight On‑Device Model](https://aiengineerguide.com) (August 15, 2025)\n*   [How to build app like Loveable](https://aiengineerguide.com) (August 14, 2025)"
        }
      ],
      "role": "model"
    },
    "finishReason": "STOP",
    "index": 0,
    "groundingMetadata": {
      "groundingChunks": [
        {
          "web": {
            "uri": "https://aiengineerguide.com",
            "title": "AI Engineer Guide"
          }
        }
      ],
      "groundingSupports": [
        {
          "segment": {
            "startIndex": 1,
            "endIndex": 52,
            "text": "Here are the recent posts from AIEngineerGuide.com:"
          },
          "groundingChunkIndices": [
            0
          ]
        },
        {
          "segment": {
            "startIndex": 54,
            "endIndex": 148,
            "text": "*   [OpenAI's Cheatsheet for Coding with GPT-5](https://aiengineerguide.com) (August 18, 2025)"
          },
          "groundingChunkIndices": [
            0
          ]
        },
        {
          "segment": {
            "startIndex": 149,
            "endIndex": 262,
            "text": "*   [Perplexity Pro Users Get $5 Free LLM API Credits Every Month](https://aiengineerguide.com) (August 17, 2025)"
          },
          "groundingChunkIndices": [
            0
          ]
        },
        {
          "segment": {
            "startIndex": 263,
            "endIndex": 348,
            "text": "*   [Gemini CLI Custom Slash Commands](https://aiengineerguide.com) (August 16, 2025)"
          },
          "groundingChunkIndices": [
            0
          ]
        },
        {
          "segment": {
            "startIndex": 349,
            "endIndex": 455,
            "text": "*   [Gemma 3 270M - Google's Lightweight On‑Device Model](https://aiengineerguide.com) (August 15, 2025)"
          },
          "groundingChunkIndices": [
            0
          ]
        },
        {
          "segment": {
            "startIndex": 456,
            "endIndex": 539,
            "text": "*   [How to build app like Loveable](https://aiengineerguide.com) (August 14, 2025)"
          },
          "groundingChunkIndices": [
            0
          ]
        }
      ]
    },
    "urlContextMetadata": {
      "urlMetadata": [
        {
          "retrievedUrl": "https://aiengineerguide.com",
          "urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
        }
      ]
    }
  }
],
"usageMetadata": {
  "promptTokenCount": 21,
  "candidatesTokenCount": 212,
  "totalTokenCount": 584,
  "promptTokensDetails": [
    {
      "modality": "TEXT",
      "tokenCount": 21
    }
  ],
  "toolUsePromptTokenCount": 279,
  "toolUsePromptTokensDetails": [
    {
      "modality": "TEXT",
      "tokenCount": 279
    }
  ],
  "thoughtsTokenCount": 72
},
"modelVersion": "gemini-2.5-flash",
"responseId": "hrqkaPKeFrTRz7IP8s3JgQw"
}

What’s in the response?

When you use URL context tool, you’ll be getting url_context_metadata object in the response.

It has url_metadata in it which you can use to verify whether the URL is successfully loaded or not.

{
  "candidates": [
    {
      ...
      "urlContextMetadata": {
        "urlMetadata": [
          {
            "retrievedUrl": "https://example.com",
            "urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
          },
          {
            "retrievedUrl": "https://example2.com",
            "urlRetrievalStatus": "URL_RETRIEVAL_STATUS_ERROR"
          }
        ]
      }
    }
}

And these are the possible values for urlRetrievalStatus

EnumDescription
URL_RETRIEVAL_STATUS_UNSPECIFIEDDefault value. This value is unused.
URL_RETRIEVAL_STATUS_SUCCESSURL retrieval is successful.
URL_RETRIEVAL_STATUS_ERRORURL retrieval failed due to error.
URL_RETRIEVAL_STATUS_PAYWALLURL retrieval failed because the content is behind a paywall.
URL_RETRIEVAL_STATUS_UNSAFEURL retrieval failed because the content is unsafe.

You also get usage metadata in it as well

{
  "usageMetadata": {
    "promptTokenCount": 21,
    "candidatesTokenCount": 212,
    "totalTokenCount": 584,
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 21
      }
    ],
    "toolUsePromptTokenCount": 279,
    "toolUsePromptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 279
      }
    ],
    "thoughtsTokenCount": 72
  }
}

Refer to Gemini Developer API Pricing for more details about pricing of each models

Supported Models

Currently this feature is supported in the following models

Limitations

Supported Content Type

2025-08-19-at-23.45.062x.png

References

#Google-Gemini

Stay Updated

Get the latest AI engineering insights delivered to your inbox.

No spam. Unsubscribe at any time.