URL 컨텍스트 도구를 사용하면 Gemini에 URL을 프롬프트의 추가 컨텍스트로 제공할 수 있습니다. 그러면 모델은 URL에서 콘텐츠를 가져와 해당 콘텐츠를 사용하여 응답을 알리고 형성할 수 있습니다.
이 도구는 다음과 같은 작업에 유용합니다.
- 기사에서 주요 데이터 포인트 또는 요점 추출
- 여러 링크의 정보 비교
- 여러 소스의 데이터 종합
- 특정 페이지의 콘텐츠를 기반으로 질문에 답변
- 특정 목적 (예: 직무 설명 작성 또는 테스트 질문 작성)을 위해 콘텐츠 분석
이 가이드에서는 Gemini API에서 URL 컨텍스트 도구를 사용하는 방법을 설명합니다.
URL 컨텍스트 사용
URL 컨텍스트 도구는 두 가지 기본 방법으로 사용할 수 있습니다. 단독으로 사용하거나 Google 검색으로 그라운딩과 함께 사용할 수 있습니다.
URL 컨텍스트만 사용
프롬프트에서 모델이 직접 분석할 특정 URL을 제공합니다.
프롬프트 예:
Summarize this document: YOUR_URLs
Extract the key features from the product description on this page: YOUR_URLs
Google 검색 + URL 컨텍스트를 사용한 그라운딩
URL 컨텍스트와 Google 검색을 통한 그라운딩을 모두 사용 설정할 수도 있습니다. URL 유무와 관계없이 프롬프트를 입력할 수 있습니다. 모델은 먼저 관련 정보를 검색한 다음 URL 컨텍스트 도구를 사용하여 검색 결과의 콘텐츠를 읽고 더 심층적으로 이해할 수 있습니다.
프롬프트 예:
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.
URL 컨텍스트만 있는 코드 예시
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
Google 검색을 사용한 그라운딩 코드 예시
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 검색으로 그라운딩하는 방법에 관한 자세한 내용은 개요 페이지를 참고하세요.
문맥 응답
모델의 응답은 URL에서 가져온 콘텐츠를 기반으로 합니다. 모델이 URL에서 콘텐츠를 가져온 경우 응답에 url_context_metadata
가 포함됩니다. 이러한 응답은 다음과 같이 표시될 수 있습니다(간결성을 위해 응답의 일부가 생략됨).
{
"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">
}
]
}
}
}
지원되는 모델
- gemini-2.5-pro-preview-06-05
- gemini-2.5-flash-preview-05-20
- gemini-2.0-flash
- gemini-2.0-flash-live-001
제한사항
- 이 도구는 분석 요청당 최대 20개의 URL을 사용합니다.
- 실험 단계에서 최상의 결과를 얻으려면 YouTube 동영상과 같은 멀티미디어 콘텐츠가 아닌 표준 웹페이지에서 이 도구를 사용하세요.
- 실험 단계에서는 이 도구를 무료로 사용할 수 있습니다. 나중에 청구됩니다.
실험용 출시에는 다음과 같은 할당량이 적용됩니다.
- Gemini API를 통한 요청의 경우 프로젝트당 일일 쿼리 1,500회
- Google AI Studio에서 사용자당 일일 쿼리 100개