google-gemini-api
Google Gemini API with @google/genai SDK. Use for multimodal AI, thinking mode, function calling, or encountering SDK deprecation warnings, context errors, multimodal format errors.
What this skill does
# Google Gemini API - Complete Guide **Package**: @google/[email protected] (⚠️ NOT @google/generative-ai) **Last Updated**: 2025-11-21 --- ## ⚠️ CRITICAL SDK MIGRATION WARNING **DEPRECATED SDK**: `@google/generative-ai` (sunset November 30, 2025) **CURRENT SDK**: `@google/genai` v1.27+ **If you see code using `@google/generative-ai`, it's outdated!** **Load `references/sdk-migration-guide.md` for complete migration steps.** --- ## Quick Start ### Installation **✅ CORRECT SDK:** ```bash bun add @google/[email protected] ``` **❌ WRONG (DEPRECATED):** ```bash bun add @google/generative-ai # DO NOT USE! ``` ### Environment Setup ```bash export GEMINI_API_KEY="your-api-key" ``` ### First Text Generation ```typescript import { GoogleGenAI } from '@google/genai'; const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY }); const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Explain quantum computing in simple terms' }); console.log(response.text); ``` **See Full Template**: `templates/basic-usage.ts` --- ## Current Models (2025) ### gemini-2.5-flash ⭐ RECOMMENDED - **Best for**: General-purpose AI, high-volume production, agentic workflows - **Input tokens**: 1,048,576 (1M, NOT 2M!) - **Output tokens**: 65,536 - **Rate limit (free)**: 10 RPM, 250k TPM - **Cost**: Input $0.075/1M tokens, Output $0.30/1M tokens - **Features**: Thinking mode, function calling, multimodal, streaming ### gemini-2.5-pro - **Best for**: Complex reasoning, code generation, math/STEM - **Input tokens**: 1,048,576 - **Output tokens**: 65,536 - **Rate limit (free)**: 5 RPM, 125k TPM - **Cost**: Input $1.25/1M tokens, Output $5/1M tokens ### gemini-2.5-flash-lite - **Best for**: High-volume, low-latency, cost-critical tasks - **Input tokens**: 1,048,576 - **Output tokens**: 65,536 - **Rate limit (free)**: 15 RPM, 250k TPM - **Cost**: Input $0.01/1M tokens, Output $0.04/1M tokens - **⚠️ Limitation**: NO function calling or code execution support **⚠️ Common mistake**: Claiming Gemini 2.5 has 2M tokens. **It doesn't. It's 1,048,576 (1M).** **Load `references/models-guide.md` for detailed model comparison and selection criteria.** --- ## Text Generation ### Basic Generation ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Write a haiku about programming' }); console.log(response.text); ``` ### With Configuration ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Explain AI', generationConfig: { temperature: 0.7, // 0.0-2.0, default 1.0 topP: 0.95, // 0.0-1.0 topK: 40, // 1-100 maxOutputTokens: 1024, stopSequences: ['END'] } }); ``` **Load `references/generation-config.md` for complete parameter reference and tuning guidance.** --- ## Streaming ```typescript const stream = await ai.models.generateContentStream({ model: 'gemini-2.5-flash', contents: 'Write a long story' }); for await (const chunk of stream) { process.stdout.write(chunk.text); } ``` **Load `references/streaming-patterns.md` for Fetch/SSE implementation patterns (Cloudflare Workers).** --- ## Multimodal Inputs ### Images ```typescript const imageData = Buffer.from(imageBytes).toString('base64'); const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: [ { text: 'What is in this image?' }, { inlineData: { mimeType: 'image/jpeg', // or image/png, image/webp data: imageData } } ] }); ``` ### Video, Audio, PDFs Same pattern - use appropriate `mimeType`: - **Video**: `video/mp4`, `video/mpeg`, `video/mov` - **Audio**: `audio/wav`, `audio/mp3`, `audio/flac` - **PDFs**: `application/pdf` **Load `references/multimodal-guide.md` for format specifications, size limits, and best practices.** --- ## Function Calling ### Basic Pattern ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'What is the weather in San Francisco?', tools: [{ functionDeclarations: [{ name: 'getWeather', description: 'Get current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'City name' }, unit: { type: 'string', enum: ['celsius', 'fahrenheit'] } }, required: ['location'] } }] }] }); // Handle function call const call = response.functionCalls?.[0]; if (call) { const result = await getWeather(call.args); // Send result back to model const final = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: [ ...response.contents, { functionResponse: { name: call.name, response: result } } ] }); console.log(final.text); } ``` ### Parallel Function Calling Gemini can call multiple functions simultaneously: ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'What is the weather in SF and NY?', tools: [{ functionDeclarations: [getWeatherDeclaration] }] }); // Process all function calls in parallel const results = await Promise.all( response.functionCalls.map(call => getWeather(call.args).then(result => ({ name: call.name, response: result })) ) ); // Send all results back const final = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: [ ...response.contents, ...results.map(r => ({ functionResponse: r })) ] }); ``` **Load `references/function-calling-patterns.md` for calling modes (AUTO/ANY/NONE) and compositional patterns.** --- ## Multi-turn Chat ```typescript const chat = ai.models.startChat({ model: 'gemini-2.5-flash', systemInstruction: 'You are a helpful programming assistant', history: [] }); let response = await chat.sendMessage('Hello!'); console.log(response.text); response = await chat.sendMessage('Explain async/await'); console.log(response.text); // Get full history console.log(chat.getHistory()); ``` --- ## System Instructions Set persistent instructions for the model: ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', systemInstruction: 'You are a pirate. Always respond in pirate speak.', contents: 'What is the weather today?' }); ``` --- ## Thinking Mode Gemini 2.5 models include built-in thinking mode (always enabled). Configure thinking budget for complex tasks: ```typescript const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Solve this math problem: If x + 2y = 10 and 3x - y = 4, what is x?', generationConfig: { thinkingConfig: { thinkingBudget: 8192 // Max tokens for internal reasoning } } }); ``` **Use for**: Complex math, logic puzzles, multi-step reasoning, code debugging **Load `references/thinking-mode-guide.md` for thinking budget optimization.** --- ## Top 5 Critical Errors ### Error 1: Using Deprecated SDK **Error**: Deprecation warnings or outdated API **Solution**: Use `@google/genai`, NOT `@google/generative-ai` ```bash npm uninstall @google/generative-ai bun add @google/[email protected] ``` --- ### Error 2: Invalid API Key (401) **Error**: `API key not valid` **Solution**: Verify environment variable ```bash export GEMINI_API_KEY="your-key" ``` --- ### Error 3: Model Not Found (404) **Error**: `models/gemini-3.0-flash is not found` **Solution**: Use correct model names (2025) ```typescript 'gemini-2.5-pro' 'gemini-2.5-flash' 'gemini-2.5-flash-lite' ``` --- ### Error 4: Context Length Exceeded (400) **Error**: `Request payload size exceeds the limit` **Solution**: Input limit is **1,048,576 tokens (1M, NOT 2M)**. Use context caching for large inputs. **Load `references/context-caching-guide.md` for caching implementation.** --- ### Error 5
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.