Gemini API development
Use this skill when building an ordinary Gemini API application rather than a long-lived Live API session or an agent workflow that specifically belongs on the Interactions API.
Start with current documentation
Treat model IDs, SDK imports, method names, response fields, supported modalities, preview labels, and pricing or quota behavior as version-sensitive. Before writing code, use the Gemini Docs MCP if it is connected. Search the official Gemini documentation for the exact task, model, language, and API surface. If the MCP is unavailable, use the official documentation index at https://ai.google.dev/gemini-api/docs/llms.txt and follow links to the relevant page.
Do not guess from generic OpenAI examples or old google-generativeai snippets. Prefer the current Google GenAI SDK and confirm the installed package version and language-specific import path. Keep the API key on a trusted server or backend; do not put it in browser bundles, mobile binaries, committed files, logs, or client-visible prompts.
Choose the API surface
Make the API choice explicit before implementation.
| Need |
Preferred starting point |
| A new model or agent workflow, server-side state, background execution, or coordinated tools |
Interactions API; read gemini-interactions-api when the task matches it |
| Continuous low-latency audio/video/text conversation over a WebSocket |
Gemini Live API; read gemini-live-api-dev |
| A conventional request/response or multimodal generation call |
Current Google GenAI SDK and the documented Gemini API method for the selected model |
Existing code using generateContent |
Keep it working unless migration is requested, then compare the current migration guide before changing behavior |
Do not migrate APIs merely to make an example look newer. Match the API to the product’s latency, state, tool, and deployment requirements.
Implement the smallest correct path
- Confirm the language, package version, model, API surface, input modalities, output modality, and deployment boundary.
- Create the SDK client using the current official quickstart for that language. Load credentials from the runtime environment or a secret manager.
- Make one minimal request and inspect the actual response shape before adding streaming, tools, retries, caching, or orchestration.
- Add multimodal inputs using the documented content and MIME-type conventions. Do not infer media support from a model name.
- Add structured output only when the application needs machine-readable data. Define a small schema, validate the result, and handle refusal, truncation, invalid JSON, and safety blocks.
- Add function calling only with explicit tool schemas, server-side validation, authorization checks, timeouts, idempotency, and a clear loop for returning tool results.
- Add retries and observability around network errors, rate limits, transient server errors, and model refusals. Do not blindly retry non-idempotent side effects.
- Write a focused smoke test that proves authentication, one representative request, parsing, and the important failure path.
Function calling guardrails
Treat model-generated function calls as untrusted input. Validate every argument against the server’s schema and business rules. The model must never decide authorization, tenant boundaries, payment amounts, file paths, SQL fragments, or irreversible actions by itself. Keep tool execution in application code, return only the minimum result needed by the model, and request user confirmation for consequential operations.
Keep the tool loop observable. Log a request ID, tool name, validated argument summary, duration, and outcome without logging API keys or sensitive payloads. Add loop limits and duplicate-call protection so a malformed model response cannot create an unbounded execution cycle.
Streaming and multimodal behavior
Use the exact streaming API documented for the selected API surface. Accumulate text deltas in order, handle finalization and errors, and expose cancellation to the user. For audio or video, document the accepted encoding, sample rate, frame cadence, MIME type, size limits, and buffering policy rather than assuming them. Preserve the distinction between model output text, inline data, citations, tool calls, and usage metadata.
Google Cloud deployment context
When the Gemini application runs on Google Cloud, read docs/google-cloud-deployment.md in the repository as a deployment review companion. Separate Gemini API correctness from cloud concerns such as runtime identity, secret storage, networking, observability, quotas, rollout, and recovery. Use the current Google Cloud Well-Architected Framework and service documentation for the target product; do not assume Cloud Run, GKE, BigQuery, Firebase, or a fixed IAM pattern is always the right choice.
Production checklist
| Area |
Check |
| Credentials |
Key is server-side, scoped where possible, rotated, and absent from logs and source control |
| Models |
Model ID and capability are confirmed from current official docs |
| Inputs |
MIME types, size limits, token limits, and user-provided content are validated |
| Outputs |
Response parts and finish/error states are parsed defensively |
| Tools |
Schemas, authorization, side effects, timeouts, and confirmation are enforced in code |
| Reliability |
Rate limits, retries, cancellation, timeouts, and request IDs are handled |
| Safety |
Application policy, user confirmation, and provider safety behavior are not bypassed |
| Tests |
A minimal live smoke test and deterministic parsing/tool tests exist |
| Docs |
The implementation records the official docs pages and SDK version used |
Common failure modes
When code fails, classify the failure before changing the API: authentication, unsupported model capability, malformed request, content or safety block, quota/rate limit, transport failure, timeout, response parsing, or tool execution. Search the current error and method names in the Gemini Docs MCP. Do not fix a 404 by inventing a different model name, and do not fix a schema error by removing validation without understanding the response contract.
If an SDK example and runtime behavior disagree, inspect the installed package version, the official API reference, and the changelog or deprecations page. Keep a compatible fallback only when the product genuinely supports multiple API surfaces.
Current documentation
Use these as starting points, not as substitutes for task-time verification:
- Gemini API overview:
https://ai.google.dev/gemini-api/docs
- Get started:
https://ai.google.dev/gemini-api/docs/get-started
- Models:
https://ai.google.dev/gemini-api/docs/models
- Text generation:
https://ai.google.dev/gemini-api/docs/text-generation
- Multimodal input:
https://ai.google.dev/gemini-api/docs/image-understanding
- Function calling:
https://ai.google.dev/gemini-api/docs/function-calling
- Structured output:
https://ai.google.dev/gemini-api/docs/structured-output
- Image generation:
https://ai.google.dev/gemini-api/docs/image-generation
- Tools:
https://ai.google.dev/gemini-api/docs/tools
- Troubleshooting:
https://ai.google.dev/gemini-api/docs/troubleshooting
- Deprecations:
https://ai.google.dev/gemini-api/docs/deprecations
1---2name: gemini-api-dev3description: Build and review general-purpose applications with the Gemini API. Use for text generation, multimodal input, image generation, SDK setup, model selection, tools, function calling, structured output, production hardening, or migrations from older Gemini integrations.4---56# Gemini API development78Use this skill when building an ordinary Gemini API application rather than a long-lived Live API session or an agent workflow that specifically belongs on the Interactions API.910## Start with current documentation1112Treat model IDs, SDK imports, method names, response fields, supported modalities, preview labels, and pricing or quota behavior as version-sensitive. Before writing code, use the Gemini Docs MCP if it is connected. Search the official Gemini documentation for the exact task, model, language, and API surface. If the MCP is unavailable, use the official documentation index at `https://ai.google.dev/gemini-api/docs/llms.txt` and follow links to the relevant page.1314Do not guess from generic OpenAI examples or old `google-generativeai` snippets. Prefer the current Google GenAI SDK and confirm the installed package version and language-specific import path. Keep the API key on a trusted server or backend; do not put it in browser bundles, mobile binaries, committed files, logs, or client-visible prompts.1516## Choose the API surface1718Make the API choice explicit before implementation.1920| Need | Preferred starting point |21| --- | --- |22| A new model or agent workflow, server-side state, background execution, or coordinated tools | Interactions API; read `gemini-interactions-api` when the task matches it |23| Continuous low-latency audio/video/text conversation over a WebSocket | Gemini Live API; read `gemini-live-api-dev` |24| A conventional request/response or multimodal generation call | Current Google GenAI SDK and the documented Gemini API method for the selected model |25| Existing code using `generateContent` | Keep it working unless migration is requested, then compare the current migration guide before changing behavior |2627Do not migrate APIs merely to make an example look newer. Match the API to the product’s latency, state, tool, and deployment requirements.2829## Implement the smallest correct path30311. Confirm the language, package version, model, API surface, input modalities, output modality, and deployment boundary.322. Create the SDK client using the current official quickstart for that language. Load credentials from the runtime environment or a secret manager.333. Make one minimal request and inspect the actual response shape before adding streaming, tools, retries, caching, or orchestration.344. Add multimodal inputs using the documented content and MIME-type conventions. Do not infer media support from a model name.355. Add structured output only when the application needs machine-readable data. Define a small schema, validate the result, and handle refusal, truncation, invalid JSON, and safety blocks.366. Add function calling only with explicit tool schemas, server-side validation, authorization checks, timeouts, idempotency, and a clear loop for returning tool results.377. Add retries and observability around network errors, rate limits, transient server errors, and model refusals. Do not blindly retry non-idempotent side effects.388. Write a focused smoke test that proves authentication, one representative request, parsing, and the important failure path.3940## Function calling guardrails4142Treat model-generated function calls as untrusted input. Validate every argument against the server’s schema and business rules. The model must never decide authorization, tenant boundaries, payment amounts, file paths, SQL fragments, or irreversible actions by itself. Keep tool execution in application code, return only the minimum result needed by the model, and request user confirmation for consequential operations.4344Keep the tool loop observable. Log a request ID, tool name, validated argument summary, duration, and outcome without logging API keys or sensitive payloads. Add loop limits and duplicate-call protection so a malformed model response cannot create an unbounded execution cycle.4546## Streaming and multimodal behavior4748Use the exact streaming API documented for the selected API surface. Accumulate text deltas in order, handle finalization and errors, and expose cancellation to the user. For audio or video, document the accepted encoding, sample rate, frame cadence, MIME type, size limits, and buffering policy rather than assuming them. Preserve the distinction between model output text, inline data, citations, tool calls, and usage metadata.4950## Google Cloud deployment context5152When the Gemini application runs on Google Cloud, read `docs/google-cloud-deployment.md` in the repository as a deployment review companion. Separate Gemini API correctness from cloud concerns such as runtime identity, secret storage, networking, observability, quotas, rollout, and recovery. Use the current Google Cloud Well-Architected Framework and service documentation for the target product; do not assume Cloud Run, GKE, BigQuery, Firebase, or a fixed IAM pattern is always the right choice.5354## Production checklist5556| Area | Check |57| --- | --- |58| Credentials | Key is server-side, scoped where possible, rotated, and absent from logs and source control |59| Models | Model ID and capability are confirmed from current official docs |60| Inputs | MIME types, size limits, token limits, and user-provided content are validated |61| Outputs | Response parts and finish/error states are parsed defensively |62| Tools | Schemas, authorization, side effects, timeouts, and confirmation are enforced in code |63| Reliability | Rate limits, retries, cancellation, timeouts, and request IDs are handled |64| Safety | Application policy, user confirmation, and provider safety behavior are not bypassed |65| Tests | A minimal live smoke test and deterministic parsing/tool tests exist |66| Docs | The implementation records the official docs pages and SDK version used |6768## Common failure modes6970When code fails, classify the failure before changing the API: authentication, unsupported model capability, malformed request, content or safety block, quota/rate limit, transport failure, timeout, response parsing, or tool execution. Search the current error and method names in the Gemini Docs MCP. Do not fix a 404 by inventing a different model name, and do not fix a schema error by removing validation without understanding the response contract.7172If an SDK example and runtime behavior disagree, inspect the installed package version, the official API reference, and the changelog or deprecations page. Keep a compatible fallback only when the product genuinely supports multiple API surfaces.7374## Current documentation7576Use these as starting points, not as substitutes for task-time verification:7778- Gemini API overview: `https://ai.google.dev/gemini-api/docs`79- Get started: `https://ai.google.dev/gemini-api/docs/get-started`80- Models: `https://ai.google.dev/gemini-api/docs/models`81- Text generation: `https://ai.google.dev/gemini-api/docs/text-generation`82- Multimodal input: `https://ai.google.dev/gemini-api/docs/image-understanding`83- Function calling: `https://ai.google.dev/gemini-api/docs/function-calling`84- Structured output: `https://ai.google.dev/gemini-api/docs/structured-output`85- Image generation: `https://ai.google.dev/gemini-api/docs/image-generation`86- Tools: `https://ai.google.dev/gemini-api/docs/tools`87- Troubleshooting: `https://ai.google.dev/gemini-api/docs/troubleshooting`88- Deprecations: `https://ai.google.dev/gemini-api/docs/deprecations`