skills/gemini-api-integration/SKILL.md
Use when integrating Google Gemini API into projects. Covers model selection, multimodal inputs, streaming, function calling, and production best practices.
npx skillsauth add ranbot-ai/awesome-skills gemini-api-integrationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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.
Node.js / TypeScript:
npm install @google/generative-ai
Python:
pip install google-generativeai
Set your API key securely:
read -rsp "Gemini API key: " GEMINI_API_KEY
echo
export GEMINI_API_KEY
Node.js:
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());
Python:
import google.generativeai as genai
import os
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("Explain async/await in JavaScript")
print(response.text)
const result = await model.generateContentStream("Write a detailed blog post about AI");
for await (const chunk of result.stream) {
process.stdout.write(chunk.text());
}
import fs from "fs";
const imageData = fs.readFileSync("screenshot.png");
const imagePart = {
inlineData: {
data: imageData.toString("base64"),
mimeType: "image/png",
},
};
const result = await model.generateContent(["Describe this image:", imagePart]);
console.log(result.response.text());
const tools = [{
functionDeclarations: [{
name: "get_weather",
description: "Get current weather for a city",
parameters: {
type: "OBJECT",
properties: {
city: { type: "STRING", description: "City name" },
},
required: ["city"],
},
}],
}];
const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro", tools });
const result = await model.generateContent("What's the weather in Mumbai?");
const call = result.response.functionCalls()?.[0];
if (call) {
// Execute the actual function
const weatherData = await getWeather(call.args.city);
// Send result back to model
}
const chat = model.startChat({
history: [
{ role: "user", parts: [{ text: "You are a helpful coding assistant." }] },
{ role: "model", parts: [{ text: "Sure! I'm ready to help with code." }] },
],
});
const response = await chat.sendMessage("How do I reverse a string in Python?");
console.log(response.response.text());
| Model | Best For | Speed | Cost |
|-------|----------|-------|------|
| gemini-1.5-flash | High-throughput, cost-sensitive tasks | Fast | Low |
| gemini-1.5-pro | Complex reasoning, long context | Medium | Medium |
| gemini-2.0-flash | Latest fast model, multimodal | Very Fast | Low |
| gemini-2.0-pro | Most capable, advanced tasks | Slow | High |
gemini-1.5-flash for most tasks — it's fast and cost-effectivesystemInstruction to set persistent model behaviorgemini-pro for simple tasks — Flash is cheaper and fastertry {
const result = await model.generateContent(prompt);
return result.response.text();
} catch (error) {
if (error.status === 429) {
// Rate limited — wait and retry with exponential backoff
await new Promise(r => setTimeout(r, 2 ** retryCount * 1000));
} else if (error.status === 400) {
// Invalid request — check prompt or parameters
console.error("Invalid request:", error.message);
} else {
throw error;
}
}
Problem: API_KEY_INVALID error
Solution: Ensure GEMINI_API_KEY environment variable is set a
tools
Use when a user asks to mine or update a private, evidence-backed work profile from local Claude Code, Codex, Copilot CLI, or OpenCode sessions.
data-ai
Use when diagnosing Android overheating, idle heat, thermal throttling, charging or radio heat, or abnormal battery drain with read-only ADB evidence and approval gates.
research
Research public competitor ads, analyze creative patterns and landing pages, and produce an evidence-labeled strategic teardown.
tools
Compiled CLI covering all 52 endpoints of the Anytype local API — objects, properties, tags, search, chat, files — one binary, no MCP server needed.