‫Interactions API: מדריך להעברת שינויים שגורמים לבעיות (מאי 2026)

ב-v1beta Interactions API מוצגים שינויים שעלולים לשבור את התאימות לאחור. השינויים האלה משנים את מבנה ה-API כדי לתמוך ביכולות עתידיות כמו הכוונה בזמן ריצה וקריאות אסינכרוניות לכלים. בדף הזה אנחנו מסבירים מה משתנה ומספקים דוגמאות לקוד לפני ואחרי השינוי כדי לעזור לכם לבצע את המעבר. יש שתי קטגוריות של שינויים:

  1. סכימת השלבים: מערך חדש של steps מחליף את המערך של outputs, ומספק ציר זמן מובנה של כל תור לאינטראקציה.
  2. הגדרת פורמט הפלט: פולימורפיזם חדש response_format מאחד את כל אמצעי הבקרה של פורמט הפלט ומסיר את response_mime_type.

כדי לעדכן את השילוב, פועלים לפי השלבים במאמר איך עוברים לסכימה החדשה.

שינוי מרכזי: outputs ל-steps

הסכימה החדשה מחליפה את המערך outputs במערך steps.

  • גרסה קודמת: התשובות הוחזרו כמערך שטוח outputs שמכיל רק את התוכן שנוצר על ידי המודל.
  • סכימה חדשה: התשובות מחזירות מערך steps שכולל גם את נתוני הקלט של המשתמשים וגם את הפלט של המודל, וכך מספקות ציר זמן מלא של תור האינטראקציה.

תגובות אונריות (לא סטרימינג) משקפות את הקלט שלכם כשלב הראשון במערך steps. שידור תשובות מדלג על שלב הקלט ופולט רק דלתאות של תוכן שנוצר.

קלט/פלט בסיסי (אונרי)

לפני (קודם)

Python

# Request
interaction = client.interactions.create(
    model="gemini-3-flash-preview", input="Tell me a joke."
)

# Response access
print(interaction.outputs[0].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[0].text);

REST

