gemini-api
Google Gemini APIを活用したAI搭載アプリケーション開発に対応します。Google Gemini APIの利用、Python SDK(google-genai)やTypeScript SDK(@google/genai)での実装、画像・動画・音声・PDFなどのマルチモーダル入力、思考・推論機能、ストリーミングレスポンス、JSONスキーマによる構造化出力、マルチターン会話、システムインストラクション、画像生成(Nano Banana)、動画生成(Veo)、音声生成(Lyria)、埋め込み処理、PDFを含むドキュメント処理など、Gemini APIの各種統合タスクに対応します。Gemini、Gemini 3、Gemini 2.5、Google AI、Nano Banana、Veo、Lyria、google-genai、@google/genai SDKなどの言及時に自動で活性化します。
description の原文を見る
Google Gemini API integration for building AI-powered applications. Use when working with Google's Gemini API, Python SDK (google-genai), TypeScript SDK (@google/genai), multimodal inputs (image, video, audio, PDF), thinking/reasoning features, streaming responses, structured outputs with JSON schemas, multi-turn chat, system instructions, image generation (Nano Banana), video generation (Veo), music generation (Lyria), embeddings, document/PDF processing, or any Gemini API integration task. Triggers on mentions of Gemini, Gemini 3, Gemini 2.5, Google AI, Nano Banana, Veo, Lyria, google-genai, or @google/genai SDK usage.
SKILL.md 本文
Gemini API
Google の Gemini API を使用して、テキスト、画像、動画、音声からテキストを生成します。
モデル
| モデル | コード | 入出力 | コンテキスト | 思考 |
|---|---|---|---|---|
| Gemini 3 Pro | gemini-3-pro-preview | テキスト/画像/動画/音声/PDF → テキスト | 1M/64K | はい |
| Gemini 3 Flash | gemini-3-flash-preview | テキスト/画像/動画/音声/PDF → テキスト | 1M/64K | はい |
| Gemini 2.5 Pro | gemini-2.5-pro | テキスト/画像/動画/音声/PDF → テキスト | 1M/65K | はい |
| Gemini 2.5 Flash | gemini-2.5-flash | テキスト/画像/動画/音声 → テキスト | 1M/65K | はい |
| Nano Banana | gemini-2.5-flash-image | テキスト/画像 → 画像 | - | いいえ |
| Nano Banana Pro | gemini-3-pro-image-preview | テキスト/画像 → 画像 (最大 4K) | 65K/32K | はい |
| Veo 3.1 | veo-3.1-generate-preview | テキスト/画像/動画 → 動画+音声 | - | - |
| Veo 3 | veo-3-generate-preview | テキスト/画像 → 動画+音声 | - | - |
| Veo 2 | veo-2.0-generate-001 | テキスト/画像 → 動画 (無音) | - | - |
| Lyria RealTime | lyria-realtime-exp | テキスト → 音楽 (ストリーミング) | - | - |
| エンベディング | gemini-embedding-001 | テキスト → エンベディング | 2K | いいえ |
無料枠: Flash モデルのみ (gemini-3-pro-preview は API に無料枠なし)。デフォルト温度: 1.0 (Gemini 3 では変更しないでください)。
料金 (1M トークンあたり):
- Gemini 3 Pro: $2/$12 (<200k)、$4/$18 (>200k)
- Gemini 3 Flash: $0.50/$3
- Nano Banana Pro: $2 (テキスト) / $0.134 (画像)
基本的なテキスト生成
Python
from google import genai
client = genai.Client()
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="How does AI work?"
)
print(response.text)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "How does AI work?",
});
console.log(response.text);
REST
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-flash-preview:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"contents": [{"parts": [{"text": "How does AI work?"}]}]}'
システムインストラクション
response = client.models.generate_content(
model="gemini-3-flash-preview",
config=types.GenerateContentConfig(
system_instruction="You are a helpful assistant."
),
contents="Hello"
)
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Hello",
config: { systemInstruction: "You are a helpful assistant." },
});
ストリーミング
for chunk in client.models.generate_content_stream(
model="gemini-3-flash-preview",
contents="Tell me a story"
):
print(chunk.text, end="")
const response = await ai.models.generateContentStream({
model: "gemini-3-flash-preview",
contents: "Tell me a story",
});
for await (const chunk of response) {
console.log(chunk.text);
}
マルチターンチャット
chat = client.chats.create(model="gemini-3-flash-preview")
response = chat.send_message("I have 2 dogs.")
print(response.text)
response = chat.send_message("How many paws total?")
print(response.text)
const chat = ai.chats.create({ model: "gemini-3-flash-preview" });
const response = await chat.sendMessage({ message: "I have 2 dogs." });
console.log(response.text);
マルチモーダル (画像)
from PIL import Image
image = Image.open("/path/to/image.png")
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents=[image, "Describe this image"]
)
const image = await ai.files.upload({ file: "/path/to/image.png" });
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: [
createUserContent([
"Describe this image",
createPartFromUri(image.uri, image.mimeType),
]),
],
});
ドキュメント処理 (PDF)
ネイティブビジョン理解を使用して PDF を処理します (最大 1000 ページ)。
from google.genai import types
import pathlib
filepath = pathlib.Path('document.pdf')
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents=[
types.Part.from_bytes(data=filepath.read_bytes(), mime_type='application/pdf'),
"Summarize this document"
]
)
import * as fs from 'fs';
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: [
{ text: "Summarize this document" },
{
inlineData: {
mimeType: 'application/pdf',
data: Buffer.from(fs.readFileSync("document.pdf")).toString("base64")
}
}
]
});
大規模な PDF の場合、Files API (48 時間保存) を使用します:
uploaded_file = client.files.upload(file=pathlib.Path('large.pdf'))
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents=[uploaded_file, "Summarize this document"]
)
Files API、複数の PDF、ベストプラクティスについては references/documents.md を参照してください。
画像生成 (Nano Banana)
会話形式で画像を生成・編集します。
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents="Create a picture of a sunset over mountains",
)
for part in response.parts:
if part.inline_data is not None:
part.as_image().save("generated.png")
const response = await ai.models.generateContent({
model: "gemini-2.5-flash-image",
contents: "Create a picture of a sunset over mountains",
});
for (const part of response.candidates[0].content.parts) {
if (part.inlineData) {
const buffer = Buffer.from(part.inlineData.data, "base64");
fs.writeFileSync("generated.png", buffer);
}
}
Nano Banana Pro (gemini-3-pro-image-preview): 4K 出力、Google Search グラウンディング、最大 14 個のリファレンス画像、思考署名を伴う会話形式の編集。
編集、マルチターン、高度な機能については references/image-generation.md を参照してください。 Gemini 3 の画像機能については references/gemini-3.md を参照してください。
動画生成 (Veo)
Veo を使用して、ネイティブ音声を備えた 8 秒間の 720p、1080p、または 4K 動画を生成します。
import time
from google import genai
client = genai.Client()
operation = client.models.generate_videos(
model="veo-3.1-generate-preview",
prompt="A cinematic shot of a majestic lion in the savannah at golden hour",
)
# 完了するまでポーリング (動画生成は非同期)
while not operation.done:
time.sleep(10)
operation = client.operations.get(operation)
# 動画をダウンロード
video = operation.response.generated_videos[0]
client.files.download(file=video.video)
video.video.save("lion.mp4")
let operation = await ai.models.generateVideos({
model: "veo-3.1-generate-preview",
prompt: "A cinematic shot of a majestic lion in the savannah at golden hour",
});
while (!operation.done) {
await new Promise(resolve => setTimeout(resolve, 10000));
operation = await ai.operations.getVideosOperation({ operation });
}
ai.files.download({
file: operation.response.generatedVideos[0].video,
downloadPath: "lion.mp4",
});
Veo 3.1 の機能: ポートレート (9:16)、動画拡張 (最大 148s)、4K 解像度、ダイアログと効果音を備えたネイティブ音声。
画像から動画への変換、リファレンス画像、動画拡張、プロンプト作成ガイドについては references/veo.md を参照してください。
音楽生成 (Lyria RealTime)
ダイナミック操舵を備えた連続インストゥルメンタル音楽をリアルタイムで生成します。
import asyncio
from google import genai
from google.genai import types
client = genai.Client()
async def main():
async with client.aio.live.music.connect(model='models/lyria-realtime-exp') as session:
# プロンプトと設定を設定
await session.set_weighted_prompts(
prompts=[types.WeightedPrompt(text='minimal techno', weight=1.0)]
)
await session.set_music_generation_config(
config=types.LiveMusicGenerationConfig(bpm=90, temperature=1.0)
)
# ストリーミング開始
await session.play()
# 音声チャンクを受け取る
async for message in session.receive():
if message.server_content and message.server_content.audio_chunks:
audio_data = message.server_content.audio_chunks[0].data
# 音声を処理...
asyncio.run(main())
const session = await ai.live.music.connect({
model: "models/lyria-realtime-exp",
callbacks: {
onmessage: (message) => {
if (message.serverContent?.audioChunks) {
for (const chunk of message.serverContent.audioChunks) {
const audioBuffer = Buffer.from(chunk.data, "base64");
// 音声を処理...
}
}
},
},
});
await session.setWeightedPrompts({
weightedPrompts: [{ text: "minimal techno", weight: 1.0 }],
});
await session.setMusicGenerationConfig({
musicGenerationConfig: { bpm: 90, temperature: 1.0 },
});
await session.play();
出力: 48kHz ステレオ 16 ビット PCM。インストゥルメンタルのみ。BPM、スケール、密度、明るさは設定可能です。
音楽操舵、設定、プロンプト作成ガイドについては references/lyria.md を参照してください。
エンベディング
意味的類似性、検索、分類用のテキストエンベディングを生成します。
result = client.models.embed_content(
model="gemini-embedding-001",
contents="What is the meaning of life?"
)
print(result.embeddings)
const response = await ai.models.embedContent({
model: 'gemini-embedding-001',
contents: 'What is the meaning of life?',
});
console.log(response.embeddings);
タスクタイプ: SEMANTIC_SIMILARITY、CLASSIFICATION、CLUSTERING、RETRIEVAL_DOCUMENT、RETRIEVAL_QUERY
出力次元: 768、1536、3072 (デフォルト)
バッチ処理、タスクタイプ、正規化については references/embeddings.md を参照してください。
思考 (Gemini 3)
thinking_level で推論の深さを制御します: minimal (Flash のみ)、low、medium (Flash のみ)、high (デフォルト)。
from google.genai import types
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Solve this math problem...",
config=types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_level="high")
),
)
import { ThinkingLevel } from "@google/genai";
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Solve this math problem...",
config: { thinkingConfig: { thinkingLevel: ThinkingLevel.HIGH } },
});
注: thinking_level をレガシーな thinking_budget と混在させることはできません (400 エラーが返されます)。
Gemini 2.5 の場合は、代わりに thinking_budget (0-32768) を使用してください。references/thinking.md を参照してください。
完全な Gemini 3 機能 (思考署名、メディア解像度など) については、references/gemini-3.md を参照してください。
構造化出力
スキーマに準拠する JSON レスポンスを生成します。
from pydantic import BaseModel
from typing import List
class Recipe(BaseModel):
name: str
ingredients: List[str]
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="Extract: chocolate chip cookies need flour, sugar, chips",
config={
"response_mime_type": "application/json",
"response_json_schema": Recipe.model_json_schema(),
},
)
recipe = Recipe.model_validate_json(response.text)
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
const recipeSchema = z.object({
name: z.string(),
ingredients: z.array(z.string()),
});
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "Extract: chocolate chip cookies need flour, sugar, chips",
config: {
responseMimeType: "application/json",
responseJsonSchema: zodToJsonSchema(recipeSchema),
},
});
高度なパターンについては references/structured-outputs.md を参照してください。
ビルトインツール (Gemini 3)
利用可能: Google Search、File Search、Code Execution、URL Context、Function Calling
非対応: Google Maps グラウンディング、Computer Use (これらは Gemini 2.5 を使用してください)
response = client.models.generate_content(
model="gemini-3-pro-preview",
contents="What's the latest news on AI?",
config={"tools": [{"google_search": {}}]},
)
const response = await ai.models.generateContent({
model: "gemini-3-pro-preview",
contents: "What's the latest news on AI?",
config: { tools: [{ googleSearch: {} }] },
});
構造化出力 + ツール: Gemini 3 は JSON スキーマをビルトインツール (Google Search、URL Context、Code Execution) と組み合わせることに対応しています。references/gemini-3.md を参照してください。
すべてのツールパターンについては references/tools.md を参照してください。
Function Calling
モデルを外部ツールと API に接続します。モデルが関数の呼び出し時期を判断し、パラメータを提供します。
from google.genai import types
# 関数を定義
get_weather = {
"name": "get_weather",
"description": "Get weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
},
"required": ["location"],
},
}
response = client.models.generate_content(
model="gemini-3-flash-preview",
contents="What's the weather in Tokyo?",
config=types.GenerateContentConfig(
tools=[types.Tool(function_declarations=[get_weather])]
),
)
# 関数呼び出しを確認
if response.function_calls:
fc = response.function_calls[0]
print(f"Call {fc.name} with {fc.args}")
const response = await ai.models.generateContent({
model: "gemini-3-flash-preview",
contents: "What's the weather in Tokyo?",
config: {
tools: [{ functionDeclarations: [getWeather] }],
},
});
if (response.functionCalls) {
const { name, args } = response.functionCalls[0];
// 関数を実行して結果を返送
}
自動関数呼び出し (Python): 自動実行のため、ツールとして関数を直接渡します。
実行モード、合成呼び出し、マルチモーダルレスポンス、MCP インテグレーション、ベストプラクティスについては references/function-calling.md を参照してください。
クイックリファレンス
| 機能 | Python | JavaScript |
|---|---|---|
| 生成 | generate_content() | generateContent() |
| ストリーム | generate_content_stream() | generateContentStream() |
| チャット | chats.create() | chats.create() |
| 構造化 | response_json_schema= | responseJsonSchema: |
| 画像生成 | gemini-2.5-flash-image | gemini-2.5-flash-image |
| 動画生成 | generate_videos() | generateVideos() |
| 音楽生成 | live.music.connect() | live.music.connect() |
| Function Call | function_declarations | functionDeclarations |
| エンベディング | embed_content() | embedContent() |
| Files API | files.upload() | files.upload() |
Gemini 3 固有機能
高度な Gemini 3 機能については、references/gemini-3.md を参照してください:
- 思考レベル: 推論の深さを制御 (
minimal、low、medium、high) - メディア解像度: 細粒度のマルチモーダル処理 (
media_resolution_low~ultra_high) - 思考署名: Function Calling と画像編集コンテキストに必須
- 構造化出力 + ツール: JSON スキーマを Google Search、URL Context と組み合わせ
- マルチモーダル関数レスポンス: ツールレスポンスで画像を返す
リソース
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- majiayu000
- ライセンス
- MIT
- 最終更新
- 2026/5/4
Source: https://github.com/majiayu000/claude-skill-registry / ライセンス: MIT