gemini-api-integration – skill Lập trình cho agent AI
Dùng khi tích hợp Google Gemini API vào dự án. Bao gồm chọn model, đầu vào đa phương thức, streaming, function calling và các best practices cho production.
Cài skill gemini-api-integration bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/gemini-api-integration-d786d.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /gemini-api-integration – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/gemini-api-integration-d786d.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $gemini-api-integration – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/gemini-api-integration-d786d.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /gemini-api-integration – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/gemini-api-integration-d786d.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /gemini-api-integration – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc 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. Select the supported SDK and model
Use the Google GenAI SDK (@google/genai for JavaScript, google-genai for Python), pin a tested package version, and select an available model for the account. The older @google/generative-ai / google-generativeai APIs and historical 1.5/2.0 model table are not current setup guidance. Check model availability, deprecations, pricing and feature support in official documentation before choosing; do not assume a universal cheapest or most capable model.
2. Server-side generation
Set GEMINI_API_KEY through a secret manager or protected environment and GEMINI_MODEL to the verified model ID. Never ship a long-lived key in browser code.
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
const response = await ai.models.generateContent({
model: process.env.GEMINI_MODEL,
contents: "Explain async/await in JavaScript"
});
console.log(response.text);import os
from google import genai
with genai.Client(api_key=os.environ["GEMINI_API_KEY"]) as client:
response = client.models.generate_content(
model=os.environ["GEMINI_MODEL"], contents="Explain async/await")
print(response.text)3. Streaming and multimodal inputs
Use the pinned SDK's models.generateContentStream / models.generate_content_stream interfaces and handle partial output, cancellation and empty/blocked responses. Verify MIME types, model limits and file retention before transmitting images/audio/video. Obtain permission for sensitive content; do not put private inputs or access URLs in logs. File uploads and generation may incur charges.
4. Function calling and chat
A model's function call is an untrusted proposal. Validate the name against a fixed allowlist and arguments against a schema, enforce user authorization, and limit calls/time/cost before dispatch. Return actual tool results through the pinned SDK's documented function-response format; never fabricate results. Preserve the required conversation turns and function-call identifiers. A chat history entry is not a privileged system instruction; use the supported configuration field for system instructions.
5. Failure handling
Inspect structured errors, block reasons and finish reasons without assuming every response has text. Retry only transient errors with bounded exponential backoff, jitter and any retry-after guidance; enforce deadlines and a retry budget. A failed network request may already have incurred usage. Do not retry invalid credentials or malformed requests indefinitely, and do not weaken safety settings merely to bypass a blocked response.
Examples
For a production integration, first run a small non-sensitive prompt against a test project, record the SDK/model version and response status, then test streaming cancellation, blocked output, quota exhaustion and rejected tool arguments. Report what was actually exercised.
Sources
- [Google GenAI migration guide](https://ai.google.dev/gemini-api/docs/migrate)
- [Content generation API](https://ai.google.dev/api/generate-content)
Limitations
SDK syntax, model availability, quotas and pricing change. These examples are unexecuted integration templates and do not establish account access, model quality or production readiness.
Skill liên quan
- gemini-interactions-api – Xây dựng với Gemini Interactions API cho văn bản, chat, sinh nội dung đa phương thức…
- gemini-live-api-dev – Dùng skill này khi xây dựng ứng dụng streaming hai chiều theo thời gian thực với Gemini…
- gemini-omni-flash-api – Dùng skill này cho chỉnh sửa video sinh bằng AI, text-to-video, tạo video tham chiếu…
- senior-fullstack – Bộ công cụ phát triển fullstack với khởi tạo dự án cho Next.js, FastAPI, MERN và Django…
- gh-attach – Tải lên và tải xuống file đính kèm GitHub (ảnh chụp màn hình, PDF, zip, video) từ…
- gh-review-requests – Lấy thông báo GitHub chưa đọc của các PR đang mở mà được yêu cầu review từ một team cụ…
- gha-security-review – Rà soát workflow GitHub Actions để tìm lỗ hổng có thể khai thác, kèm đường tấn công cụ…
- git-advanced-workflows – Thành thạo các kỹ thuật Git nâng cao để giữ lịch sử sạch, cộng tác hiệu quả và khôi phục…