What it covers
The Gemini API supports text and multimodal model calls, streaming, embeddings, file inputs, tools, and live sessions. Google AI Studio provides project and key management for direct Gemini API use.
Request shape
curl "https://generativelanguage.googleapis.com/v1beta/models/YOUR_MODEL:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contents":[{"parts":[{"text":"Compare these two API responses."}]}]}'
Use the official model list at integration time. Quotas belong to the project, so creating more keys does not multiply the available allowance.
Key endpoints
| Endpoint | Description |
|---|---|
POST /v1beta/models/{model}:generateContent |
Generate text content |
POST /v1beta/models/{model}:streamGenerateContent |
Streaming generation |
POST /v1beta/models/{model}:embedContent |
Generate embeddings |
POST /v1beta/models/{model}:countTokens |
Count tokens |
GET /v1beta/models |
List available models |
GET /v1beta/tunedModels |
List tuned models |
POST /v1beta/tunedModels |
Create tuned model |
Decision notes
Separate stable integration facts from model-specific facts. The base API and authentication pattern are relatively stable; model IDs, preview status, token limits, prices, and quotas need dated verification.
Python example: generate content
import httpx
API_KEY = "your_gemini_api_key"
BASE = "https://generativelanguage.googleapis.com/v1beta"
def generate(prompt: str, model: str = "gemini-2.5-flash") -> str:
"""Generate content. API key goes in the query string."""
resp = httpx.post(
f"{BASE}/models/{model}:generateContent",
params={"key": API_KEY},
json={"contents": [{"parts": [{"text": prompt}]}]},
timeout=60,
)
if resp.status_code == 429:
raise RuntimeError("Rate limited — back off and retry")
resp.raise_for_status()
data = resp.json()
return data["candidates"][0]["content"]["parts"][0]["text"]
print(generate("What is a dividend? One sentence."))
Notes:
- Auth is the
keyquery parameter (orx-goog-api-keyheader) - Model names evolve fast;
gemini-2.5-flashis the current efficient default — verify in docs - Free tier has strict RPM/TPD limits; check
candidates[].finishReasonforMAX_TOKENS/SAFETY - Use the official
google-genaiSDK for structured output and function calling
For manually reconstructed function-call history, see the Gemini thought_signature 400 case. It explains how to preserve parallel calls in their original model response.
Integration surface
- Versioning
- Versioned REST paths; current examples use v1beta for several Gemini API operations.
- Resource groups
- Models and generation, Embeddings, Files, Tools, Live API
- Pagination
- List operations use endpoint-specific pageToken fields.
- Errors
- Google JSON error status responses are used; quota exhaustion is documented as 429 RESOURCE_EXHAUSTED.
- Webhooks
- No general event webhook product was confirmed in the reviewed Gemini API documentation.
- Official SDKs
- Python, JavaScript and TypeScript, Go, Java