Gemini API
7/28/26About 2 min
Gemini API
The Gemini API provides access to Google's Gemini models. The endpoint URL includes the model name in the path, and authentication can be passed via URL parameter or header.
Endpoint Info
| Item | Value |
|---|---|
| URL | /v1beta/models/{model}:generateContent |
| Method | POST |
| Auth | URL parameter key or Bearer Token header |
| Content-Type | application/json |
URL Format
Replace {model} with the model name:
/v1beta/models/gemini-2.5-flash:generateContent/v1beta/models/gemini-2.5-pro:generateContent
For streaming, use :streamGenerateContent instead.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | Message array with role and parts |
system_instruction | object | No | System instruction (single part object) |
generation_config | object | No | Generation settings (temperature, max_tokens, etc.) |
safety_settings | array | No | Safety filter settings |
contents Format
{
"contents": [
{
"role": "user",
"parts": [
{"text": "Hello, Gemini!"}
]
},
{
"role": "model",
"parts": [
{"text": "Hello! How can I assist you?"}
]
},
{
"role": "user",
"parts": [
{"text": "Tell me about quantum computing"}
]
}
]
}generation_config Fields
| Field | Type | Description |
|---|---|---|
temperature | number | Sampling temperature, 0–2 |
max_output_tokens | integer | Maximum output tokens |
top_p | number | Nucleus sampling |
top_k | integer | Top-k sampling |
candidate_count | integer | Number of candidates to generate |
cURL Examples
URL Parameter Authentication
curl "https://api.quickapi.store/v1beta/models/gemini-2.5-flash:generateContent?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Hello, Gemini!"}}
}
],
"generation_config": {
"temperature": 0.7,
"max_output_tokens": 1000
}
}'Header Authentication
curl https://api.quickapi.store/v1beta/models/gemini-2.5-flash:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Hello, Gemini!"}}
}
],
"generation_config": {
"temperature": 0.7,
"max_output_tokens": 1000
}
}'Streaming (streamGenerateContent)
curl "https://api.quickapi.store/v1beta/models/gemini-2.5-flash:streamGenerateContent?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Write a short poem"}}
}
],
"generation_config": {
"max_output_tokens": 500
}
}'With System Instruction
curl https://api.quickapi.store/v1beta/models/gemini-2.5-pro:generateContent \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"contents": [
{
"role": "user",
"parts": [{"text": "Explain this code: def fib(n): return n if n <= 1 else fib(n-1) + fib(n-2)"}}
}
],
"system_instruction": {
"parts": [{"text": "You are an expert Python programmer. Explain code clearly."}]
},
"generation_config": {
"temperature": 0.3,
"max_output_tokens": 2000
}
}'💡 Model Name in Path
Unlike OpenAI's API where the model is specified in the request body, Gemini requires the model name in the URL path. Make sure to use the correct model identifier.
Response Example
Normal Response
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Hello! I'm Gemini, Google's AI model. How can I help you today?"
}
]
},
"finishReason": "STOP",
"index": 0,
"safetyRatings": [
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"probability": "NEGLIGIBLE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"probability": "NEGLIGIBLE"
}
]
}
],
"usageMetadata": {
"promptTokenCount": 6,
"candidatesTokenCount": 20,
"totalTokenCount": 26
}
}Streaming Response
[
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{"text": "Roses are red"}]
},
"finishReason": "STOP"
}
]
},
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{"text": ",
violets are blue"}]
}
}
]
},
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{"text": ",
AI is great"}]
}
}
]
},
{
"candidates": [
{
"content": {
"role": "model",
"parts": [{"text": ",
and so are you!"}]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 5,
"candidatesTokenCount": 18,
"totalTokenCount": 23
}
}
]Python Example
import google.generativeai as genai
genai.configure(
api_key="YOUR_API_KEY",
client_options={"api_endpoint": "https://api.quickapi.store"}
)
model = genai.GenerativeModel("gemini-2.5-flash")
# Normal request
response = model.generate_content("Hello, Gemini!")
print(response.text)
# With generation config
response = model.generate_content(
"Explain quantum computing",
generation_config=genai.types.GenerationConfig(
temperature=0.7,
max_output_tokens=2000,
top_p=0.9,
top_k=40
)
)
print(response.text)
# Streaming request
for chunk in model.generate_content(
"Write a short poem",
stream=True
):
print(chunk.text, end="")
# With system instruction
model_with_system = genai.GenerativeModel(
"gemini-2.5-pro",
system_instruction="You are an expert Python programmer."
)
response = model_with_system.generate_content("Explain decorators in Python")
print(response.text)⚠️ API Version
This endpoint uses the v1beta API version. Some features may change before reaching stable v1. Check Google's official documentation for the latest updates.

