Gemini 3.1 Pro API : Guide Développeur avec Exemples de Code (2026)
Guide développeur complet pour l'API Gemini 3.1 Pro. Couvre les model IDs (gemini-3.1-pro-preview-customtools), les tarifs, les exemples de code en Python et JavaScript, les custom tools, le function calling et l'intégration dans votre app.
Résumé
| Gemini 3.1 Pro | |
|---|---|
| Model IDs | gemini-3.1-pro, gemini-3.1-pro-preview-customtools |
| Fenêtre de contexte | 1M tokens |
| Prix input | 2 $/1M tokens |
| Prix output | 12 $/1M tokens |
| Fonctionnalités clés | Custom tools, function calling, grounding, multimodal (texte + image + audio + vidéo) |
| API | Google AI Studio / Vertex AI |
Gemini 3.1 Pro est le dernier modèle frontier de Google, lancé en mars 2026. C'est l'API frontier la moins chère par token, avec un contexte natif de 1M et l'introduction des custom tools.
Model IDs
| Model ID | Description | Statut |
|---|---|---|
gemini-3.1-pro | Version stable, disponibilité générale | GA |
gemini-3.1-pro-preview-customtools | Preview avec support amélioré des custom tools | Preview |
# Google AI Studio
model = "gemini-3.1-pro"
# Vertex AI
model = "gemini-3.1-pro@001"
Démarrage Rapide : 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)
Démarrage Rapide : 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.
Tarifs
| Gemini 3.1 Pro | GPT-5.2 | Claude Sonnet 4.6 | |
|---|---|---|---|
| Input | 2 $/1M | 5 $/1M | 3 $/1M |
| Output | 12 $/1M | 15 $/1M | 15 $/1M |
| Contexte | 1M | 400K | 1M (beta) |
Offre gratuite : 60 requêtes/min, 1M tokens/min, pas de carte bancaire requise.
Fonctionnalités Clés
- Fenêtre de contexte 1M tokens — GA, même prix que le contexte standard
- Custom tools (function calling) — déclarer des fonctions externes que Gemini peut appeler
- Grounding avec Google Search — résultats de recherche en temps réel
- Multimodal natif — texte, images, audio et vidéo dans une seule requête
Exemple de Code : 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]),
)
Comparaison API : Gemini 3.1 Pro vs GPT-5.2 vs Claude Sonnet 4.6
| Fonctionnalité | Gemini 3.1 Pro | GPT-5.2 | Claude Sonnet 4.6 |
|---|---|---|---|
| Prix input | 2 $/1M | 5 $/1M | 3 $/1M |
| Contexte | 1M (GA) | 400K | 1M (beta) |
| Multimodal | Texte+image+audio+vidéo | Texte+image+audio | Texte+image |
| Coding (SWE-bench) | 76,8 % | 80,0 % | 79,6 % |
Intégration avec 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));
}
Conclusion
Gemini 3.1 Pro est la meilleure API frontier en termes de rapport qualité-prix en mars 2026. Pour les développeurs : utilisez Gemini pour le multimodal et les budgets serrés, Claude pour le coding et les agents, et GPT-5.2 pour le raisonnement mathématique.
Vous construisez un produit IA ? Y Build gère toute la stack. Commencez gratuitement.
Sources :
Be first to build with AI
Y Build is the AI-era operating system for startups. Join the waitlist and get early access.