| name | gemini-api-guides |
| description | | Use when this capability is needed. |
Gemini API Skill
Build AI applications with Google's Gemini models and tools.
Quick Start
Installation
pip install google-genai
npm install @google/genai
go get google.golang.org/genai
Environment Setup
export GEMINI_API_KEY="your-api-key"
Basic Usage
Python:
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="Your prompt here"
)
print(response.text)
JavaScript:
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Your prompt here"
});
console.log(response.text);
REST:
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"contents": [{"parts": [{"text": "Your prompt here"}]}]}'
Model Selection
| Model | Best For | Context Window |
|---|
| Gemini 3 Pro | Most intelligent tasks, multimodal reasoning, agentic | See models-overview |
| Gemini 2.5 Pro | Complex reasoning, coding, extended thinking | 1M tokens |
| Gemini 2.5 Flash | Balanced performance, general tasks | 1M tokens |
| Gemini 2.5 Flash-Lite | High-volume, cost-sensitive, fastest | See models-overview |
| Imagen | High-fidelity image generation | N/A |
| Veo 3.1 | Video generation (8s, 720p/1080p with audio) | N/A |
| Nano Banana | Native image gen with Gemini 2.5 Flash | N/A |
| Nano Banana Pro | Native image gen with Gemini 3 Pro | N/A |
Reference Documentation Index
Getting Started
| Topic | File | Description |
|---|
| Setup & Libraries | getting-started.md | API keys, SDK installation, OpenAI compatibility |
Models & Pricing
Core Capabilities
Advanced Features
Tools
Live API (Real-time Streaming)
Guides
Troubleshooting & Migration
| Topic | File | Description |
|---|
| Troubleshooting | troubleshooting.md | Diagnose and resolve common API issues (25K) |
| Vertex AI Comparison | vertex-ai-comparison.md | READ ONLY IF USER MENTIONS "VERTEX AI": Gemini Developer API vs Vertex AI differences |
Large Files - Search Patterns
For large reference files (>30K), use grep to find specific sections:
image-generation-gemini.md (174K):
grep -n "## " references/image-generation-gemini.md
grep -n "edit" references/image-generation-gemini.md
grep -n "style" references/image-generation-gemini.md
veo.md (69K):
grep -n "## " references/veo.md
grep -n "audio" references/veo.md
models-overview.md (67K):
grep -n "gemini-3" references/models-overview.md
grep -n "context" references/models-overview.md
function-calling.md (54K):
grep -n "## " references/function-calling.md
grep -n "parallel" references/function-calling.md
Common Patterns
Multimodal Input (Image + Text)
from google import genai
from google.genai import types
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=[
types.Part.from_image(image_path),
types.Part.from_text("Describe this image")
]
)
Function Calling
tools = [
types.Tool(function_declarations=[{
"name": "get_weather",
"description": "Get weather for a location",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"]
}
}])
]
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="What's the weather in Paris?",
config=types.GenerateContentConfig(tools=tools)
)
Google Search Grounding
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="What are the latest AI developments?",
config=types.GenerateContentConfig(
tools=[types.Tool(google_search=types.GoogleSearch())]
)
)
Thinking Mode
response = client.models.generate_content(
model="gemini-2.5-pro",
contents="Solve this complex problem...",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_budget_tokens=10000)
)
)
Streaming
for chunk in client.models.generate_content_stream(
model="gemini-2.5-flash",
contents="Write a story"
):
print(chunk.text, end="")
Key Concepts
Tool Execution Flow
Built-in tools (Google Search, Code Execution): Executed by Google
- Send prompt with tool config → Model executes tool → Response with grounded results
Custom tools (Function Calling): You execute
- Send prompt with function declarations → Model returns function call JSON
- You execute function, send result back → Model generates final response
Thought Signatures (Important)
- If using official SDKs with chat feature: Thought signatures are handled automatically. No action needed.
- If manually managing conversation history: Read thought-signatures.md for Gemini 3 Pro function calling requirements.
API Endpoints
| Endpoint | Purpose |
|---|
/v1beta/models/{model}:generateContent | Standard generation |
/v1beta/models/{model}:streamGenerateContent | Streaming |
/v1beta/models/{model}:embedContent | Embeddings |
/v1beta/models/{model}:countTokens | Token counting |
Base URL: https://generativelanguage.googleapis.com
Converted and distributed by TomeVault — claim your Tome and manage your conversions.