Issue with URL Context Tooling

Does URL context tool internally use Google Search tool?

When using the URL context tool, the response includes both groundingMetadata and urlContextMetadata in the candidates array. I also noticed that when using both URL context and Google Search together, the response is the same.

1 Like

Hello,

Welcome to the Forum!

URL context and Google Search are two different tools. With URL context, Gemini can access the content of the provided URL directly and use it for generation. In contrast, Google Search works more like entering your prompt into Google, retrieving the search results, and then using that information for generation.

For detailed information, I would recommend going through URL Context and Google search documentation.

If url context and google search are two different tools then why I’m getting groundingMetadata in response when i am only using url context tool

@Lalit_Kumar any update on this

Hello,

Could you please share the complete response so that I can analyze your issue better?

@Lalit_Kumar

below is the candidate array

[
  {
    "content": {
      "parts": [
        {
          "text": "\nHere's a breakdown of the pricing for Gemini image models: \n\n **Gemini 2.5 Flash Image Preview** \n\n *   **Input price (text/image):** $0.30 per 1M tokens (paid tier, standard mode); $0.15 per 1M tokens (paid tier, batch mode). \n *   **Output price:** $0.039 per image for images up to 1024x1024px (paid tier, standard mode); $0.0195 per image for images up to 1024x1024px (paid tier, batch mode). \n *   Image output is priced at $30 per 1,000,000 tokens, with 1290 tokens consumed per image up to 1024x1024px, equating to $0.039 per image. \n\n **Gemini 2.0 Flash** \n\n *   **Image generation pricing:** $0.039 per image (paid tier, standard mode); $0.0195 per image (paid tier, batch mode). \n *   Image output is priced at $30 per 1,000,000 tokens, with 1290 tokens consumed per image up to 1024x1024px, equating to $0.039 per image. \n\n **Imagen 4** \n\n *   **Imagen 4 Fast image price:** $0.02 per image (paid tier). \n *   **Imagen 4 Standard image price:** $0.04 per image (paid tier). \n *   **Imagen 4 Ultra image price:** $0.06 per image (paid tier). \n\n **Imagen 3** \n\n *   **Image price:** $0.03 per image (paid tier). \n\n Google AI Studio usage for these models is free in all available regions."
        }
      ],
      "role": "model"
    },
    "finishReason": "STOP",
    "urlContextMetadata": {
      "urlMetadata": [
        {
          "retrievedUrl": "https://ai.google.dev/gemini-api/docs/pricing",
          "urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
        },
        {
          "retrievedUrl": "https://ai.google.dev/gemini-api/docs/pricing",
          "urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
        }
      ]
    },
    "groundingMetadata": {
      "groundingChunks": [
        {
          "web": {
            "uri": "https://ai.google.dev/gemini-api/docs/pricing",
            "title": "Gemini Developer API Pricing | Gemini API | Google AI for Developers"
          }
        },
        {
          "web": {
            "uri": "https://ai.google.dev/gemini-api/docs/pricing",
            "title": "Gemini Developer API Pricing | Gemini API | Google AI for Developers"
          }
        }
      ],
      "groundingSupports": [
        {
          "segment": {
            "startIndex": 102,
            "endIndex": 228,
            "text": "*   **Input price (text/image):** $0.30 per 1M tokens (paid tier, standard mode); $0.15 per 1M tokens (paid tier, batch mode)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 231,
            "endIndex": 398,
            "text": "*   **Output price:** $0.039 per image for images up to 1024x1024px (paid tier, standard mode); $0.0195 per image for images up to 1024x1024px (paid tier, batch mode)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 401,
            "endIndex": 541,
            "text": "*   Image output is priced at $30 per 1,000,000 tokens, with 1290 tokens consumed per image up to 1024x1024px, equating to $0.039 per image."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 569,
            "endIndex": 690,
            "text": "*   **Image generation pricing:** $0.039 per image (paid tier, standard mode); $0.0195 per image (paid tier, batch mode)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 693,
            "endIndex": 833,
            "text": "*   Image output is priced at $30 per 1,000,000 tokens, with 1290 tokens consumed per image up to 1024x1024px, equating to $0.039 per image."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 853,
            "endIndex": 916,
            "text": "*   **Imagen 4 Fast image price:** $0.02 per image (paid tier)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 919,
            "endIndex": 986,
            "text": "*   **Imagen 4 Standard image price:** $0.04 per image (paid tier)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 989,
            "endIndex": 1053,
            "text": "*   **Imagen 4 Ultra image price:** $0.06 per image (paid tier)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 1073,
            "endIndex": 1122,
            "text": "*   **Image price:** $0.03 per image (paid tier)."
          },
          "groundingChunkIndices": [1]
        },
        {
          "segment": {
            "startIndex": 1126,
            "endIndex": 1199,
            "text": "Google AI Studio usage for these models is free in all available regions."
          },
          "groundingChunkIndices": [1]
        }
      ]
    },
    "index": 0
  }
]

And this is usageMetadata

{
  promptTokenCount: 71,
  candidatesTokenCount: 477,
  totalTokenCount: 15598,
  cachedContentTokenCount: 33,
  promptTokensDetails: [ { modality: 'TEXT', tokenCount: 71 } ],
  cacheTokensDetails: [ { modality: 'TEXT', tokenCount: 33 } ],
  toolUsePromptTokenCount: 15050,
  toolUsePromptTokensDetails: [ { modality: 'TEXT', tokenCount: 15050 } ]
}

Tool used-

const tools = [
      { urlContext: {} },
    ];

Model and query

const model = 'gemini-2.5-flash';
const contents = [
      {
        role: 'user',
        parts: [
          {
            text: `url- https://ai.google.dev/gemini-api/docs/pricing
                   user_query- what is the pricing for gemini image models`,
          },
        ],
      },
    ];

Gemini’s Google Search grounding and URL context both utilize grounding chunks for context, but the difference is that Google Search grounding finds and accesses multiple links across the public web in real time, while URL context only fetches from explicitly specified URLs.