تُجري واجهة برمجة التطبيقات v1beta من Interactions 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.5-flash", input="Tell me a joke."
)
# Response access
print(interaction.outputs[-1].text)
JavaScript
// Request
const interaction = await client.interactions.create({
model: 'gemini-3.5-flash',
input: 'Tell me a joke.'
});
// Response access
console.log(interaction.outputs[-1].text);
راحة
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"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.5-flash", input="Tell me a joke."
)
# Response access (Recommended sugar)
print(interaction.output_text)
JavaScript
// Request
const interaction = await client.interactions.create({
model: 'gemini-3.5-flash',
input: 'Tell me a joke.'
});
// Response access (Recommended sugar)
console.log(interaction.output_text);
[sdk-convenience]: /gemini-api/docs/interactions#convenience-properties
راحة
# 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.5-flash",
"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)}`);
}
}
راحة
// 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)}`);
}
}
راحة
// 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" أو "تنفيذ الرموز البرمجية") الآن أنواعًا معيّنة من الخطوات في مصفوفة 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}`);
}
}
راحة
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"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}`);
}
}
راحة
# 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.5-flash",
"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.completedinteraction.status_update← تم استبدالها بـinteraction.in_progressوinteraction.requires_actionوما إلى ذلك
استدعاءات الدوال في البث: عند استخدام البث مع استدعاء الدوال،
يقدّم الحدث step.start اسم الدالة، وتعمل أحداث step.delta على
بثّ الوسيطات كسلاسل JSON جزئية (باستخدام arguments_delta). يجب
تجميع هذه التغييرات الجزئية للحصول على الوسيطات الكاملة. يختلف ذلك عن الاستدعاءات الأحادية التي تتلقّى فيها كائن استدعاء الدالة الكامل مرة واحدة.
أمثلة
قبل (الإصدار القديم)
Python
# Legacy streaming used content.delta
stream = client.interactions.create(
model="gemini-3.5-flash",
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.5-flash',
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);
}
}
}
راحة
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"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.5-flash",
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.5-flash',
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);
}
}
}
راحة
# 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.5-flash",
"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.5-flash"}, "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
يوحّد الإصدار المعدَّل من واجهة برمجة التطبيقات جميع عناصر التحكّم في تنسيق الإخراج في حقل response_format موحّد ومتعدد الأشكال. يؤدي ذلك إلى مركزة إعدادات الإخراج على المستوى الأعلى ويحافظ على تركيز generation_config على سلوك النموذج (مثل درجة العشوائية وأعلى احتمال تراكمي والتفكير).
أهم التغييرات
- تزيل واجهة برمجة التطبيقات
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.5-flash",
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.5-flash',
input: 'Summarize this article.',
response_mime_type: 'application/json',
response_format: {
type: 'object',
properties: {
summary: { type: 'string' }
}
},
});
console.log(interaction.outputs[-1].text);
راحة
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"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.5-flash",
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 response
print(interaction.output_text)
JavaScript
const interaction = await client.interactions.create({
model: 'gemini-3.5-flash',
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 response
console.log(interaction.output_text);
راحة
# 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.5-flash",
"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.5-flash",
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.5-flash',
input: 'Generate an image of a sunset over the ocean.',
generation_config: {
image_config: {
aspect_ratio: '1:1',
image_size: '1K'
}
},
});
راحة
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?key=$GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.5-flash",
"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.5-flash",
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.5-flash',
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'
},
});
راحة
# 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.5-flash",
"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 يونيو، عندما تزيل واجهة برمجة التطبيقات المخطط القديم نهائيًا.
المخطط الزمني
| التاريخ | المرحلة | مستخدِمو حزمة تطوير البرامج (SDK) | مستخدِمو REST API |
|---|---|---|---|
| 7 مايو | اشتراك | يتوفّر إصدار جديد من حزمة تطوير البرامج (SDK) (Python ≥2.0.0 وJS ≥2.0.0). رقِّ للحصول على المخطط الجديد تلقائيًا. | أضِف العنوان Api-Revision: 2026-05-20 للاشتراك. يبقى المخطط القديم هو المخطط التلقائي. |
| 26 مايو | قلب تلقائي | ليس عليك اتّخاذ أي إجراء إذا كنت قد رقّيت بالفعل. تستمر حزم تطوير البرامج (SDK) الأقدم (Python 1.x.x وJS 1.x.x) في العمل، ولكنها تعرض الردود القديمة. | أصبح المخطط الجديد هو المخطط التلقائي الآن. أرسِل العنوان Api-Revision: 2026-05-07 لإيقاف الاشتراك. |
| 8 يونيو | الغروب | ستتوقف إصدارات حزمة تطوير البرامج (SDK) Python 1.x.x وJS 1.x.x عن العمل لاستدعاءات 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. راجِع الأمثلة. - (متعدد الوسائط) حوِّل
response_formatمن كائن واحد إلى مصفوفة عند طلب وسائط إخراج متعددة.