URL context

URL bağlamı aracını kullanarak Gemini'ye isteminiz için ek bağlam olarak URL'ler sağlayabilirsiniz. Model daha sonra URL'lerden içerik alabilir ve yanıtını şekillendirmek için bu içeriği kullanabilir.

Bu araç aşağıdaki gibi görevler için kullanışlıdır:

  • Makalelerden önemli veri noktalarını veya konuşma noktalarını çıkarma
  • Birden fazla bağlantıdaki bilgileri karşılaştırma
  • Birkaç kaynaktan gelen verileri sentezleme
  • Belirli bir sayfanın veya sayfaların içeriğine göre soruları yanıtlama
  • Belirli amaçlar için içerikleri analiz etme (ör. iş tanımı yazma veya test soruları oluşturma)

Bu kılavuzda, Gemini API'deki URL bağlamı aracının nasıl kullanılacağı açıklanmaktadır.

URL bağlamını kullanma

URL bağlamı aracını tek başına veya Google Arama ile temellendirme ile birlikte iki temel şekilde kullanabilirsiniz.

Yalnızca URL bağlamı

İsteminizde, modelin doğrudan analiz etmesini istediğiniz belirli URL'leri sağlarsınız.

Örnek istemler:

Summarize this document: YOUR_URLs

Extract the key features from the product description on this page: YOUR_URLs

Google Arama + URL bağlamı ile temellendirme

URL bağlamını ve Google Arama ile temellendirmeyi birlikte de etkinleştirebilirsiniz. URL'lerle veya URL'siz bir istem girebilirsiniz. Model, önce alakalı bilgileri arayabilir ve daha sonra daha ayrıntılı bir şekilde anlamak için arama sonuçlarının içeriğini okumak üzere URL bağlamı aracını kullanabilir.

Örnek istemler:

Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.

Recommend 3 books for beginners to read to learn more about the latest YOUR_subject.

Yalnızca URL bağlamına sahip kod örnekleri

Python

from google import genai
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch

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

url_context_tool = Tool(
    url_context = types.UrlContext
)

response = client.models.generate_content(
    model=model_id,
    contents="Compare recipes from YOUR_URL1 and YOUR_URL2",
    config=GenerateContentConfig(
        tools=[url_context_tool],
        response_modalities=["TEXT"],
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)
# get URLs retrieved for context
print(response.candidates[0].url_context_metadata)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: "GEMINI_API_KEY" });

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash-preview-05-20",
    contents: [
        "Compare recipes from YOUR_URL1 and YOUR_URL2",
    ],
    config: {
      tools: [{urlContext: {}}],
    },
  });
  console.log(response.text);
  // To get URLs retrieved for context
  console.log(response.candidates[0].urlContextMetadata)
}

await main();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=$GOOGLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "Compare recipes from YOUR_URL1 and YOUR_URL2"}
              ]
          }
      ],
      "tools": [
          {
              "url_context": {}
          }
      ]
  }' > result.json

cat result.json

Python

from google import genai
from google.genai.types import Tool, GenerateContentConfig, GoogleSearch

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

tools = []
tools.append(Tool(url_context=types.UrlContext))
tools.append(Tool(google_search=types.GoogleSearch))

response = client.models.generate_content(
    model=model_id,
    contents="Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
    config=GenerateContentConfig(
        tools=tools,
        response_modalities=["TEXT"],
    )
)

for each in response.candidates[0].content.parts:
    print(each.text)
# get URLs retrieved for context
print(response.candidates[0].url_context_metadata)

JavaScript

import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: "GEMINI_API_KEY" });

async function main() {
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash-preview-05-20",
    contents: [
        "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute.",
    ],
    config: {
      tools: [{urlContext: {}}, {googleSearch: {}}],
    },
  });
  console.log(response.text);
  // To get URLs retrieved for context
  console.log(response.candidates[0].urlContextMetadata)
}

await main();

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=$GOOGLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
      "contents": [
          {
              "parts": [
                  {"text": "Give me three day events schedule based on YOUR_URL. Also let me know what needs to taken care of considering weather and commute."}
              ]
          }
      ],
      "tools": [
          {
              "url_context": {}
          },
          {
              "google_search": {}
          }
      ]
  }' > result.json

cat result.json

Google Arama ile temellendirme hakkında daha fazla bilgi için genel bakış sayfasına bakın.

Bağlamsal yanıt

Modelin yanıtı, URL'lerden aldığı içeriğe dayanır. Model URL'lerden içerik aldıysa yanıtta url_context_metadata yer alır. Bu tür bir yanıt aşağıdaki gibi görünebilir (kısaltmak amacıyla yanıtın bazı bölümleri çıkarılmıştır):

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "... \n"
          }
        ],
        "role": "model"
      },
      ...
      "url_context_metadata":
      {
          "url_metadata":
          [
            {
              "retrieved_url": "https://vertexaisearch.cloud.google.com/grounding-api-redirect/1234567890abcdef",
              "url_retrieval_status": <UrlRetrievalStatus.URL_RETRIEVAL_STATUS_SUCCESS: "URL_RETRIEVAL_STATUS_SUCCESS">
            },
            {
              "retrieved_url": "https://vertexaisearch.cloud.google.com/grounding-api-redirect/abcdef1234567890",
              "url_retrieval_status": <UrlRetrievalStatus.URL_RETRIEVAL_STATUS_SUCCESS: "URL_RETRIEVAL_STATUS_SUCCESS">
            },
            {
              "retrieved_url": "YOUR_URL",
              "url_retrieval_status": <UrlRetrievalStatus.URL_RETRIEVAL_STATUS_SUCCESS: "URL_RETRIEVAL_STATUS_SUCCESS">
            },
            {
              "retrieved_url": "https://vertexaisearch.cloud.google.com/grounding-api-redirect/fedcba0987654321",
              "url_retrieval_status": <UrlRetrievalStatus.URL_RETRIEVAL_STATUS_SUCCESS: "URL_RETRIEVAL_STATUS_SUCCESS">
            }
          ]
        }
    }
}

Desteklenen modeller

Sınırlamalar

  • Araç, analiz isteği başına en fazla 20 URL kullanır.
  • Deneme aşamasında en iyi sonuçları elde etmek için aracı YouTube videoları gibi multimedya içerikleri yerine standart web sayfalarında kullanın.
  • Deneme aşamasında araç ücretsizdir. Faturalandırma daha sonra yapılacak.
  • Deneysel sürümde aşağıdaki kotalar geçerlidir:

    • Gemini API üzerinden yapılan istekler için proje başına günlük 1.500 sorgu
    • Google Yapay Zeka Studio'da kullanıcı başına günlük 100 sorgu