// Request: POST /v1beta/interactions
{
  "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

// Request: POST /v1beta/interactions
{
  "model": "gemini-3-flash-preview",
  "input": "Tell me a joke."
}

// Response
{
  "id": "int_123",
  "steps": [
    {
      "type": "user_input",
      "status": "done",
      "content": [
        {
          "type": "text",
          "text": "Tell me a joke."
        }
      ]
    },
    {
      "type": "model_output",
      "status": "done",
      "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

// Response
{
  "id": "int_001",
  "status": "requires_action",
  "steps": [
    {
      "type": "user_input",
      "status": "done",
      "content": [
        { "type": "text", "text": "What's the weather in Boston?" }
      ]
    },
    {
      "type": "thought",
      "status": "done",
      "signature": "abc123..."
    },
    {
      "type": "function_call",
      "status": "waiting",
      "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

// Request: POST /v1beta/interactions
{
  "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

// Request: POST /v1beta/interactions
{
  "model": "gemini-3-flash-preview",
  "input": "Who won the last Super Bowl?",
  "tools": [
    { "type": "google_search" }
  ]
}

// Response
{
  "id": "int_456",
  "steps": [
    {
      "type": "user_input",
      "status": "done",
      "content": [
        { "type": "text", "text": "Who won the last Super Bowl?" }
      ]
    },
    {
      "type": "google_search_call",
      "status": "done",
      "id": "gs_1",
      "arguments": { "queries": ["last Super Bowl winner"] },
      "signature": "abc123..."
    },
    {
      "type": "google_search_result",
      "status": "done",
      "call_id": "gs_1",
      "result": {
        "search_suggestions": "<div>...</div>"
      },
      "signature": "abc123..."
    },
    {
      "type": "model_output",
      "status": "done",
      "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.created
  • interaction.status_update – עכשיו כולל את כל מצבי מחזור החיים, כולל השלמה ושגיאות (ראו את הסטטוסים בהמשך)
  • step.start
  • step.delta
  • step.stop
interaction.status_update סטטוסים
  • in_progress
  • active
  • completed
  • interrupted
  • requires_action
  • error

סוגי אירועים שיצאו משימוש

סוגי האירועים הבאים מדור קודם מוחלפים באירועים החדשים שמופיעים למעלה:

  • interaction.startinteraction.created
  • content.startstep.start
  • content.deltastep.delta
  • content.stopstep.stop
  • interaction.completeinteraction.status_update עם status: "completed"
  • errorinteraction.status_update עם status: "error"
  • interaction.status_updateinteraction.status_update (ללא שינוי, אבל עכשיו כולל מדינות נוספות)

הזרמת קריאות לפונקציות: כשמשתמשים בהזרמה עם קריאות לפונקציות, האירוע 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

// Request: POST /v1beta/interactions
{
  "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

 // Request: POST /v1beta/interactions
 // Accept: text/event-stream
 {
   "model": "gemini-3-flash-preview",
   "input": "Tell me a story."
 }

 // Response (SSE Lines)
 // event: interaction.created
 // data: {"type": "interaction.created", "interaction": {"id": "int_xyz", "status": "created"}} // CHANGED: 'type' instead of 'event_type'
 //
 // event: interaction.status_update
 // data: {"type": "interaction.status_update", "status": "in_progress"} // NEW: Lifecycle status updates in stream (postpone until Sessions launch dependency)
 //
 // event: step.start
 // data: {"type": "step.start", "index": 0, "step": {"type": "thought"}} // NEW: Replaces content.start, 'step' instead of 'content'
 //
 // event: step.delta
 // data: {"type": "step.delta", "index": 0, "delta": {"type": "thought", "text": "User wants an explanation."}} // NEW: Delta type matches step type
 //
 // event: step.stop
 // data: {"type": "step.stop", "index": 0, "status": "done"} // NEW: Includes status
 //
 // event: step.start
 // data: {"type": "step.start", "index": 1, "step": {"type": "model_output"}} // NEW: Step wrapper for output
 //
 // event: step.delta
 // data: {"type": "step.delta", "index": 1, "delta": {"type": "text", "text": "Hello"}}
 //
 // event: step.stop
 // data: {"type": "step.stop", "index": 1, "status": "done"}
 //
 // event: interaction.complete
 // data: {"type": "interaction.complete", "interaction": {"id": "int_xyz", "status": "completed", "usage": {"prompt_tokens": 10, "completion_tokens": 5, "total_tokens": 15}}} // NEW: End of stream event with interaction details

היסטוריית שיחות ללא שמירת מצב

אם אתם מנהלים את היסטוריית השיחות באופן ידני בצד הלקוח (תרחיש שימוש בלי שמירת מצב), אתם צריכים לעדכן את האופן שבו אתם מחברים בין תורות קודמות.

  • גרסה קודמת: מפתחים אספו לעיתים קרובות את מערך 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[0].text)

JavaScript

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Summarize this article.',
    responseMimeType: 'application/json',
    responseFormat: {
        type: 'object',
        properties: {
            summary: { type: 'string' }
        }
    },
});

console.log(interaction.outputs[0].text);

REST

// Request: POST /v1beta/interactions
{
  "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.',
    // responseMimeType is removed — specify mimeType inside responseFormat
    responseFormat: {
        type: 'text',
        mimeType: 'application/json',
        schema: {
            type: 'object',
            properties: {
                summary: { type: 'string' }
            }
        }
    },
});

console.log(interaction.steps.at(-1).content[0].text);

REST

// Request: POST /v1beta/interactions
{
  "model": "gemini-3-flash-preview",
  "input": "Summarize this article.",
  // response_mime_type is removed
  "response_format": {
    "type": "text",                          // NEW: type discriminator
    "mime_type": "application/json",          // MOVED: from response_mime_type
    "schema": {                              // RENAMED: was response_format directly
      "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.',
    generationConfig: {
        imageConfig: {
            aspectRatio: '1:1',
            imageSize: '1K'
        }
    },
});

REST

// Request: POST /v1beta/interactions
{
  "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",
        "delivery": "inline",
        "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.',
    // imageConfig is removed from generationConfig — use responseFormat
    responseFormat: {
        type: 'image',
        mimeType: 'image/jpeg',
        delivery: 'inline',
        aspectRatio: '1:1',
        imageSize: '1K'
    },
});

REST

// Request: POST /v1beta/interactions
{
  "model": "gemini-3-flash-preview",
  "input": "Generate an image of a sunset over the ocean.",
  // image_config removed from generation_config
  "response_format": {
    "type": "image",                         // NEW: type discriminator
    "mime_type": "image/jpeg",
    "delivery": "inline",
    "aspect_ratio": "1:1",                   // MOVED: from generation_config.image_config
    "image_size": "1K"                       // MOVED: from generation_config.image_config
  }
}

כדי לבקש כמה פורמטים של פלט (למשל, טקסט ואודיו ביחד), צריך להעביר מערך של רשומות פורמט אל response_format במקום אובייקט יחיד.

איך עוברים לסכימה החדשה

משתמשי SDK

שדרוג לגרסה האחרונה של ה-SDK‏ (Python ≥1.76.0, ‏ JavaScript ≥1.53.0). ה-SDK מפעיל את הסכימה החדשה באופן אוטומטי – לא צריך לשנות את הקוד, רק לעדכן את אופן קריאת התגובות (ראו דוגמאות למעלה). שימו לב שרק הסכימה החדשה נתמכת בגרסאות האלה של ה-SDK. גרסאות ישנות יותר של ה-SDK (Python ≤1.73.1,‏ JavaScript ≤1.50.1) ימשיכו לפעול עד להסרת סכימת הנתונים מדור קודם ב-6 ביוני 2026.

משתמשי REST API

כדי להצטרף לתוכנית עם הסכימה החדשה, מוסיפים את הכותרת Api-Revision: 2026-05-20 לבקשות. אחרי 20 במאי, הסכימה החדשה תהפוך לברירת המחדל לכל הבקשות. אפשר להשבית את ה-API באופן זמני באמצעות Api-Revision: 2026-05-06 עד 6 ביוני, ואז ה-API יסיר לצמיתות את הסכימה מדור קודם.

ציר הזמן

תאריך שלב משתמשי SDK משתמשי REST API
6 במאי הבעת הסכמה גרסה ראשית חדשה של SDK זמינה (Python ≥2.0.0, ‏ JS ≥2.0.0). כדאי לשדרג כדי לקבל את הסכימה החדשה באופן אוטומטי. הוספת הכותרת Api-Revision: 2026-05-20 להסכמה להצטרפות. ברירת המחדל נשארת מדור קודם.
May 20 היפוך ברירת המחדל אם כבר שדרגתם, לא צריך לעשות כלום. ‫SDKs ישנים יותר (Python 1.x.x,‏ JS 1.x.x) עדיין פועלים, אבל מחזירים תשובות מדור קודם. הסכימה החדשה מוגדרת עכשיו כברירת מחדל. כדי לבטל את ההסכמה, שולחים את הכותרת Api-Revision: 2026-05-06.
‫6 ביוני שקיעה גרסאות SDK‏ 1.x.x ל-Python ול-JS יפסיקו לפעול בקריאות ל-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) Convert response_format from a single object to an array when requesting multiple output modalities..