رابط برنامهنویسی کاربردی v1beta Interactions در حال معرفی تغییرات مهمی است که شکل API را برای پشتیبانی از قابلیتهای آینده مانند هدایت در حین پرواز و فراخوانیهای ابزار ناهمزمان، بازسازی میکند. این صفحه توضیح میدهد که چه چیزی در حال تغییر است و نمونههای کد قبل و بعد را برای کمک به شما در مهاجرت ارائه میدهد. دو دسته تغییر وجود دارد:
- طرحواره مراحل : یک آرایه
stepsجدید جایگزین آرایهoutputsمیشود و یک جدول زمانی ساختاریافته از هر نوبت تعامل ارائه میدهد. - پیکربندی قالب خروجی : یک
response_formatچندریختی جدید، تمام کنترلهای قالب خروجی را تجمیع کرده وresponse_mime_typeحذف میکند.
برای بهروزرسانی یکپارچهسازی، مراحل مربوط به نحوه مهاجرت به طرحواره جدید را دنبال کنید.
تغییر اصلی: outputs به steps
طرحواره جدید، آرایه outputs را با آرایه steps جایگزین میکند.
- Legacy : پاسخها یک آرایه
outputsمسطح را که فقط محتوای تولید شده مدل را شامل میشود، برگرداندند. - طرحواره جدید : پاسخها یک آرایه
stepsرا برمیگردانند که شامل ورودیهای کاربر و خروجیهای مدل است و یک جدول زمانی کامل از نوبت تعامل را ارائه میدهد.
پاسخهای تکمرحلهای (غیرجریانی) ورودی شما را به عنوان اولین مرحله در آرایه steps ) بازتاب میدهند. پاسخهای جریانی از مرحله ورودی صرف نظر میکنند و فقط دلتاهای محتوای تولید شده را منتشر میکنند.
ورودی/خروجی پایه (یگانی)
قبل (میراث)
پایتون
# Request
interaction = client.interactions.create(
model="gemini-3-flash-preview", input="Tell me a joke."
)
# Response access
print(interaction.outputs[0].text)
جاوا اسکریپت
// 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);
استراحت
// 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?"
}
]
}
بعد از (طرحواره جدید)
پایتون
# 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
جاوا اسکریپت
// 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);
استراحت
// 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 مسطح را با مراحل ساختاریافته جایگزین میکند.
قبل (میراث)
پایتون
# Accessing function call in legacy schema
for output in interaction.outputs:
if output.type == "function_call":
print(f"Calling {output.name} with {output.arguments}")
جاوا اسکریپت
// 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)}`);
}
}
استراحت
// 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" }
}
]
}
بعد از (طرحواره جدید)
پایتون
# 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}")
جاوا اسکریپت
// 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)}`);
}
}
استراحت
// 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" }
}
]
}
ابزارهای سمت سرور
ابزارهای سمت سرور (مانند جستجوی گوگل یا اجرای کد) اکنون انواع مراحل خاص را در آرایه steps ارائه میدهند. در حالی که طرحواره قدیمی این عملیات را به عنوان انواع محتوای خاص در آرایه outputs برمیگرداند، طرحواره جدید آنها را به آرایه steps منتقل میکند. مثالهای زیر از جستجوی گوگل استفاده میکنند.
قبل (میراث)
پایتون
# 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}")
جاوا اسکریپت
// 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}`);
}
}
استراحت
// 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"
}
بعد از (طرحواره جدید)
پایتون
# 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}")
جاوا اسکریپت
// 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}`);
}
}
استراحت
// 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.start→interaction.created -
content.start→step.start -
content.delta→step.delta -
content.stop→step.stop -
interaction.complete→interaction.status_updateباstatus: "completed" -
error→interaction.status_updateباstatus: "error" -
interaction.status_update→interaction.status_update(بدون تغییر، اما اکنون حالتهای بیشتری را پوشش میدهد)
فراخوانیهای تابع جریانی : وقتی از جریانی با فراخوانی تابع استفاده میکنید، رویداد step.start نام تابع را ارائه میدهد و رویدادهای step.delta آرگومانها را به صورت رشتههای JSON جزئی (با استفاده از arguments_delta ) جریان میدهند. برای دریافت آرگومانهای کامل، باید این دلتاها را جمع کنید. این با فراخوانیهای تکی که در آن شیء فراخوانی تابع کامل را به طور همزمان دریافت میکنید، متفاوت است.
مثالها
قبل (میراث)
پایتون
# 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)
جاوا اسکریپت
// 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);
}
}
}
استراحت
// 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}}
بعد از (طرحواره جدید)
پایتون
# 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="")
جاوا اسکریپت
// 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);
}
}
}
استراحت
// 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درخواست بعدی ارسال کنید و کاربر جدید turn خود را به عنوان یکuser_inputstep اضافه کنید.
پیکربندی قالب خروجی: تغییرات 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" مشخص کنید.
قبل (میراث)
پایتون
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)
جاوا اسکریپت
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);
استراحت
// 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" }
}
}
}
بعد از (طرحواره جدید)
پایتون
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)
جاوا اسکریپت
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);
استراحت
// 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" مشخص کنید.
قبل (میراث)
پایتون
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"
}
},
)
جاوا اسکریپت
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'
}
},
});
استراحت
// 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"
}
}
}
بعد از (طرحواره جدید)
پایتون
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"
},
)
جاوا اسکریپت
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'
},
});
استراحت
// 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 (پایتون ≥۱.۷۶.۰، جاوا اسکریپت ≥۱.۵۳.۰) ارتقا دهید. SDK به طور خودکار شما را در طرحواره جدید قرار میدهد - هیچ تغییر کدی فراتر از بهروزرسانی نحوه خواندن پاسخها لازم نیست (به مثالهای بالا مراجعه کنید). توجه داشته باشید که فقط طرحواره جدید در این نسخههای SDK پشتیبانی میشود. نسخههای قدیمیتر SDK (پایتون ≤۱.۷۳.۱، جاوا اسکریپت ≤۱.۵۰.۱) تا زمان حذف طرحواره قدیمی در ۶ ژوئن ۲۰۲۶ به کار خود ادامه خواهند داد.
کاربران REST API
برای پذیرش طرحواره جدید، هدر Api-Revision: 2026-05-20 را به درخواستهای خود اضافه کنید. پس از 20 می ، طرحواره جدید به عنوان پیشفرض برای همه درخواستها در نظر گرفته میشود. میتوانید به طور موقت با Api-Revision: 2026-05-06 تا 6 ژوئن ، زمانی که API طرحواره قدیمی را به طور دائم حذف میکند، از این سرویس انصراف دهید.
گاهشمار
| تاریخ | فاز | کاربران SDK | کاربران REST API |
|---|---|---|---|
| ۶ مه | انتخاب کردن | نسخه اصلی SDK جدید (پایتون ≥۲.۰.۰، جاوا اسکریپت ≥۲.۰.۰) در دسترس است. برای دریافت خودکار طرحواره جدید، ارتقا دهید. | برای انتخاب، هدر Api-Revision: 2026-05-20 را اضافه کنید. پیشفرض به قوت خود باقی میماند. |
| ۲۰ مه | برگرداندن پیشفرض | اگر قبلاً ارتقا داده شده باشد، نیازی به اقدام خاصی نیست. SDK های قدیمیتر (Python 1.xx، JS 1.xx) هنوز کار میکنند اما پاسخهای قدیمی را برمیگردانند. | طرحواره جدید اکنون پیشفرض است. برای انصراف، هدر Api-Revision: 2026-05-06 را ارسال کنید. |
| ۶ ژوئن | غروب خورشید | نسخههای SDK نسخه ۱.xx برای پایتون و جاوااسکریپت، برای فراخوانیهای API مربوط به تعاملات، با مشکل مواجه خواهند شد. | طرحواره قدیمی برای API تعاملات حذف شد. هدر Api-Revision نادیده گرفته شد. |
چک لیست مهاجرت
طرحواره مراحل ( steps )
- کد را بهروزرسانی کنید تا محتوای پاسخ را به جای
outputs، از آرایهstepsبخواند. به مثالها مراجعه کنید .. - تأیید کنید که کد شما هر دو نوع گام
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منتقل کنید. به مثالها مراجعه کنید . - (چندوجهی) تبدیل
response_formatاز یک شیء واحد به یک آرایه هنگام درخواست چندین روش خروجی..