·Y Build Team
Gemini 3.1 Pro API:コード例付き開発者ガイド(2026年)
Gemini 3.1 Pro APIの完全な開発者ガイド。モデルID(gemini-3.1-pro-preview-customtools)、料金、PythonとJavaScriptのコード例、カスタムツール、関数呼び出し、アプリへの統合方法を網羅。
GeminiGoogleAPIDeveloper GuidePythonJavaScriptAIFunction Calling2026
Y
G3概要
| Gemini 3.1 Pro | |
|---|---|
| モデルID | gemini-3.1-pro, gemini-3.1-pro-preview-customtools |
| コンテキストウィンドウ | 100万トークン |
| 入力料金 | $2/100万トークン |
| 出力料金 | $12/100万トークン |
| 主要機能 | カスタムツール、関数呼び出し、グラウンディング、マルチモーダル(テキスト+画像+音声+動画) |
| API | Google AI Studio / Vertex AI |
Gemini 3.1 ProはGoogleの最新フロンティアモデルで、2026年3月にリリースされました。トークン単価で最も安価なフロンティアAPIで、ネイティブ100万コンテキストを持ち、カスタムツールを導入しています。
モデルID
| モデルID | 説明 | ステータス |
|---|---|---|
gemini-3.1-pro | 安定版リリース、一般提供 | GA |
gemini-3.1-pro-preview-customtools | カスタムツールサポートが強化されたプレビュー | Preview |
# Google AI Studio
model = "gemini-3.1-pro"
# Vertex AI
model = "gemini-3.1-pro@001"
クイックスタート:Python
bash
pip install google-genai
python
from google import genai
client = genai.Client(api_key="YOUR_API_KEY")
response = client.models.generate_content(
model="gemini-3.1-pro",
contents="Explain quantum computing in 3 sentences."
)
print(response.text)
クイックスタート:JavaScript
bash
npm install @google/genai
javascript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: "YOUR_API_KEY" });
const response = await ai.models.generateContent({
model: "gemini-3.1-pro",
contents: "Explain quantum computing in 3 sentences.",
});
console.log(response.text);
Early Access
Be first to build with AI
Y Build is the AI-era operating system for startups. Join the waitlist and get early access.
料金
| Gemini 3.1 Pro | GPT-5.2 | Claude Sonnet 4.6 | |
|---|---|---|---|
| 入力 | $2/1M | $5/1M | $3/1M |
| 出力 | $12/1M | $15/1M | $15/1M |
| コンテキスト | 1M | 400K | 1M (beta) |
無料プラン:60リクエスト/分、100万トークン/分、クレジットカード不要。
主要機能
- 100万トークンコンテキストウィンドウ — GA、標準コンテキストと同価格
- カスタムツール(関数呼び出し) — Geminiが呼び出せる外部関数を宣言
- Google Searchによるグラウンディング — リアルタイム検索結果
- ネイティブマルチモーダル — テキスト、画像、音声、動画を1つのリクエストで
コード例:カスタムツール
Python
python
from google import genai
from google.genai import types
client = genai.Client(api_key="YOUR_API_KEY")
weather_tool = types.Tool(
function_declarations=[
types.FunctionDeclaration(
name="get_weather",
description="Get the current weather for a city",
parameters=types.Schema(
type=types.Type.OBJECT,
properties={
"city": types.Schema(type=types.Type.STRING, description="City name"),
"unit": types.Schema(type=types.Type.STRING, enum=["celsius", "fahrenheit"]),
},
required=["city"],
),
)
]
)
response = client.models.generate_content(
model="gemini-3.1-pro-preview-customtools",
contents="What's the weather like in Tokyo?",
config=types.GenerateContentConfig(tools=[weather_tool]),
)
API比較:Gemini 3.1 Pro vs GPT-5.2 vs Claude Sonnet 4.6
| 機能 | Gemini 3.1 Pro | GPT-5.2 | Claude Sonnet 4.6 |
|---|---|---|---|
| 入力料金 | $2/1M | $5/1M | $3/1M |
| コンテキスト | 1M (GA) | 400K | 1M (beta) |
| マルチモーダル | テキスト+画像+音声+動画 | テキスト+画像+音声 | テキスト+画像 |
| コーディング (SWE-bench) | 76.8% | 80.0% | 79.6% |
Y Buildとの統合
javascript
// In a Y Build project (Cloudflare Worker)
export async function onRequest(context) {
const response = await fetch(
"https://generativelanguage.googleapis.com/v1beta/models/gemini-3.1-pro:generateContent",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-goog-api-key": context.env.GEMINI_API_KEY,
},
body: JSON.stringify({
contents: [{ parts: [{ text: "Your prompt here" }] }],
}),
}
);
const data = await response.json();
return new Response(JSON.stringify(data));
}
まとめ
Gemini 3.1 Proは2026年3月時点で最もコストパフォーマンスの高いフロンティアAPIです。開発者へのアドバイス:マルチモーダルとコスト重視にはGemini、コーディングとエージェントにはClaude、数学的推論にはGPT-5.2を使いましょう。
AI製品を構築中ですか?Y Buildがスタック全体を担います。無料で始める。
出典:
Early Access
Be first to build with AI
Y Build is the AI-era operating system for startups. Join the waitlist and get early access.