Loading...
Loading...
Compare original and translation side by side
GOOGLE_API_KEYhttps://generativelanguage.googleapis.com/v1betaGOOGLE_API_KEYhttps://generativelanguage.googleapis.com/v1beta| Model | Use Case |
|---|---|
| Fast text generation (default) |
| High quality text generation |
| Latest flash model |
| Latest pro model |
| Image generation (Nano Banana) |
| Advanced image generation with thinking & search |
| 模型 | 使用场景 |
|---|---|
| 快速文本生成(默认) |
| 高质量文本生成 |
| 最新Flash模型 |
| 最新Pro模型 |
| 图像生成(Nano Banana) |
| 具备思维与搜索能力的高级图像生成 |
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt here"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt here"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt here"}]
}],
"generationConfig": {
"temperature": 0.9,
"maxOutputTokens": 2000,
"stopSequences": ["END"]
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt here"}]
}],
"generationConfig": {
"temperature": 0.9,
"maxOutputTokens": 2000,
"stopSequences": ["END"]
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{"role": "user", "parts": [{"text": "First message"}]},
{"role": "model", "parts": [{"text": "Model response"}]},
{"role": "user", "parts": [{"text": "Follow-up question"}]}
]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{"role": "user", "parts": [{"text": "First message"}]},
{"role": "model", "parts": [{"text": "Model response"}]},
{"role": "user", "parts": [{"text": "Follow-up question"}]}
]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"system_instruction": {
"parts": [{"text": "You are a helpful assistant that speaks like a pirate."}]
},
"contents": [{
"parts": [{"text": "Hello!"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"system_instruction": {
"parts": [{"text": "You are a helpful assistant that speaks like a pirate."}]
},
"contents": [{
"parts": [{"text": "Hello!"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "List 3 colors as JSON array"}]
}],
"generationConfig": {
"response_mime_type": "application/json"
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "List 3 colors as JSON array"}]
}],
"generationConfig": {
"response_mime_type": "application/json"
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Write a long story"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent?alt=sse&key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Write a long story"}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt"}]
}],
"safetySettings": [
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_ONLY_HIGH"},
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"}
]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [{"text": "Your prompt"}]
}],
"safetySettings": [
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_ONLY_HIGH"},
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_ONLY_HIGH"}
]
}'undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedcurl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Describe what happens in this video"},
{"file_data": {"mime_type": "video/mp4", "file_uri": "FILE_URI_FROM_UPLOAD"}}
]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Describe what happens in this video"},
{"file_data": {"mime_type": "video/mp4", "file_uri": "FILE_URI_FROM_UPLOAD"}}
]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Transcribe and summarize this audio"},
{"file_data": {"mime_type": "audio/mp3", "file_uri": "FILE_URI_FROM_UPLOAD"}}
]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Transcribe and summarize this audio"},
{"file_data": {"mime_type": "audio/mp3", "file_uri": "FILE_URI_FROM_UPLOAD"}}
]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Create a photorealistic image of a cat wearing a hat"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Create a photorealistic image of a cat wearing a hat"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'1:12:33:23:44:34:55:49:1616:921:9curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Create a landscape scene"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {
"aspectRatio": "16:9"
}
}
}'1:12:33:23:44:34:55:49:1616:921:9curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Create a landscape scene"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {
"aspectRatio": "16:9"
}
}
}'BASE64_IMAGE=$(base64 -w0 original.jpg)
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Put this character in a tropical forest"},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMAGE'"}}
]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'BASE64_IMAGE=$(base64 -w0 original.jpg)
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Put this character in a tropical forest"},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMAGE'"}}
]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "A photo of an oak tree in all four seasons"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "1:1",
"imageSize": "4K"
}
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "A photo of an oak tree in all four seasons"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "1:1",
"imageSize": "4K"
}
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Visualize the current weather forecast for Tokyo as a chart"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "16:9"
}
},
"tools": [{"google_search": {}}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "Visualize the current weather forecast for Tokyo as a chart"}]}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"aspectRatio": "16:9"
}
},
"tools": [{"google_search": {}}]
}'BASE64_IMG1=$(base64 -w0 image1.jpg)
BASE64_IMG2=$(base64 -w0 image2.jpg)
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Combine these two characters in a fantasy world"},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMG1'"}},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMG2'"}}
]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'BASE64_IMG1=$(base64 -w0 image1.jpg)
BASE64_IMG2=$(base64 -w0 image2.jpg)
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts": [
{"text": "Combine these two characters in a fantasy world"},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMG1'"}},
{"inline_data": {"mime_type": "image/jpeg", "data": "'$BASE64_IMG2'"}}
]
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"]
}
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "What movies are playing in Mountain View?"}]
}],
"tools": [{
"function_declarations": [{
"name": "find_movies",
"description": "Find movies playing in theaters",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and state"},
"genre": {"type": "string", "description": "Movie genre"}
},
"required": ["location"]
}
}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"role": "user",
"parts": [{"text": "What movies are playing in Mountain View?"}]
}],
"tools": [{
"function_declarations": [{
"name": "find_movies",
"description": "Find movies playing in theaters",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City and state"},
"genre": {"type": "string", "description": "Movie genre"}
},
"required": ["location"]
}
}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{"role": "user", "parts": [{"text": "What movies are playing in Mountain View?"}]},
{"role": "model", "parts": [{"functionCall": {"name": "find_movies", "args": {"location": "Mountain View, CA"}}}]},
{"role": "function", "parts": [{"functionResponse": {"name": "find_movies", "response": {"movies": ["Barbie", "Oppenheimer"]}}}]}
],
"tools": [{
"function_declarations": [{
"name": "find_movies",
"description": "Find movies playing in theaters",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"genre": {"type": "string"}
},
"required": ["location"]
}
}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [
{"role": "user", "parts": [{"text": "What movies are playing in Mountain View?"}]},
{"role": "model", "parts": [{"functionCall": {"name": "find_movies", "args": {"location": "Mountain View, CA"}}}]},
{"role": "function", "parts": [{"functionResponse": {"name": "find_movies", "response": {"movies": ["Barbie", "Oppenheimer"]}}}]}
],
"tools": [{
"function_declarations": [{
"name": "find_movies",
"description": "Find movies playing in theaters",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"genre": {"type": "string"}
},
"required": ["location"]
}
}]
}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "What is the current Google stock price?"}]}],
"tools": [{"google_search": {}}]
}'groundingMetadatacurl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{"parts": [{"text": "What is the current Google stock price?"}]}],
"tools": [{"google_search": {}}]
}'groundingMetadatacurl "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"model": "models/gemini-2.5-flash",
"contents": [{"parts": [{"text": "LARGE_DOCUMENT_TEXT_HERE"}]}],
"ttl": "3600s"
}'curl "https://generativelanguage.googleapis.com/v1beta/cachedContents?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"model": "models/gemini-2.5-flash",
"contents": [{"parts": [{"text": "LARGE_DOCUMENT_TEXT_HERE"}]}],
"ttl": "3600s"
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"cachedContent": "cachedContents/CACHE_ID",
"contents": [{"parts": [{"text": "Summarize the document"}]}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"cachedContent": "cachedContents/CACHE_ID",
"contents": [{"parts": [{"text": "Summarize the document"}]}]
}'curl "https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY"curl "https://generativelanguage.googleapis.com/v1beta/models?key=$GOOGLE_API_KEY"curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash?key=$GOOGLE_API_KEY"curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash?key=$GOOGLE_API_KEY"{
"candidates": [{
"content": {
"parts": [{"text": "Response text here"}],
"role": "model"
},
"finishReason": "STOP"
}],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 50,
"totalTokenCount": 60
}
}{
"candidates": [{
"content": {
"parts": [{"text": "Response text here"}],
"role": "model"
},
"finishReason": "STOP"
}],
"usageMetadata": {
"promptTokenCount": 10,
"candidatesTokenCount": 50,
"totalTokenCount": 60
}
}{
"candidates": [{
"content": {
"parts": [
{"text": "Here is your image:"},
{"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
]
}
}]
}undefined{
"candidates": [{
"content": {
"parts": [
{"text": "Here is your image:"},
{"inlineData": {"mimeType": "image/png", "data": "BASE64_IMAGE_DATA"}}
]
}
}]
}undefined
---
---| Error | Cause | Solution |
|---|---|---|
| 400 | Invalid request | Check JSON syntax |
| 401 | Invalid API key | Verify GOOGLE_API_KEY |
| 429 | Rate limit | Wait and retry |
| 500 | Server error | Retry with exponential backoff |
| 错误码 | 原因 | 解决方案 |
|---|---|---|
| 400 | 请求无效 | 检查JSON语法 |
| 401 | API密钥无效 | 验证GOOGLE_API_KEY |
| 429 | 触发速率限制 | 等待后重试 |
| 500 | 服务器错误 | 使用指数退避策略重试 |
maxOutputTokensstreamGenerateContentmaxOutputTokensstreamGenerateContent