Gemini 3.1 Pro API: מדריך למפתחים עם דוגמאות קוד (2026)
מדריך מפתחים מקיף ל-API של Gemini 3.1 Pro. מכסה model IDs (gemini-3.1-pro-preview-customtools), תמחור, דוגמאות קוד ב-Python וב-JavaScript, custom tools, function calling ואינטגרציה באפליקציה שלכם.
סיכום
| Gemini 3.1 Pro | |
|---|---|
| Model IDs | gemini-3.1-pro, gemini-3.1-pro-preview-customtools |
| חלון הקשר | 1M tokens |
| מחיר קלט | $2/1M tokens |
| מחיר פלט | $12/1M tokens |
| תכונות עיקריות | Custom tools, function calling, grounding, מולטימודאלי (טקסט + תמונה + אודיו + וידאו) |
| API | Google AI Studio / Vertex AI |
Gemini 3.1 Pro הוא המודל הפרונטיר החדש ביותר של Google, שהושק במרץ 2026. זהו ה-API הפרונטיר הזול ביותר לכל טוקן, עם הקשר מקורי של 1M, ומציג custom tools.
Model IDs
| Model ID | תיאור | סטטוס |
|---|---|---|
gemini-3.1-pro | גרסה יציבה, זמינות כללית | GA |
gemini-3.1-pro-preview-customtools | תצוגה מקדימה עם תמיכה משופרת ב-custom tools | Preview |
# Google AI Studio
model = "gemini-3.1-pro"
# Vertex AI
model = "gemini-3.1-pro@001"
התחלה מהירה: Python
pip install google-genai
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
npm install @google/genai
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);
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 בקשות/דקה, 1M tokens/דקה, ללא כרטיס אשראי.
תכונות עיקריות
- חלון הקשר 1M tokens — GA, אותו מחיר כמו הקשר רגיל
- Custom tools (function calling) — הצהרת פונקציות חיצוניות ש-Gemini יכול לקרוא
- Grounding עם Google Search — תוצאות חיפוש בזמן אמת
- מולטימודאלי מקורי — טקסט, תמונות, אודיו ווידאו בבקשה אחת
דוגמת קוד: Custom Tools
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 לעומת GPT-5.2 לעומת 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
// 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 הוא ה-API הפרונטיר עם יחס העלות-תועלת הטוב ביותר במרץ 2026. למפתחים: השתמשו ב-Gemini למולטימודאלי ולתקציב, ב-Claude לקידוד וסוכנים, וב-GPT-5.2 לחשיבה מתמטית.
בונים מוצר AI? Y Build מטפל בכל ה-stack. התחילו בחינם.
מקורות:
Be first to build with AI
Y Build is the AI-era operating system for startups. Join the waitlist and get early access.