Gemini sedang berpikir
Model seri Gemini 3 dan 2.5 menggunakan "proses berpikir" yang secara signifikan meningkatkan kemampuan penalaran dan perencanaan multi-langkahnya, sehingga sangat efektif untuk tugas-tugas kompleks seperti coding, matematika tingkat lanjut, dan analisis data.
Saat Anda menggunakan model berbasis penalaran, Gemini akan melakukan penalaran secara internal sebelum memberikan respons. Interactions API menampilkan alasan ini melalui langkah-langkah thought, langkah-langkah khusus yang muncul secara kronologis bersama panggilan fungsi, input pengguna, atau output model dalam array steps.
Setiap langkah pemikiran berisi dua kolom:
| Kolom | Wajib | Deskripsi |
|---|---|---|
signature |
✅ Ya | Representasi terenkripsi dari status penalaran internal model. Selalu ada, bahkan saat model melakukan penalaran minimal. |
summary |
❌ Tidak | Serangkaian konten (teks dan/atau gambar) yang merangkum alasan. Mungkin kosong, bergantung pada konfigurasi thinking_summaries, apakah model melakukan penalaran yang cukup, atau jenis konten (misalnya, latensi gambar mungkin tidak memiliki ringkasan teks). |
Interaksi dengan pemikiran
Memulai interaksi dengan model pemikiran serupa dengan permintaan interaksi lainnya. Tentukan salah satu model dengan dukungan pemikiran di kolom model:
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain the concept of Occam's Razor and provide a simple, everyday example."
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Explain the concept of Occam's Razor and provide a simple, everyday example."
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain the concept of Occam'\''s Razor and provide a simple example."
}'
Ringkasan pemikiran
Ringkasan pemikiran memberikan insight tentang proses penalaran internal model.
Secara default, hanya output akhir yang ditampilkan. Anda dapat mengaktifkan ringkasan pemikiran
dengan thinking_summaries:
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="What is the sum of the first 50 prime numbers?",
generation_config={
"thinking_summaries": "auto"
}
)
for step in interaction.steps:
if step.type == "thought":
print("Thought summary:")
for content_block in step.summary:
if content_block.type == "text":
print(content_block.text)
print()
elif step.type == "model_output":
for content_block in step.content:
if content_block.type == "text":
print("Answer:")
print(content_block.text)
print()
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "What is the sum of the first 50 prime numbers?",
generation_config: {
thinking_summaries: "auto"
}
});
for (const step of interaction.steps) {
if (step.type === "thought") {
console.log("Thought summary:");
for (const contentBlock of step.summary) {
if (contentBlock.type === "text") console.log(contentBlock.text);
}
} else if (step.type === "model_output") {
for (const contentBlock of step.content) {
if (contentBlock.type === "text") {
console.log("Answer:");
console.log(contentBlock.text);
}
}
}
}
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "What is the sum of the first 50 prime numbers?",
"generation_config": {
"thinking_summaries": "auto"
}
}'
Blok pemikiran dapat berisi hanya tanda tangan tanpa ringkasan dalam kasus berikut:
- Permintaan sederhana, di mana model tidak cukup bernalar untuk membuat ringkasan
thinking_summaries: "none", tempat ringkasan dinonaktifkan secara eksplisit- Jenis konten pemikiran tertentu, seperti gambar, mungkin tidak memiliki ringkasan teks
Kode Anda harus selalu menangani blok pemikiran saat summary kosong atau tidak ada.
Streaming dengan penalaran
Gunakan streaming untuk menerima ringkasan pemikiran inkremental selama pembuatan. Blok pemikiran dikirimkan menggunakan Peristiwa yang Dikirim Server (SSE) dengan dua jenis delta yang berbeda:
| Jenis delta | Berisi | Waktu dikirim |
|---|---|---|
thought_summary |
Konten ringkasan teks atau gambar | Satu atau beberapa delta dengan ringkasan inkremental |
thought_signature |
Tanda tangan kriptografi | delta terakhir sebelum step.stop |
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
prompt = """
Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue.
Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?
"""
thoughts = ""
answer = ""
stream = client.interactions.create(
model="gemini-3-flash-preview",
input=prompt,
generation_config={
"thinking_summaries": "auto"
},
stream=True
)
for event in stream:
if event.event_type == "step.delta":
if event.delta.type == "thought_summary":
if not thoughts:
print("Thinking...")
summary_text = event.delta.content.get('text', '') if hasattr(event.delta, 'content') else getattr(event.delta, 'text', '')
print(f"[Thought] {summary_text}", end="")
thoughts += summary_text
elif event.delta.type == "text" and event.delta.text:
if not answer:
print("\nAnswer:")
print(event.delta.text, end="")
answer += event.delta.text
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const prompt = `Alice, Bob, and Carol each live in a different house on the same
street: red, green, and blue. Alice does not live in the red house.
Bob does not live in the green house.
Carol does not live in the red or green house.
Which house does each person live in?`;
let thoughts = "";
let answer = "";
const stream = await client.interactions.create({
model: "gemini-3-flash-preview",
input: prompt,
generation_config: {
thinking_summaries: "auto"
},
stream: true
});
for await (const event of stream) {
if (event.event_type === "step.delta") {
if (event.delta.type === "thought_summary") {
if (!thoughts) console.log("Thinking...");
const text = event.delta.content?.text || "";
process.stdout.write(`[Thought] ${text}`);
thoughts += text;
} else if (event.delta.type === "text" && event.delta.text) {
if (!answer) console.log("\nAnswer:");
process.stdout.write(event.delta.text);
answer += event.delta.text;
}
}
}
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
--no-buffer \
-d '{
"model": "gemini-3-flash-preview",
"input": "Alice, Bob, and Carol each live in a different house on the same street: red, green, and blue. Alice does not live in the red house. Bob does not live in the green house. Carol does not live in the red or green house. Which house does each person live in?",
"generation_config": {
"thinking_summaries": "auto"
},
"stream": true
}'
Respons streaming menggunakan Server-Sent Events (SSE) dan terdiri dari langkah-langkah dan peristiwa. Lihat contoh di bawah.
event: interaction.created
data: {"interaction":{"id":"v1_xxx","status":"in_progress","object":"interaction","model":"gemini-3-flash-preview"},"event_type":"interaction.created"}
event: step.start
data: {"index":0,"step":{"signature":"","summary":[{"text":"**Evaluating the clues**\n\nI'm considering...","type":"text"}],"type":"thought"},"event_type":"step.start"}
event: step.delta
data: {"index":0,"delta":{"signature":"EpoGCpcGAXLI2nx/...","type":"thought_signature"},"event_type":"step.delta"}
event: step.stop
data: {"index":0,"event_type":"step.stop"}
event: step.start
data: {"index":1,"step":{"content":[{"text":"Based on the clues provided, here","type":"text"}],"type":"model_output"},"event_type":"step.start"}
event: step.delta
data: {"index":1,"delta":{"text":" is the answer to your question...","type":"text"},"event_type":"step.delta"}
event: step.stop
data: {"index":1,"event_type":"step.stop"}
event: interaction.completed
data: {"interaction":{"id":"v1_xxx","status":"completed","usage":{"total_tokens":530,"total_input_tokens":62,"total_output_tokens":171,"total_thought_tokens":297}},"event_type":"interaction.completed"}
event: done
data: [DONE]
Mengontrol pemikiran
Model Gemini terlibat dalam pemikiran dinamis secara default, dengan otomatis menyesuaikan
jumlah upaya penalaran berdasarkan kompleksitas permintaan. Anda dapat mengontrol perilaku ini menggunakan parameter thinking_level.
| Model | Pemikiran Default | Level yang Didukung |
|---|---|---|
| gemini-3.1-pro-preview | Aktif (tinggi) | rendah, sedang, tinggi |
| gemini-3-flash-preview | Aktif (tinggi) | minimal, rendah, sedang, tinggi |
| gemini-3-pro-preview | Aktif (tinggi) | rendah, tinggi |
| gemini-2.5-pro | Aktif | rendah, sedang, tinggi |
| gemini-2.5-flash | Aktif | rendah, sedang, tinggi |
| gemini-2.5-flash-lite | Nonaktif | rendah, sedang, tinggi |
Python
# This will only work for SDK newer than 2.0.0
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Provide a list of 3 famous physicists and their key contributions",
generation_config={
"thinking_level": "low"
}
)
print(interaction.steps[-1].content[0].text)
JavaScript
// This will only work for SDK newer than 2.0.0
import { GoogleGenAI } from "@google/genai";
const client = new GoogleGenAI({});
const interaction = await client.interactions.create({
model: "gemini-3-flash-preview",
input: "Provide a list of 3 famous physicists and their key contributions",
generation_config: {
thinking_level: "low"
}
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Specifies the API revision to avoid breaking changes when they become default
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Api-Revision: 2026-05-20" \
-H 'Content-Type: application/json' \
-d '{
"model": "gemini-3-flash-preview",
"input": "Provide a list of 3 famous physicists and their key contributions",
"generation_config": {
"thinking_level": "low"
}
}'
Tanda tangan pikiran
Tanda tangan pemikiran adalah representasi terenkripsi dari penalaran internal model. Agen ini harus mempertahankan kontinuitas penalaran di seluruh interaksi multi-giliran.
Interactions API membuat penanganan tanda tangan pemikiran jauh lebih sederhana daripada generateContent API.
Mode Stateful (Direkomendasikan)
Secara default, saat Anda menggunakan Interactions API dalam mode stateful (dengan menyetel store: true dan meneruskan previous_interaction_id pada giliran berikutnya), server akan otomatis mengelola status percakapan, termasuk semua blok pemikiran dan tanda tangan. Dalam mode ini, Anda tidak perlu melakukan apa pun terkait tanda tangan. Semua ini ditangani sepenuhnya di sisi server.
Mode tanpa status
Jika Anda mengelola status percakapan sendiri (mode stateless) dan meneruskan histori lengkap input dan output di setiap permintaan:
- Anda HARUS selalu mengirim ulang semua blok
thoughtpersis seperti yang diterima dari model. - Anda TIDAK boleh menghapus atau mengubah blok pemikiran dari histori, karena blok tersebut berisi tanda tangan yang diperlukan agar model dapat melanjutkan penalaran.
- Saat beralih model dalam sesi, Anda tetap harus mengirim ulang blok pemikiran model sebelumnya. Backend mengelola kompatibilitas.
Harga
Jika penalaran diaktifkan, harga respons adalah jumlah token output dan token penalaran. Anda bisa mendapatkan total jumlah token pemikiran yang dihasilkan dari kolom total_thought_tokens.
Python
# This will only work for SDK newer than 2.0.0
# ...
print("Thoughts tokens:", interaction.usage.total_thought_tokens)
print("Output tokens:", interaction.usage.total_output_tokens)
JavaScript
// This will only work for SDK newer than 2.0.0
// ...
console.log(`Thoughts tokens: ${interaction.usage.total_thought_tokens}`);
console.log(`Output tokens: ${interaction.usage.total_output_tokens}`);
Model pemikiran menghasilkan pemikiran lengkap untuk meningkatkan kualitas respons akhir, lalu menghasilkan ringkasan untuk memberikan insight tentang proses pemikiran. Harga didasarkan pada token pemikiran penuh yang dibutuhkan model untuk dibuat, meskipun hanya ringkasan yang dihasilkan dari API.
Anda dapat mempelajari lebih lanjut token dalam panduan Penghitungan token.
Praktik terbaik
Gunakan model berpikir secara efisien dengan mengikuti panduan berikut.
- Tinjau penalaran: Analisis ringkasan pemikiran untuk memahami kegagalan dan meningkatkan kualitas perintah.
- Mengontrol anggaran penalaran: Beri perintah pada model untuk berpikir lebih sedikit untuk output yang panjang guna menghemat token.
- Tugas sederhana: Menggunakan pemikiran minimal untuk pengambilan atau klasifikasi fakta (misalnya, "Di mana DeepMind didirikan?").
- Tugas moderasi: Gunakan pemikiran default untuk membandingkan konsep atau penalaran kreatif (misalnya, Bandingkan mobil listrik dan hybrid).
- Tugas kompleks: Gunakan pemikiran maksimal untuk coding tingkat lanjut, matematika, atau perencanaan multi-langkah (misalnya, Selesaikan soal matematika AIME).
Langkah berikutnya
- Pembuatan teks: Respons teks dasar
- Panggilan fungsi: Terhubung ke alat
- Panduan Gemini 3: Fitur khusus model