これが役に立つなら、❤️ を押して他の人が見つけやすくしてください。
Gemini で構築するときに私が何度も調べていることを、1か所にまとめました。
モデル(2026)
| モデル | コンテキスト | おすすめ |
|---|---|---|
| gemini-2.5-flash-preview | 1M トークン | 一般用途、考える作業、高速 |
| gemini-2.5-pro-preview | 1M トークン | 複雑な推論、最高品質 |
| gemini-1.5-flash | 1M トークン | 安定していて本番運用に対応 |
| gemini-1.5-pro | 2M トークン | 最長のコンテキスト |
| gemini-2.0-flash-lite | 1M トークン | 最小レイテンシー、最大ボリューム |
ほとんどのユースケースに:gemini-2.5-flash-preview
無料枠の制限(Google AI Studio)
| モデル | RPM | TPM | RPD |
|---|---|---|---|
| Gemini 2.5 Flash Preview | 10 | 250,000 | 500 |
| Gemini 1.5 Flash | 15 | 1,000,000 | 1,500 |
| Gemini 1.5 Pro | 2 | 32,000 | 50 |
| Gemini 2.0 Flash Lite | 30 | 1,000,000 | 1,500 |
RPM = 1分あたりのリクエスト数、TPM = 1分あたりのトークン数、RPD = 1日あたりのリクエスト数
基本リクエスト(REST)
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:generateContent \
-H "Content-Type: application/json" \
-H "x-goog-api-key: YOUR_API_KEY" \
-d '{
"contents": [{"parts": [{"text": "Your prompt here"}]}]
}'
システムプロンプト付き
{
"system_instruction": {
"parts": [{"text": "You are a helpful assistant."}]
},
"contents": [
{"role": "user", "parts": [{"text": "Your prompt here"}]}
]
}
ストリーミング
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:streamGenerateContent \
-H "Content-Type: application/json" \
-H "x-goog-api-key: YOUR_API_KEY" \
-d '{"contents": [{"parts": [{"text": "Tell me a story"}]}]}'
Rust(reqwest)で
use reqwest::Client;
use serde_json::json;
pub async fn call_gemini(prompt: &str, api_key: &str) -> Result {
let client = Client::new();
let url = format!(
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview:generateContent?key={}",
api_key
);
let body = json!({
"contents": [{"parts": [{"text": prompt}]}]
});
let res = client.post(&url).json(&body).send().await?;
let data: serde_json::Value = res.json().await?;
let text = data["candidates"][0]["content"]["parts"][0]["text"]
.as_str()
.unwrap_or("")
.to_string();
Ok(text)
}
エラーコード
返却形式: {"translated": "翻訳されたHTML"}| コード | 意味 | 対処 |
|---|---|---|
| 400 | 不正なリクエスト / トークン上限 | プロンプトを短くする |
| 403 | 無効なAPIキー | キーを確認する |
| 429 | レート制限に到達 | 待ってから再試行 |
| 500 | 内部エラー | 再試行 |
| 503 | 過負荷 | 2秒待って、1回だけ再試行する |
トークン数の目安
- 1トークン ≈ 英語で4文字
- 1トークン ≈ 日本語で2〜3文字
- logcatの100行 ≈ 3,000〜5,000トークン
- PDFテキスト1ページ ≈ 500〜800トークン
無料のAPIキーを取得する
- aistudio.google.com にアクセス
- Googleでサインイン
- 「Get API Key」をクリック
- 完了 — クレジットカード不要
Hiyoko PDF Vault → https://hiyokoko.gumroad.com/l/HiyokoPDFVault
X → @hiyoyok




