Skill

Integrate Gemini API into Applications

A production-grade guide to integrating Gemini's API - text generation, streaming, multimodal input, and function calling.

Works with google generative ai

78
Spark score
out of 100
Updated 17 days ago
Version 14.2.0
Models
gemini 1 5 progemini 2 0

Add to Favorites

Why it matters

Seamlessly integrate Google's Gemini API into your Node.js, Python, or browser projects. This skill covers everything from basic text generation to advanced multimodal inputs, streaming responses, and function calling, ensuring production-grade implementation.

Outcomes

What it gets done

01

Set up Gemini API for the first time

02

Implement multimodal inputs (text + image/audio/video)

03

Add streaming responses for improved perceived latency

04

Implement function calling / tool use with Gemini

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-gemini-api-integration | bash

Overview

Gemini API Integration

A step-by-step guide to integrating Google's Gemini API, covering text generation, streaming, multimodal input, function calling, model selection, and error handling. Use when setting up Gemini for the first time, adding multimodal or streaming support, implementing tool use, or debugging rate-limit and quota errors.

What it does

Guides integration of Google's Gemini API into an application, covering the full SDK lifecycle from basic text generation through multimodal input, function calling, streaming, and multi-turn chat with production-grade patterns. It installs via npm install @google/generative-ai (Node/TypeScript) or pip install google-generativeai (Python), reads the API key from an environment variable, and walks through: basic generateContent calls; generateContentStream for token-by-token streaming; multimodal calls that pass an image alongside text as inline base64 data; function/tool calling via a functionDeclarations schema plus reading result.response.functionCalls(); and multi-turn chat via startChat with a message history. It also gives a model-selection table across four Gemini models (gemini-1.5-flash, gemini-1.5-pro, gemini-2.0-flash, gemini-2.0-pro), rated on speed and cost, plus an error-handling pattern for HTTP 429 (rate limit, exponential backoff) and 400 (invalid request) responses.

When to use - and when NOT to

Use it when setting up Gemini for the first time in a Node.js, Python, or browser project; when adding multimodal (text + image/audio/video) input; when adding streaming to reduce perceived latency in a chat UI; when implementing function calling / tool use; when choosing between Flash, Pro, and Ultra-tier models for cost and performance; or when debugging Gemini API errors, rate limits, or quota issues. Its own best practices flag misuses to avoid: don't reach for gemini-pro on simple tasks where Flash is cheaper and faster, don't send base64-inlined images over 20MB (use the File API instead), and don't ignore safety ratings in production responses.

Inputs and outputs

import { GoogleGenerativeAI } from "@google/generative-ai";

const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });

const result = await model.generateContent("Explain async/await in JavaScript");
console.log(result.response.text());

Input is a prompt (plus optional image/audio/video parts or a tool schema); output is the model's text response, a streamed sequence of text chunks, or a function-call request that the caller must execute and feed back to the model. Common failures and fixes: API_KEY_INVALID means the GEMINI_API_KEY env var isn't set or the key isn't active in Google AI Studio; a response blocked by safety filters is surfaced via result.response.promptFeedback.blockReason; slow responses call for switching to gemini-1.5-flash with streaming and caching repeated prompts; RESOURCE_EXHAUSTED means a quota check plus request queuing and exponential backoff.

Integrations

Integrates the @google/generative-ai (Node/TypeScript) or google-generativeai (Python) SDKs with the Gemini API family (gemini-1.5-flash, gemini-1.5-pro, gemini-2.0-flash, gemini-2.0-pro), including its function-calling/tool-use interface for connecting Gemini to external functions like a weather lookup, and its File API as the alternative to inline base64 for large media.

Who it's for

Developers integrating Gemini into a Node.js, Python, or browser application who need production-grade patterns for streaming, multimodal input, tool use, model selection, and rate-limit/error handling rather than a bare API reference.

Source README

This skill guides AI agents through integrating Google Gemini API into applications - from basic text generation to advanced multimodal, function calling, and streaming use cases. It covers the full Gemini SDK lifecycle with production-grade patterns.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.