gemini-api-integration
Skill này làm gì
Công cụ này giúp kết nối chương trình của bạn với trí tuệ nhân tạo Google Gemini. Nó hướng dẫn cách để Gemini hiểu và phản hồi văn bản, hình ảnh, thậm chí âm thanh/video, và cho phép nó thực hiện các hành động cụ thể.
Khi nào nên dùng
- ✓Khi bắt đầu dùng Gemini trong một dự án mới.
- ✓Khi muốn chương trình của bạn hiểu hình ảnh hoặc âm thanh.
- ✓Khi muốn Gemini phản hồi nhanh hơn hoặc thực hiện các tác vụ cụ thể.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/gemini-api-integration/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm thế nào để kết nối Gemini để nó có thể trả lời câu hỏi về hình ảnh?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Bạn thêm đoạn mã đặc biệt vào chương trình để giao tiếp với Gemini API. Đoạn mã này chọn mô hình phù hợp, gửi dữ liệu (văn bản, hình ảnh, v.v.) và nhận phản hồi.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Gemini API Integration
Overview
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.
When to Use This Skill
- Use when setting up Gemini API for the first time in a Node.js, Python, or browser project
- Use when implementing multimodal inputs (text + image/audio/video)
- Use when adding streaming responses to improve perceived latency
- Use when implementing function calling / tool use with Gemini
- Use when optimizing model selection (Flash vs Pro vs Ultra) for cost and performance
- Use when debugging Gemini API errors, rate limits, or quota issues
Step-by-Step Guide
1. Installation & Setup
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
2. Basic Text Generation
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)
3. Streaming Responses
const result = await model.generateContentStream("Write a detailed blog post about AI");
for await (const chunk of result.stream) {
process.stdout.write(chunk.text());
}
4. Multimodal Input (Text + Image)
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());
5. Function Calling / Tool Use
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
}
6. Multi-turn Chat
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());
7. Model Selection Guide
| 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 |
Best Practices
- ✅ Do: Use
gemini-1.5-flashfor most tasks — it's fast and cost-effective - ✅ Do: Always stream responses for user-facing chat UIs to reduce perceived latency
- ✅ Do: Store API keys in environment variables, never hard-code them
- ✅ Do: Implement exponential backoff for rate limit (429) errors
- ✅ Do: Use
systemInstructionto set persistent model behavior - ❌ Don't: Use
gemini-profor simple tasks — Flash is cheaper and faster - ❌ Don't: Send large base64 images inline for files > 20MB — use File API instead
- ❌ Don't: Ignore safety ratings in responses for production apps
Error Handling
try {
const result = await model.generateContent(prompt);
…
Câu hỏi thường gặp
Khác nhau giữa các mô hình Flash, Pro và Ultra là gì?
Flash nhanh hơn và rẻ hơn cho các tác vụ đơn giản. Pro tốt cho suy luận phức tạp. Ultra là mô hình tiên tiến nhất, nhưng có thể chậm hơn và đắt hơn.
'Streaming' là gì?
Đây là khi phản hồi của AI đến từng phần một, thay vì chờ mọi thứ sẵn sàng. Điều này làm cho AI có vẻ phản hồi nhanh hơn.
'Function calling' là gì?
Đây là cách dạy AI sử dụng các công cụ hoặc hàm cụ thể trong chương trình của bạn, như tra cứu thời tiết của một thành phố.
Chi tiết
Mô tả gốc của tác giả
Use when integrating Google Gemini API into projects. Covers model selection, multimodal inputs, streaming, function calling, and production best practices.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #4707
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
add-model-provider
394kGiúp agent của bạn kết nối nhà cung cấp mô hình AI mới với OpenClaw bằng lệnh an toàn, giữ API key khỏi văn bản thuần và chạy thử.
acp-router
394kGiúp agent của bạn gửi một tác vụ đến trợ lý lập trình như Claude Code hoặc Cursor qua OpenClaw, để công việc chạy ngay trong công cụ đó.
browser-automation
394kHướng dẫn agent của bạn điều khiển trang web từng bước, gồm đăng nhập, tab và cách khôi phục khi trang ngừng phản hồi.