ב-v1beta Interactions API מוצגים שינויים שעלולים לשבור את התאימות לאחור. השינויים האלה משנים את מבנה ה-API כדי לתמוך ביכולות עתידיות כמו הכוונה בזמן ריצה וקריאות אסינכרוניות לכלים. בדף הזה אנחנו מסבירים מה משתנה ומספקים דוגמאות לקוד לפני ואחרי השינוי כדי לעזור לכם לבצע את המעבר. יש שתי קטגוריות של שינויים:
- סכימת השלבים: מערך חדש של
stepsמחליף את המערך שלoutputs, ומספק ציר זמן מובנה של כל תור לאינטראקציה. - הגדרת פורמט הפלט: פולימורפיזם חדש
response_formatמאחד את כל אמצעי הבקרה של פורמט הפלט ומסיר אתresponse_mime_type.
כדי לעדכן את השילוב, פועלים לפי השלבים במאמר איך עוברים לסכימה החדשה.
שינוי מרכזי: outputs ל-steps
הסכימה החדשה מחליפה את המערך outputs במערך steps.
- גרסה קודמת: התשובות הוחזרו כמערך שטוח
outputsשמכיל רק את התוכן שנוצר על ידי המודל. - סכימה חדשה: התשובות מחזירות מערך
stepsשמכיל שלבים מובנים עם מפלים של סוגים.
POST /interactions מחזירה רק שלבי פלט. GET /interactions/{id}
מחזירה את ציר הזמן המלא של השלב, כולל השלב הראשוני user_input.
קלט/פלט בסיסי (אונרי)
לפני (קודם)
Python
# Request
interaction = client.interactions.create(
model="gemini-3-flash-preview", input="Tell me a joke."
)
# Response access
print(interaction.outputs[-1].text)
JavaScript
// Request
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Tell me a joke.'
});
// Response access
console.log(interaction.outputs[-1].text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Tell me a joke."
}'
// Response
{
"id": "int_123",
"role": "model",
"outputs": [
{
"type": "text",
"text": "Why did the chicken cross the road?"
}
]
}
אחרי (סכימה חדשה)
Python
# Request
interaction = client.interactions.create(
model="gemini-3-flash-preview", input="Tell me a joke."
)
# Response access
print(interaction.steps[-1].content[0].text) # CHANGED: steps instead of outputs
JavaScript
// Request
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Tell me a joke.'
});
// Response access
console.log(interaction.steps.at(-1).content[0].text);
REST
# Opt-in needed before May 26th
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Tell me a joke."
}'
// POST Response
{
"id": "int_123",
"steps": [
{
"type": "model_output",
"content": [
{
"type": "text",
"text": "Why did the chicken cross the road?"
}
]
}
]
}
// GET /v1beta/interactions/int_123 (returns full timeline including input)
{
"id": "int_123",
"steps": [
{
"type": "user_input",
"content": [
{ "type": "text", "text": "Tell me a joke." }
]
},
{
"type": "model_output",
"content": [
{
"type": "text",
"text": "Why did the chicken cross the road?"
}
]
}
]
}
בקשה להפעלת פונקציה
מבנה הבקשה נשאר ללא שינוי, אבל התגובה מחליפה את התוכן השטוח outputs בשלבים מובנים.
לפני (קודם)
Python
# Accessing function call in legacy schema
for output in interaction.outputs:
if output.type == "function_call":
print(f"Calling {output.name} with {output.arguments}")
JavaScript
// Accessing function call in legacy schema
for (const output of interaction.outputs) {
if (output.type === 'function_call') {
console.log(`Calling {output.name} with {JSON.stringify(output.arguments)}`);
}
}
REST
// Response
{
"id": "int_001",
"role": "model",
"status": "requires_action",
"outputs": [
{
"type": "thought",
"signature": "abc123..."
},
{
"type": "function_call",
"id": "fc_1",
"name": "get_weather",
"arguments": { "location": "Boston, MA" }
}
]
}
אחרי (סכימה חדשה)
Python
# Accessing function call in new steps schema
for step in interaction.steps:
if step.type == "function_call":
print(f"Calling {step.name} with {step.arguments}")
JavaScript
// Accessing function call in new steps schema
for (const step of interaction.steps) {
if (step.type === 'function_call') {
console.log(`Calling {step.name} with {JSON.stringify(step.arguments)}`);
}
}
REST
// POST Response
{
"id": "int_001",
"status": "requires_action",
"steps": [
{
"type": "thought",
"summary": [{
"type": "text",
"text": "I need to check the weather in Boston..."
}],
"signature": "abc123..."
},
{
"type": "function_call",
"id": "fc_1",
"name": "get_weather",
"arguments": { "location": "Boston, MA" }
}
]
}
כלים בצד השרת
עכשיו כלים בצד השרת (כמו חיפוש Google או Code Execution) מחזירים סוגים ספציפיים של שלבים במערך steps. בזמן שהסכימה הקודמת החזירה את הפעולות האלה כסוגי תוכן ספציפיים במערך outputs, הסכימה החדשה מעבירה אותן למערך steps. הדוגמאות הבאות מתבססות על חיפוש Google.
לפני (קודם)
Python
# Accessing search results in legacy schema
for output in interaction.outputs:
if output.type == "google_search_call":
print(f"Searched for: {output.arguments.queries}")
elif output.type == "google_search_result":
print(f"Found results: {output.result.rendered_content}")
JavaScript
// Accessing search results in legacy schema
for (const output of interaction.outputs) {
if (output.type === 'google_search_call') {
console.log(`Searched for: {output.arguments.queries}`);
} else if (output.type === 'google_search_result') {
console.log(`Found results: {output.result.renderedContent}`);
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Who won the last Super Bowl?",
"tools": [
{ "type": "google_search" }
]
}'
// Response
{
"id": "int_456",
"outputs": [
{
"type": "google_search_call",
"id": "gs_1",
"arguments": { "queries": ["last Super Bowl winner"] }
},
{
"type": "google_search_result",
"call_id": "gs_1",
"result": {
"rendered_content": "<div>...</div>",
"url": "https://www.nfl.com/super-bowl"
}
},
{
"type": "text",
"text": "The Kansas City Chiefs won the last Super Bowl.",
"annotations": [
{
"start_index": 4,
"end_index": 22,
"source": "https://www.nfl.com/super-bowl"
}
]
}
],
"status": "completed"
}
אחרי (סכימה חדשה)
Python
# Accessing search results in new steps schema
for step in interaction.steps:
if step.type == "google_search_call":
print(f"Searched for: {step.arguments.queries}")
elif step.type == "google_search_result":
print(f"Found results: {step.result.search_suggestions}")
JavaScript
// Accessing search results in new steps schema
for (const step of interaction.steps) {
if (step.type === 'google_search_call') {
console.log(`Searched for: {step.arguments.queries}`);
} else if (step.type === 'google_search_result') {
console.log(`Found results: {step.result.searchSuggestions}`);
}
}
REST
# Opt-in needed before May 26th
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Who won the last Super Bowl?",
"tools": [
{ "type": "google_search" }
]
}'
// POST Response
{
"id": "int_456",
"steps": [
{
"type": "google_search_call",
"id": "gs_1",
"arguments": { "queries": ["last Super Bowl winner"] },
"signature": "abc123..."
},
{
"type": "google_search_result",
"call_id": "gs_1",
"result": {
"search_suggestions": "<div>...</div>"
},
"signature": "abc123..."
},
{
"type": "model_output",
"content": [
{
"type": "text",
"text": "The Kansas City Chiefs won the last Super Bowl.",
"annotations": [
{
"type": "url_citation",
"url": "https://www.nfl.com/super-bowl",
"title": "NFL.com",
"start_index": 4,
"end_index": 22
}
]
}
]
}
],
"status": "completed"
}
סטרימינג
הסטרימינג חושף סוגים חדשים של אירועים:
סוגי אירועים חדשים
interaction.createdinteraction.completedinteraction.in_progressinteraction.requires_actionstep.startstep.deltastep.stop
סוגי אירועים שיצאו משימוש
סוגי האירועים הבאים מדור קודם מוחלפים באירועים החדשים שמופיעים למעלה:
interaction.start←interaction.createdcontent.start←step.startcontent.delta←step.deltacontent.stop←step.stopinteraction.complete←interaction.completed-
interaction.status_update← הוחלף על ידיinteraction.in_progress,interaction.requires_actionוכו'.
הזרמת קריאות לפונקציות: כשמשתמשים בהזרמה עם קריאות לפונקציות, האירוע step.start מעביר את שם הפונקציה, והאירועים step.delta מזרימים את הארגומנטים כמחרוזות JSON חלקיות (באמצעות arguments_delta). צריך לצבור את הדלתאות האלה כדי לקבל את הארגומנטים המלאים. זה שונה מקריאות unary, שבהן מקבלים את האובייקט המלא של בקשה להפעלת פונקציה בבת אחת.
דוגמאות
לפני (דור קודם)
Python
# Legacy streaming used content.delta
stream = client.interactions.create(
model="gemini-3-flash-preview",
input="Explain quantum entanglement in simple terms.",
stream=True,
)
for chunk in stream:
if chunk.event_type == "content.delta":
if chunk.delta.type == "text":
print(chunk.delta.text, end="", flush=True)
JavaScript
// Legacy streaming used content.delta
const stream = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Explain quantum entanglement in simple terms.',
stream: true,
});
for await (const chunk of stream) {
if (chunk.event_type === 'content.delta') {
if (chunk.delta.type === 'text') {
process.stdout.write(chunk.delta.text);
}
}
}
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Explain quantum entanglement in simple terms.",
"stream": true
}'
// Response (SSE Lines)
// event: interaction.start
// data: {"id": "int_123", "status": "in_progress"}
//
// event: content.start
// data: {"index": 0, "type": "text"}
//
// event: content.delta
// data: {"delta": {"type": "text", "text": "Quantum entanglement is..."}}
//
// event: content.stop
// data: {"index": 0}
//
// event: interaction.complete
// data: {"id": "int_123", "status": "done", "usage": {"total_tokens": 42}}
אחרי (סכימה חדשה)
Python
# Consuming stream and handling new event types
for event in client.interactions.create(
model="gemini-3-flash-preview",
input="Tell me a story.",
stream=True,
):
if event.type == "step.delta": # CHANGED: step.delta instead of content.delta
if event.delta.type == "text":
print(event.delta.text, end="")
JavaScript
// Consuming stream and handling new event types
const stream = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Tell me a story.',
stream: true,
});
for await (const event of stream) {
if (event.type === 'step.delta') { // CHANGED: step.delta instead of content.delta
if (event.delta.type === 'text') {
process.stdout.write(event.delta.text);
}
}
}
REST
# Opt-in needed before May 26th
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Tell me a story.",
"stream": true
}'
// Response (SSE Lines)
// event: interaction.created
// data: {"interaction": {"id": "int_xyz", "status": "in_progress", "object": "interaction", "model": "gemini-3-flash-preview"}, "event_type": "interaction.created"}
//
// event: interaction.in_progress
// data: {"interaction_id": "int_xyz", "event_type": "interaction.in_progress"}
//
// event: step.start
// data: {"index": 0, "step": {"type": "thought", "signature": "abc123..."}, "event_type": "step.start"}
//
// event: step.stop
// data: {"index": 0, "event_type": "step.stop"}
//
// event: step.start
// data: {"index": 1, "step": {"content": [{"text": "Once upon", "type": "text"}], "type": "model_output"}, "event_type": "step.start"}
//
// event: step.delta
// data: {"index": 1, "delta": {"text": " a time...", "type": "text"}, "event_type": "step.delta"}
//
// event: step.stop
// data: {"type": "step.stop", "index": 1, "status": "done"}
//
// event: interaction.completed
// data: {"type": "interaction.completed", "interaction": {"id": "int_xyz", "status": "completed", "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15}}} // NEW: Dedicated completion event
היסטוריית שיחות ללא שמירת מצב
אם אתם מנהלים את היסטוריית השיחות באופן ידני בצד הלקוח (תרחיש שימוש בלי שמירת מצב), אתם צריכים לעדכן את האופן שבו אתם מחברים בין תורות קודמות.
- גרסה קודמת: מפתחים אספו לעיתים קרובות את מערך
outputsמהתגובות ושלחו אותן בחזרה בשדהinputבתור הבא. - סכימה חדשה: עכשיו צריך לאסוף את מערך
stepsמהתגובה ולהעביר אותו בשדהinputשל הבקשה הבאה, ולצרף את תור המשתמש החדש כשלבuser_input.
הגדרות פורמט הפלט: response_format שינויים
ב-API המעודכן, כל אמצעי הבקרה של פורמט הפלט מאוחדים בשדה response_format פולימורפי. כך ההגדרה של הפלט מתבצעת במקום אחד ברמה העליונה, וההתמקדות של generation_config היא בהתנהגות המודל (כמו רמת אקראיות, Top-P והעמקה).
שינויים מרכזיים
- ה-API מסיר את
response_mime_type. עכשיו מציינים את סוג ה-MIME לכל רשומה של פורמט בתוךresponse_format. response_formatהוא עכשיו אובייקט (או מערך) פולימורפי. לכל רשומה יש דיסקרימינטורtype(text, audio, image) ושדות ספציפיים לסוג. כדי לבקש כמה אופנים של פלט, מעבירים מערך של רשומות פורמט.image_configעובר מ-generation_configאלresponse_format. עכשיו אפשר לציין הגדרות של פלט תמונה כמוaspect_ratioו-image_sizeבתוך רשומה שלresponse_formatעם"type": "image".
פלט מובנה (JSON)
הסכימה החדשה מסירה את השדה response_mime_type. במקום זאת, מציינים את סוג ה-MIME ואת סכימת ה-JSON בתוך אובייקט response_format עם "type": "text".
לפני (קודם)
Python
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Summarize this article.",
response_mime_type="application/json",
response_format={
"type": "object",
"properties": {
"summary": {"type": "string"}
}
},
)
print(interaction.outputs[-1].text)
JavaScript
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Summarize this article.',
response_mime_type: 'application/json',
response_format: {
type: 'object',
properties: {
summary: { type: 'string' }
}
},
});
console.log(interaction.outputs[-1].text);
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Summarize this article.",
"response_mime_type": "application/json",
"response_format": {
"type": "object",
"properties": {
"summary": { "type": "string" }
}
}
}'
אחרי (סכימה חדשה)
Python
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Summarize this article.",
# response_mime_type is removed — specify mime_type inside response_format
response_format={
"type": "text",
"mime_type": "application/json",
"schema": {
"type": "object",
"properties": {
"summary": {"type": "string"}
}
}
},
)
print(interaction.steps[-1].content[0].text)
JavaScript
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Summarize this article.',
// response_mime_type is removed — specify mime_type inside response_format
response_format: {
type: 'text',
mime_type: 'application/json',
schema: {
type: 'object',
properties: {
summary: { type: 'string' }
}
}
},
});
console.log(interaction.steps.at(-1).content[0].text);
REST
# Opt-in needed before May 26th
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Summarize this article.",
"response_format": {
"type": "text",
"mime_type": "application/json",
"schema": {
"type": "object",
"properties": {
"summary": { "type": "string" }
}
}
}
}'
הגדרת תמונה
הסכימה החדשה מסירה את image_config מ-generation_config. עכשיו אפשר לציין הגדרות של פלט תמונה ברשומה response_format עם "type": "image".
לפני (קודם)
Python
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Generate an image of a sunset over the ocean.",
generation_config={
"image_config": {
"aspect_ratio": "1:1",
"image_size": "1K"
}
},
)
JavaScript
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Generate an image of a sunset over the ocean.',
generation_config: {
image_config: {
aspect_ratio: '1:1',
image_size: '1K'
}
},
});
REST
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Generate an image of a sunset over the ocean.",
"generation_config": {
"image_config": {
"aspect_ratio": "1:1",
"image_size": "1K"
}
}
}'
אחרי (סכימה חדשה)
Python
interaction = client.interactions.create(
model="gemini-3-flash-preview",
input="Generate an image of a sunset over the ocean.",
# image_config is removed from generation_config — use response_format
response_format={
"type": "image",
"mime_type": "image/jpeg",
"aspect_ratio": "1:1",
"image_size": "1K"
},
)
JavaScript
const interaction = await client.interactions.create({
model: 'gemini-3-flash-preview',
input: 'Generate an image of a sunset over the ocean.',
// image_config is removed from generation_config — use response_format
response_format: {
type: 'image',
mime_type: 'image/jpeg',
aspect_ratio: '1:1',
image_size: '1K'
},
});
REST
# Opt-in needed before May 26th
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-H "Api-Revision: 2026-05-20" \
-d '{
"model": "gemini-3-flash-preview",
"input": "Generate an image of a sunset over the ocean.",
"response_format": {
"type": "image",
"mime_type": "image/jpeg",
"aspect_ratio": "1:1",
"image_size": "1K"
}
}'
כדי לבקש כמה פורמטים של פלט (למשל, טקסט ואודיו ביחד), צריך להעביר מערך של רשומות פורמט אל response_format במקום אובייקט יחיד.
איך עוברים לסכימה החדשה
משתמשי SDK
שדרוג לגרסת ה-SDK העדכנית ביותר (Python ≥2.0.0, JavaScript ≥2.0.0). ה-SDK מפעיל את הסכימה החדשה באופן אוטומטי – לא צריך לשנות את הקוד, רק לעדכן את אופן קריאת התגובות (ראו דוגמאות למעלה). שימו לב שרק הסכימה החדשה נתמכת בגרסאות האלה של ה-SDK. גרסאות ישנות יותר של SDK (Python 1.x.x, JavaScript 1.x.x) ימשיכו לפעול עד להסרת סכימת הנתונים מדור קודם ב-8 ביוני 2026.
משתמשי REST API
כדי להצטרף לתוכנית עם הסכימה החדשה, מוסיפים את הכותרת Api-Revision: 2026-05-20 לבקשות. אחרי 26 במאי, הסכימה החדשה תהפוך לברירת המחדל לכל הבקשות. אפשר להשבית את התכונה באופן זמני באמצעות Api-Revision: 2026-05-07
עד 8 ביוני, ואז ה-API יסיר לצמיתות את סכימת הנתונים מדור קודם.
ציר הזמן
| תאריך | שלב | משתמשי SDK | משתמשי REST API |
|---|---|---|---|
| 7 במאי | הבעת הסכמה | גרסת SDK חדשה זמינה (Python ≥2.0.0, JS ≥2.0.0). כדאי לשדרג כדי לקבל את הסכימה החדשה באופן אוטומטי. | הוספת הכותרת Api-Revision: 2026-05-20 להסכמה להצטרפות. ברירת המחדל נשארת מדור קודם. |
| 26 במאי | היפוך ברירת המחדל | אם כבר שדרגתם, לא צריך לעשות כלום. SDKs ישנים יותר (Python 1.x.x, JS 1.x.x) עדיין פועלים, אבל מחזירים תשובות מדור קודם. | הסכימה החדשה מוגדרת עכשיו כברירת מחדל. כדי לבטל את ההסכמה, שולחים את הכותרת Api-Revision: 2026-05-07. |
| 8 ביוני | שקיעה | גרסאות Python 1.x.x ו-JS 1.x.x SDK יפסיקו לפעול בקריאות ל-Interactions API. | הסרנו את סכימת הנתונים הקודמת של Interactions API. הכותרת Api-Revision לא נכללה. |
הגירה - רשימת משימות לביצוע
סכימת השלבים (steps)
- צריך לעדכן את הקוד כדי לקרוא את תוכן התשובה מהמערך
stepsבמקום מ-outputs. דוגמאות - מוודאים שהקוד מטפל בשני סוגי השלבים
user_inputו-model_output. דוגמאות - (קריאה לפונקציות) עדכון קוד כדי למצוא
function_callשלבים במערךsteps. דוגמאות - (כלים בצד השרת) מעדכנים את הקוד כדי לטפל בשלבים ספציפיים לכלים (למשל
google_search_call,google_search_result). דוגמאות - (היסטוריה בלי שמירת מצב) עדכון של ניהול ההיסטוריה כדי להעביר את המערך [
steps] בשדה [input] של הבקשה הבאה. פרטים נוספים - (סטרימינג בלבד) עדכון הלקוח להאזנה לסוגים חדשים של אירועי SSE (
interaction.created, step.deltaוכו'). דוגמאות
הגדרת פורמט הפלט (response_format)
- מחליפים את
response_mime_typeבשדהmime_typeבתוךresponse_format. דוגמאות - עוטפים את סכימת ה-JSON הקיימת
response_formatבאובייקט{"type": "text", "schema": ...}. דוגמאות - (יצירת תמונות) העברה של
image_configמ-generation_configלרשומה{"type": "image", ...}ב-response_format. דוגמאות - (Multimodal) המרת
response_formatמאובייקט יחיד למערך כשמבקשים כמה אופנויות פלט.