google-gemini-api
Integrate Gemini API with correct current SDK (@google/genai v1.27+, NOT deprecated @google/generative-ai). Supports text generation, multimodal (images/video/audio/PDFs), function calling, and thinking mode. 1M input tokens. Use when: integrating Gemini API, implementing multimodal AI, using thinking mode for reasoning, function calling with parallel execution, streaming responses, deploying to Cloudflare Workers, building chat, or troubleshooting SDK deprecation, context window, model not found, function calling, or multimodal format errors. Keywords: gemini api, @google/genai, gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-3-pro-preview, multimodal gemini, thinking mode, google ai, genai sdk, function calling gemini, streaming gemini, gemini vision, gemini video, gemini audio, gemini pdf, system instructions, multi-turn chat, DEPRECATED @google/generative-ai, gemini context window, gemini models 2025, gemini 1m tokens, gemini tool use, parallel function calling, compositional function calling, gemini 3
What this skill does
# Google Gemini API - Complete Guide **Version**: Phase 2 Complete + Gemini 3 ✅ **Package**: @google/[email protected] (⚠️ NOT @google/generative-ai) **Last Updated**: 2025-11-19 (Gemini 3 preview release) --- ## ⚠️ 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!** This skill uses the **correct current SDK** and provides a complete migration guide. --- ## Status **✅ Phase 1 Complete**: - ✅ Text Generation (basic + streaming) - ✅ Multimodal Inputs (images, video, audio, PDFs) - ✅ Function Calling (basic + parallel execution) - ✅ System Instructions & Multi-turn Chat - ✅ Thinking Mode Configuration - ✅ Generation Parameters (temperature, top-p, top-k, stop sequences) - ✅ Both Node.js SDK (@google/genai) and fetch approaches **✅ Phase 2 Complete**: - ✅ Context Caching (cost optimization with TTL-based caching) - ✅ Code Execution (built-in Python interpreter and sandbox) - ✅ Grounding with Google Search (real-time web information + citations) **📦 Separate Skills**: - **Embeddings**: See `google-gemini-embeddings` skill for text-embedding-004 --- ## Table of Contents **Phase 1 - Core Features**: 1. [Quick Start](#quick-start) 2. [Current Models (2025)](#current-models-2025) 3. [SDK vs Fetch Approaches](#sdk-vs-fetch-approaches) 4. [Text Generation](#text-generation) 5. [Streaming](#streaming) 6. [Multimodal Inputs](#multimodal-inputs) 7. [Function Calling](#function-calling) 8. [System Instructions](#system-instructions) 9. [Multi-turn Chat](#multi-turn-chat) 10. [Thinking Mode](#thinking-mode) 11. [Generation Configuration](#generation-configuration) **Phase 2 - Advanced Features**: 12. [Context Caching](#context-caching) 13. [Code Execution](#code-execution) 14. [Grounding with Google Search](#grounding-with-google-search) **Common Reference**: 15. [Error Handling](#error-handling) 16. [Rate Limits](#rate-limits) 17. [SDK Migration Guide](#sdk-migration-guide) 18. [Production Best Practices](#production-best-practices) --- ## Quick Start ### Installation **CORRECT SDK:** ```bash npm install @google/[email protected] ``` **❌ WRONG (DEPRECATED):** ```bash npm install @google/generative-ai # DO NOT USE! ``` ### Environment Setup ```bash export GEMINI_API_KEY="..." ``` Or create `.env` file: ``` GEMINI_API_KEY=... ``` ### First Text Generation (Node.js SDK) ```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); ``` ### First Text Generation (Fetch - Cloudflare Workers) ```typescript const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-goog-api-key': env.GEMINI_API_KEY, }, body: JSON.stringify({ contents: [{ parts: [{ text: 'Explain quantum computing in simple terms' }] }] }), } ); const data = await response.json(); console.log(data.candidates[0].content.parts[0].text); ``` --- ## Current Models (2025) ### Gemini 3 Series (Preview - November 2025) #### gemini-3-pro-preview - **Context**: TBD (documentation pending) - **Status**: 🆕 Preview release (November 18, 2025) - **Description**: Google's newest and most intelligent AI model with state-of-the-art reasoning - **Best for**: Most complex reasoning tasks, advanced multimodal understanding, benchmark-critical applications - **Features**: Enhanced multimodal (text, image, video, audio, PDF), function calling, streaming - **Benchmark Performance**: Outperforms Gemini 2.5 Pro on every major AI benchmark - **⚠️ Preview**: Use for evaluation. Consider gemini-2.5-pro for production until stable release ### Gemini 2.5 Series (General Availability - Stable) #### gemini-2.5-pro - **Context**: 1,048,576 input tokens / 65,536 output tokens - **Description**: State-of-the-art thinking model for complex reasoning - **Best for**: Code, math, STEM, complex problem-solving - **Features**: Thinking mode (default on), function calling, multimodal, streaming - **Knowledge cutoff**: January 2025 #### gemini-2.5-flash - **Context**: 1,048,576 input tokens / 65,536 output tokens - **Description**: Best price-performance workhorse model - **Best for**: Large-scale processing, low-latency, high-volume, agentic use cases - **Features**: Thinking mode (default on), function calling, multimodal, streaming - **Knowledge cutoff**: January 2025 #### gemini-2.5-flash-lite - **Context**: 1,048,576 input tokens / 65,536 output tokens - **Description**: Cost-optimized, fastest 2.5 model - **Best for**: High throughput, cost-sensitive applications - **Features**: Thinking mode (default on), function calling, multimodal, streaming - **Knowledge cutoff**: January 2025 ### Model Feature Matrix | Feature | 3-Pro (Preview) | 2.5-Pro | 2.5-Flash | 2.5-Flash-Lite | |---------|-----------------|---------|-----------|----------------| | Thinking Mode | TBD | ✅ Default ON | ✅ Default ON | ✅ Default ON | | Function Calling | ✅ | ✅ | ✅ | ✅ | | Multimodal | ✅ Enhanced | ✅ | ✅ | ✅ | | Streaming | ✅ | ✅ | ✅ | ✅ | | System Instructions | ✅ | ✅ | ✅ | ✅ | | Context Window | TBD | 1,048,576 in | 1,048,576 in | 1,048,576 in | | Output Tokens | TBD | 65,536 max | 65,536 max | 65,536 max | | Status | Preview | Stable | Stable | Stable | ### ⚠️ Context Window Correction **ACCURATE (Gemini 2.5)**: Gemini 2.5 models support **1,048,576 input tokens** (NOT 2M!) **OUTDATED**: Only Gemini 1.5 Pro (previous generation) had 2M token context window **GEMINI 3**: Context window specifications pending official documentation **Common mistake**: Claiming Gemini 2.5 has 2M tokens. It doesn't. This skill prevents this error. --- ## SDK vs Fetch Approaches ### Node.js SDK (@google/genai) **Pros:** - Type-safe with TypeScript - Easier API (simpler syntax) - Built-in chat helpers - Automatic SSE parsing for streaming - Better error handling **Cons:** - Requires Node.js or compatible runtime - Larger bundle size - May not work in all edge runtimes **Use when:** Building Node.js apps, Next.js Server Actions/Components, or any environment with Node.js compatibility ### Fetch-based (Direct REST API) **Pros:** - Works in **any** JavaScript environment (Cloudflare Workers, Deno, Bun, browsers) - Minimal dependencies - Smaller bundle size - Full control over requests **Cons:** - More verbose syntax - Manual SSE parsing for streaming - No built-in chat helpers - Manual error handling **Use when:** Deploying to Cloudflare Workers, browser clients, or lightweight edge runtimes --- ## Text Generation ### Basic Text Generation (SDK) ```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: 'Write a haiku about artificial intelligence' }); console.log(response.text); ``` ### Basic Text Generation (Fetch) ```typescript const response = await fetch( `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-goog-api-key': env.GEMINI_API_KEY, }, body: JSON.stringify({ contents: [ { parts: [ { text: 'Write a haiku about artificial intelligence' } ] } ] }), } ); const data = await response.json(); console.log(data.candidates[0].content.parts[0].text); ``` ### Response Structure ```typescript { text: string, // Convenience accessor for text content candidates: [ { content: { par
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.