ইন্টারঅ্যাকশন API

ইন্টারঅ্যাকশন API ( বিটা ) হল জেমিনি মডেল এবং এজেন্টদের সাথে ইন্টারঅ্যাক্ট করার জন্য একটি ইউনিফাইড ইন্টারফেস। এটি স্টেট ম্যানেজমেন্ট, টুল অর্কেস্ট্রেশন এবং দীর্ঘমেয়াদী কাজগুলিকে সহজ করে তোলে। API স্কিমার বিস্তৃত দৃশ্যের জন্য, API রেফারেন্স দেখুন। বিটা চলাকালীন, বৈশিষ্ট্য এবং স্কিমাগুলিতে ব্রেকিং পরিবর্তন হতে পারে।

নিচের উদাহরণটি দেখায় কিভাবে টেক্সট প্রম্পট ব্যবহার করে ইন্টারঅ্যাকশন API কল করতে হয়।

পাইথন

from google import genai

client = genai.Client()

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

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction =  await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a short joke about programming.',
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a short joke about programming."
}'

মৌলিক মিথস্ক্রিয়া

আমাদের বিদ্যমান SDK গুলির মাধ্যমে ইন্টারঅ্যাকশন API উপলব্ধ। মডেলের সাথে ইন্টারঅ্যাক্ট করার সবচেয়ে সহজ উপায় হল একটি টেক্সট প্রম্পট প্রদান করা। input একটি স্ট্রিং, একটি কন্টেন্ট অবজেক্ট ধারণকারী একটি তালিকা, অথবা ভূমিকা এবং কন্টেন্ট অবজেক্ট সহ টার্নের একটি তালিকা হতে পারে।

পাইথন

from google import genai

client = genai.Client()

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

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction =  await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a short joke about programming.',
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a short joke about programming."
}'

কথা-বার্তা

আপনি দুটি উপায়ে বহু-পালা কথোপকথন তৈরি করতে পারেন:

  • পূর্ববর্তী মিথস্ক্রিয়া উল্লেখ করে স্পষ্টভাবে
  • সম্পূর্ণ কথোপকথনের ইতিহাস প্রদান করে রাষ্ট্রহীনভাবে

রাষ্ট্রীয় কথোপকথন

কথোপকথন চালিয়ে যেতে পূর্ববর্তী ইন্টারঅ্যাকশন থেকে id previous_interaction_id প্যারামিটারে পাস করুন।

পাইথন

from google import genai

client = genai.Client()

# 1. First turn
interaction1 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Hi, my name is Phil."
)
print(f"Model: {interaction1.outputs[-1].text}")

# 2. Second turn (passing previous_interaction_id)
interaction2 = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is my name?",
    previous_interaction_id=interaction1.id
)
print(f"Model: {interaction2.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. First turn
const interaction1 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Hi, my name is Phil.'
});
console.log(`Model: ${interaction1.outputs[interaction1.outputs.length - 1].text}`);

// 2. Second turn (passing previous_interaction_id)
const interaction2 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What is my name?',
    previous_interaction_id: interaction1.id
});
console.log(`Model: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);

বিশ্রাম

# 1. First turn
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Hi, my name is Phil."
}'

# 2. Second turn (Replace INTERACTION_ID with the ID from the previous interaction)
# curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
# -H "Content-Type: application/json" \
# -H "x-goog-api-key: $GEMINI_API_KEY" \
# -d '{
#     "model": "gemini-3-flash-preview",
#     "input": "What is my name?",
#     "previous_interaction_id": "INTERACTION_ID"
# }'

অতীতের রাষ্ট্রীয় মিথস্ক্রিয়া পুনরুদ্ধার করুন

কথোপকথনের পূর্ববর্তী মোড়গুলি পুনরুদ্ধার করতে ইন্টারঅ্যাকশন id ব্যবহার করা।

পাইথন

previous_interaction = client.interactions.get("<YOUR_INTERACTION_ID>")

print(previous_interaction)

জাভাস্ক্রিপ্ট

const previous_interaction = await client.interactions.get("<YOUR_INTERACTION_ID>");
console.log(previous_interaction);

বিশ্রাম

curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/<YOUR_INTERACTION_ID>" \
-H "x-goog-api-key: $GEMINI_API_KEY"

রাষ্ট্রহীন কথোপকথন

আপনি ক্লায়েন্টের পক্ষ থেকে কথোপকথনের ইতিহাস ম্যানুয়ালি পরিচালনা করতে পারেন।

পাইথন

from google import genai

client = genai.Client()

conversation_history = [
    {
        "role": "user",
        "content": "What are the three largest cities in Spain?"
    }
]

interaction1 = client.interactions.create(
    model="gemini-3-flash-preview",
    input=conversation_history
)

print(f"Model: {interaction1.outputs[-1].text}")

conversation_history.append({"role": "model", "content": interaction1.outputs})
conversation_history.append({
    "role": "user",
    "content": "What is the most famous landmark in the second one?"
})

interaction2 = client.interactions.create(
    model="gemini-3-flash-preview",
    input=conversation_history
)

print(f"Model: {interaction2.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const conversationHistory = [
    {
        role: 'user',
        content: "What are the three largest cities in Spain?"
    }
];

const interaction1 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: conversationHistory
});

console.log(`Model: ${interaction1.outputs[interaction1.outputs.length - 1].text}`);

conversationHistory.push({ role: 'model', content: interaction1.outputs });
conversationHistory.push({
    role: 'user',
    content: "What is the most famous landmark in the second one?"
});

const interaction2 = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: conversationHistory
});

console.log(`Model: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);

বিশ্রাম

 curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
 -H "Content-Type: application/json" \
 -H "x-goog-api-key: $GEMINI_API_KEY" \
 -d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {
            "role": "user",
            "content": "What are the three largest cities in Spain?"
        },
        {
            "role": "model",
            "content": "The three largest cities in Spain are Madrid, Barcelona, and Valencia."
        },
        {
            "role": "user",
            "content": "What is the most famous landmark in the second one?"
        }
    ]
}'

মাল্টিমোডাল ক্ষমতা

আপনি ইমেজ বোঝার বা ভিডিও তৈরির মতো মাল্টিমোডাল ব্যবহারের ক্ষেত্রে ইন্টারঅ্যাকশন API ব্যবহার করতে পারেন।

বহুমুখী বোঝাপড়া

আপনি বেস৬৪-এনকোডেড ডেটা ইনলাইন হিসেবে মাল্টিমোডাল ইনপুট প্রদান করতে পারেন, বড় ফাইলের জন্য Files API ব্যবহার করে, অথবা uri ক্ষেত্রে একটি সর্বজনীনভাবে অ্যাক্সেসযোগ্য লিঙ্ক পাস করে। নিম্নলিখিত কোড নমুনাগুলি সর্বজনীন URL পদ্ধতি প্রদর্শন করে।

চিত্র বোঝাপড়া

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "Describe the image."},
        {
            "type": "image",
            "uri": "YOUR_URL",
            "mime_type": "image/png"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import {GoogleGenAI} from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        {type: 'text', text: 'Describe the image.'},
        {
            type: 'image',
            uri: 'YOUR_URL',
            mime_type: 'image/png'
        }
    ]
});
console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
    {
        "type": "text",
        "text": "Describe the image."
    },
    {
        "type": "image",
        "uri": "YOUR_URL",
        "mime_type": "image/png"
    }
    ]
}'

অডিও বোঝাপড়া

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What does this audio say?"},
        {
            "type": "audio",
            "uri": "YOUR_URL",
            "mime_type": "audio/wav"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What does this audio say?' },
        {
            type: 'audio',
            uri: 'YOUR_URL',
            mime_type: 'audio/wav'
        }
    ]
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What does this audio say?"},
        {
            "type": "audio",
            "uri": "YOUR_URL",
            "mime_type": "audio/wav"
        }
    ]
}'

ভিডিও বোঝাপড়া

পাইথন

from google import genai
client = genai.Client()

print("Analyzing video...")
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What is happening in this video? Provide a timestamped summary."},
        {
            "type": "video",
            "uri": "YOUR_URL",
            "mime_type": "video/mp4"
        }
    ]
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

console.log('Analyzing video...');
const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What is happening in this video? Provide a timestamped summary.' },
        {
            type: 'video',
            uri: 'YOUR_URL',
            mime_type: 'video/mp4'
        }
    ]
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What is happening in this video?"},
        {
            "type": "video",
            "uri": "YOUR_URL",
            "mime_type": "video/mp4"
        }
    ]
}'

ডকুমেন্ট (পিডিএফ) বোঝাপড়া

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {"type": "text", "text": "What is this document about?"},
        {
            "type": "document",
            "uri": "YOUR_URL",
            "mime_type": "application/pdf"
        }
    ]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'text', text: 'What is this document about?' },
        {
            type: 'document',
            uri: 'YOUR_URL',
            mime_type: 'application/pdf'
        }
    ],
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "text", "text": "What is this document about?"},
        {
            "type": "document",
            "uri": "YOUR_URL",
            "mime_type": "application/pdf"
        }
    ]
}'

মাল্টিমোডাল জেনারেশন

মাল্টিমোডাল আউটপুট তৈরি করতে আপনি ইন্টারঅ্যাকশন API ব্যবহার করতে পারেন।

চিত্র তৈরি

পাইথন

import base64
from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-pro-image-preview",
    input="Generate an image of a futuristic city.",
    response_modalities=["IMAGE"]
)

for output in interaction.outputs:
    if output.type == "image":
        print(f"Generated image with mime_type: {output.mime_type}")
        # Save the image
        with open("generated_city.png", "wb") as f:
            f.write(base64.b64decode(output.data))

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-pro-image-preview',
    input: 'Generate an image of a futuristic city.',
    response_modalities: ['IMAGE']
});

for (const output of interaction.outputs) {
    if (output.type === 'image') {
        console.log(`Generated image with mime_type: ${output.mime_type}`);
        // Save the image
        fs.writeFileSync('generated_city.png', Buffer.from(output.data, 'base64'));
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-pro-image-preview",
    "input": "Generate an image of a futuristic city.",
    "response_modalities": ["IMAGE"]
}'

বক্তৃতা তৈরি

টেক্সট-টু-স্পিচ (TTS) মডেল ব্যবহার করে টেক্সট থেকে প্রাকৃতিক-সাউন্ডিং স্পিচ তৈরি করুন। speech_config ব্যবহার করে ভয়েস, ভাষা এবং স্পিকার সেটিংস কনফিগার করুন।
প্যারামিটার।

পাইথন

import base64
from google import genai
import wave

# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
    with wave.open(filename, "wb") as wf:
        wf.setnchannels(channels)
        wf.setsampwidth(sample_width)
        wf.setframerate(rate)
        wf.writeframes(pcm)

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-2.5-flash-preview-tts",
    input="Say the following: WOOHOO This is so much fun!.",
    response_modalities=["AUDIO"],
    generation_config={
        "speech_config": {
            "language": "en-us",
            "voice": "kore"
        }
    }
)

for output in interaction.outputs:
    if output.type == "audio":
        print(f"Generated audio with mime_type: {output.mime_type}")
        # Save the audio as wave file to the current directory.
        wave_file("generated_audio.wav", base64.b64decode(output.data))

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
import wav from 'wav';

async function saveWaveFile(
    filename,
    pcmData,
    channels = 1,
    rate = 24000,
    sampleWidth = 2,
) {
    return new Promise((resolve, reject) => {
        const writer = new wav.FileWriter(filename, {
                channels,
                sampleRate: rate,
                bitDepth: sampleWidth * 8,
        });

        writer.on('finish', resolve);
        writer.on('error', reject);

        writer.write(pcmData);
        writer.end();
    });
}

async function main() {
    const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
    const client = new GoogleGenAI({apiKey: GEMINI_API_KEY});

    const interaction = await client.interactions.create({
        model: 'gemini-2.5-flash-preview-tts',
        input: 'Say the following: WOOHOO This is so much fun!.',
        response_modalities: ['AUDIO'],
        generation_config: {
            speech_config: {
                language: "en-us",
                voice: "kore"
            }
        }
    });

    for (const output of interaction.outputs) {
        if (output.type === 'audio') {
            console.log(`Generated audio with mime_type: ${output.mime_type}`);
            const audioBuffer = Buffer.from(output.data, 'base64');
            // Save the audio as wave file to the current directory
            await saveWaveFile("generated_audio.wav", audioBuffer);
        }
    }
}
await main();

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-flash-preview-tts",
    "input": "Say the following: WOOHOO This is so much fun!.",
    "response_modalities": ["AUDIO"],
    "generation_config": {
        "speech_config": {
            "language": "en-us",
            "voice": "kore"
        }
    }
}' | jq -r '.outputs[] | select(.type == "audio") | .data' | base64 -d > generated_audio.pcm
# You may need to install ffmpeg.
ffmpeg -f s16le -ar 24000 -ac 1 -i generated_audio.pcm generated_audio.wav
মাল্টি-স্পিকার স্পিচ জেনারেশন

প্রম্পটে স্পিকারের নাম উল্লেখ করে এবং speech_config এ তাদের সাথে মিলিয়ে একাধিক স্পিকার দিয়ে স্পিচ তৈরি করুন।

প্রম্পটে বক্তার নাম অন্তর্ভুক্ত করা উচিত:

TTS the following conversation between Alice and Bob:
Alice: Hi Bob, how are you doing today?
Bob: I'm doing great, thanks for asking! How about you?
Alice: Fantastic! I just learned about the Gemini API.

তারপর ম্যাচিং স্পিকার দিয়ে speech_config কনফিগার করুন:

"generation_config": {
    "speech_config": [
        {"voice": "Zephyr", "speaker": "Alice", "language": "en-US"},
        {"voice": "Puck", "speaker": "Bob", "language": "en-US"}
    ]
}

এজেন্টিক ক্ষমতা

ইন্টারঅ্যাকশন API এজেন্ট তৈরি এবং তাদের সাথে ইন্টারঅ্যাক্ট করার জন্য ডিজাইন করা হয়েছে এবং এতে ফাংশন কলিং, বিল্ট-ইন টুলস, স্ট্রাকচার্ড আউটপুট এবং মডেল কনটেক্সট প্রোটোকল (MCP) এর জন্য সমর্থন অন্তর্ভুক্ত রয়েছে।

এজেন্ট

জটিল কাজের জন্য আপনি deep-research-pro-preview-12-2025 এর মতো বিশেষায়িত এজেন্ট ব্যবহার করতে পারেন। জেমিনি ডিপ রিসার্চ এজেন্ট সম্পর্কে আরও জানতে, ডিপ রিসার্চ গাইডটি দেখুন।

পাইথন

import time
from google import genai

client = genai.Client()

# 1. Start the Deep Research Agent
initial_interaction = client.interactions.create(
    input="Research the history of the Google TPUs with a focus on 2025 and 2026.",
    agent="deep-research-pro-preview-12-2025",
    background=True
)

print(f"Research started. Interaction ID: {initial_interaction.id}")

# 2. Poll for results
while True:
    interaction = client.interactions.get(initial_interaction.id)
    print(f"Status: {interaction.status}")

    if interaction.status == "completed":
        print("\nFinal Report:\n", interaction.outputs[-1].text)
        break
    elif interaction.status in ["failed", "cancelled"]:
        print(f"Failed with status: {interaction.status}")
        break

    time.sleep(10)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. Start the Deep Research Agent
const initialInteraction = await client.interactions.create({
    input: 'Research the history of the Google TPUs with a focus on 2025 and 2026.',
    agent: 'deep-research-pro-preview-12-2025',
    background: true
});

console.log(`Research started. Interaction ID: ${initialInteraction.id}`);

// 2. Poll for results
while (true) {
    const interaction = await client.interactions.get(initialInteraction.id);
    console.log(`Status: ${interaction.status}`);

    if (interaction.status === 'completed') {
        console.log('\nFinal Report:\n', interaction.outputs[interaction.outputs.length - 1].text);
        break;
    } else if (['failed', 'cancelled'].includes(interaction.status)) {
        console.log(`Failed with status: ${interaction.status}`);
        break;
    }

    await new Promise(resolve => setTimeout(resolve, 10000));
}

বিশ্রাম

# 1. Start the Deep Research Agent
curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "input": "Research the history of the Google TPUs with a focus on 2025 and 2026.",
    "agent": "deep-research-pro-preview-12-2025",
    "background": true
}'

# 2. Poll for results (Replace INTERACTION_ID with the ID from the previous interaction)
# curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/INTERACTION_ID" \
# -H "x-goog-api-key: $GEMINI_API_KEY"

টুল এবং ফাংশন কলিং

এই বিভাগটি ব্যাখ্যা করে যে কীভাবে কাস্টম টুল সংজ্ঞায়িত করতে ফাংশন কলিং ব্যবহার করতে হয় এবং ইন্টারঅ্যাকশন API-এর মধ্যে Google-এর অন্তর্নির্মিত টুলগুলি কীভাবে ব্যবহার করতে হয়।

ফাংশন কলিং

পাইথন

from google import genai

client = genai.Client()

# 1. Define the tool
def get_weather(location: str):
    """Gets the weather for a given location."""
    return f"The weather in {location} is sunny."

weather_tool = {
    "type": "function",
    "name": "get_weather",
    "description": "Gets the weather for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
        },
        "required": ["location"]
    }
}

# 2. Send the request with tools
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="What is the weather in Paris?",
    tools=[weather_tool]
)

# 3. Handle the tool call
for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Tool Call: {output.name}({output.arguments})")
        # Execute tool
        result = get_weather(**output.arguments)

        # Send result back
        interaction = client.interactions.create(
            model="gemini-3-flash-preview",
            previous_interaction_id=interaction.id,
            input=[{
                "type": "function_result",
                "name": output.name,
                "call_id": output.id,
                "result": result
            }]
        )
        print(f"Response: {interaction.outputs[-1].text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

// 1. Define the tool
const weatherTool = {
    type: 'function',
    name: 'get_weather',
    description: 'Gets the weather for a given location.',
    parameters: {
        type: 'object',
        properties: {
            location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA' }
        },
        required: ['location']
    }
};

// 2. Send the request with tools
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'What is the weather in Paris?',
    tools: [weatherTool]
});

// 3. Handle the tool call
for (const output of interaction.outputs) {
    if (output.type === 'function_call') {
        console.log(`Tool Call: ${output.name}(${JSON.stringify(output.arguments)})`);

        // Execute tool (Mocked)
        const result = `The weather in ${output.arguments.location} is sunny.`;

        // Send result back
        interaction = await client.interactions.create({
            model: 'gemini-3-flash-preview',
            previous_interaction_id:interaction.id,
            input: [{
                type: 'function_result',
                name: output.name,
                call_id: output.id,
                result: result
            }]
        });
        console.log(`Response: ${interaction.outputs[interaction.outputs.length - 1].text}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "What is the weather in Paris?",
    "tools": [{
        "type": "function",
        "name": "get_weather",
        "description": "Gets the weather for a given location.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"}
            },
            "required": ["location"]
        }
    }]
}'

# Handle the tool call and send result back (Replace INTERACTION_ID and CALL_ID)
# curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
# -H "Content-Type: application/json" \
# -H "x-goog-api-key: $GEMINI_API_KEY" \
# -d '{
#     "model": "gemini-3-flash-preview",
#     "previous_interaction_id": "INTERACTION_ID",
#     "input": [{
#         "type": "function_result",
#         "name": "get_weather",
#         "call_id": "FUNCTION_CALL_ID",
#         "result": "The weather in Paris is sunny."
#     }]
# }'
ক্লায়েন্ট-সাইড স্টেট সহ ফাংশন কলিং

আপনি যদি সার্ভার-সাইড স্টেট ব্যবহার করতে না চান, তাহলে আপনি ক্লায়েন্ট সাইডে সবকিছু পরিচালনা করতে পারেন।

পাইথন

from google import genai
client = genai.Client()

functions = [
    {
        "type": "function",
        "name": "schedule_meeting",
        "description": "Schedules a meeting with specified attendees at a given time and date.",
        "parameters": {
            "type": "object",
            "properties": {
                "attendees": {"type": "array", "items": {"type": "string"}},
                "date": {"type": "string", "description": "Date of the meeting (e.g., 2024-07-29)"},
                "time": {"type": "string", "description": "Time of the meeting (e.g., 15:00)"},
                "topic": {"type": "string", "description": "The subject of the meeting."},
            },
            "required": ["attendees", "date", "time", "topic"],
        },
    }
]

history = [{"role": "user","content": [{"type": "text", "text": "Schedule a meeting for 2025-11-01 at 10 am with Peter and Amir about the Next Gen API."}]}]

# 1. Model decides to call the function
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=history,
    tools=functions
)

# add model interaction back to history
history.append({"role": "model", "content": interaction.outputs})

for output in interaction.outputs:
    if output.type == "function_call":
        print(f"Function call: {output.name} with arguments {output.arguments}")

        # 2. Execute the function and get a result
        # In a real app, you would call your function here.
        # call_result = schedule_meeting(**json.loads(output.arguments))
        call_result = "Meeting scheduled successfully."

        # 3. Send the result back to the model
        history.append({"role": "user", "content": [{"type": "function_result", "name": output.name, "call_id": output.id, "result": call_result}]})

        interaction2 = client.interactions.create(
            model="gemini-3-flash-preview",
            input=history,
        )
        print(f"Final response: {interaction2.outputs[-1].text}")
    else:
        print(f"Output: {output}")

জাভাস্ক্রিপ্ট

// 1. Define the tool
const functions = [
    {
        type: 'function',
        name: 'schedule_meeting',
        description: 'Schedules a meeting with specified attendees at a given time and date.',
        parameters: {
            type: 'object',
            properties: {
                attendees: { type: 'array', items: { type: 'string' } },
                date: { type: 'string', description: 'Date of the meeting (e.g., 2024-07-29)' },
                time: { type: 'string', description: 'Time of the meeting (e.g., 15:00)' },
                topic: { type: 'string', description: 'The subject of the meeting.' },
            },
            required: ['attendees', 'date', 'time', 'topic'],
        },
    },
];

const history = [
    { role: 'user', content: [{ type: 'text', text: 'Schedule a meeting for 2025-11-01 at 10 am with Peter and Amir about the Next Gen API.' }] }
];

// 2. Model decides to call the function
let interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: history,
    tools: functions
});

// add model interaction back to history
history.push({ role: 'model', content: interaction.outputs });

for (const output of interaction.outputs) {
    if (output.type === 'function_call') {
        console.log(`Function call: ${output.name} with arguments ${JSON.stringify(output.arguments)}`);

        // 3. Send the result back to the model
        history.push({ role: 'user', content: [{ type: 'function_result', name: output.name, call_id: output.id, result: 'Meeting scheduled successfully.' }] });

        const interaction2 = await client.interactions.create({
            model: 'gemini-3-flash-preview',
            input: history,
        });
        console.log(`Final response: ${interaction2.outputs[interaction2.outputs.length - 1].text}`);
    }
}

অন্তর্নির্মিত সরঞ্জাম

জেমিনি বিল্ট-ইন টুলগুলির সাথে আসে যেমন গুগল সার্চের সাথে গ্রাউন্ডিং , কোড এক্সিকিউশন , ইউআরএল কনটেক্সট এবং কম্পিউটার ব্যবহার।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Who won the last Super Bowl?",
    tools=[{"type": "google_search"}]
)
# Find the text output (not the GoogleSearchResultContent)
text_output = next((o for o in interaction.outputs if o.type == "text"), None)
if text_output:
    print(text_output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Who won the last Super Bowl?',
    tools: [{ type: 'google_search' }]
});
// Find the text output (not the GoogleSearchResultContent)
const textOutput = interaction.outputs.find(o => o.type === 'text');
if (textOutput) console.log(textOutput.text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Who won the last Super Bowl?",
    "tools": [{"type": "google_search"}]
}'
কোড এক্সিকিউশন

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Calculate the 50th Fibonacci number.",
    tools=[{"type": "code_execution"}]
)
print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Calculate the 50th Fibonacci number.',
    tools: [{ type: 'code_execution' }]
});
console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Calculate the 50th Fibonacci number.",
    "tools": [{"type": "code_execution"}]
}'
URL প্রসঙ্গ

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Summarize the content of https://www.wikipedia.org/",
    tools=[{"type": "url_context"}]
)
# Find the text output (not the URLContextResultContent)
text_output = next((o for o in interaction.outputs if o.type == "text"), None)
if text_output:
    print(text_output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Summarize the content of https://www.wikipedia.org/',
    tools: [{ type: 'url_context' }]
});
// Find the text output (not the URLContextResultContent)
const textOutput = interaction.outputs.find(o => o.type === 'text');
if (textOutput) console.log(textOutput.text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Summarize the content of https://www.wikipedia.org/",
    "tools": [{"type": "url_context"}]
}'
কম্পিউটার ব্যবহার

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-2.5-computer-use-preview-10-2025",
    input="Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.",
    tools=[{
        "type": "computer_use",
        "environment": "browser",
        "excludedPredefinedFunctions": ["drag_and_drop"]
    }]
)

# The response will contain tool calls (actions) for the computer interface
# or text explaining the action
for output in interaction.outputs:
    print(output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-2.5-computer-use-preview-10-2025',
    input: 'Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.',
    tools: [{
        type: 'computer_use',
        environment: 'browser',
        excludedPredefinedFunctions: ['drag_and_drop']
    }]
});

// The response will contain tool calls (actions) for the computer interface
// or text explaining the action
interaction.outputs.forEach(output => console.log(output));

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-computer-use-preview-10-2025",
    "input": "Search for highly rated smart fridges with touchscreen, 2 doors, around 25 cu ft, priced below 4000 dollars on Google Shopping. Create a bulleted list of the 3 cheapest options in the format of name, description, price in an easy-to-read layout.",
    "tools": [{
        "type": "computer_use",
        "environment": "browser",
        "excludedPredefinedFunctions": ["drag_and_drop"]
    }]
}'

রিমোট মডেল কনটেক্সট প্রোটোকল (MCP)

রিমোট এমসিপি ইন্টিগ্রেশন এজেন্ট ডেভেলপমেন্টকে সহজ করে তোলে, যার ফলে জেমিনি এপিআই রিমোট সার্ভারে হোস্ট করা বহিরাগত টুলগুলিকে সরাসরি কল করতে পারে।

পাইথন

import datetime
from google import genai

client = genai.Client()

mcp_server = {
    "type": "mcp_server",
    "name": "weather_service",
    "url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
}

today = datetime.date.today().strftime("%d %B %Y")

interaction = client.interactions.create(
    model="gemini-2.5-flash",
    input="What is the weather like in New York today?",
    tools=[mcp_server],
    system_instruction=f"Today is {today}."
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const mcpServer = {
    type: 'mcp_server',
    name: 'weather_service',
    url: 'https://gemini-api-demos.uc.r.appspot.com/mcp'
};

const today = new Date().toDateString();

const interaction = await client.interactions.create({
    model: 'gemini-2.5-flash',
    input: 'What is the weather like in New York today?',
    tools: [mcpServer],
    system_instruction: `Today is ${today}.`
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-2.5-flash",
    "input": "What is the weather like in New York today?",
    "tools": [{
        "type": "mcp_server",
        "name": "weather_service",
        "url": "https://gemini-api-demos.uc.r.appspot.com/mcp"
    }],
    "system_instruction": "Today is '"$(date +"%du%Bt%Y")"' YYYY-MM-DD>."
}'

গুরুত্বপূর্ণ নোট:

  • রিমোট এমসিপি শুধুমাত্র স্ট্রিমেবল HTTP সার্ভারের সাথে কাজ করে (এসএসই সার্ভার সমর্থিত নয়)
  • রিমোট এমসিপি জেমিনি ৩ মডেলের সাথে কাজ করে না (এটি শীঘ্রই আসছে)
  • MCP সার্ভারের নামগুলিতে "-" অক্ষর থাকা উচিত নয় (এর পরিবর্তে snake_case সার্ভারের নাম ব্যবহার করুন)

স্ট্রাকচার্ড আউটপুট (JSON স্কিমা)

response_format প্যারামিটারে একটি JSON স্কিমা প্রদান করে একটি নির্দিষ্ট JSON আউটপুট প্রয়োগ করুন। এটি মডারেশন, শ্রেণীবিভাগ, বা ডেটা নিষ্কাশনের মতো কাজের জন্য কার্যকর।

পাইথন

from google import genai
from pydantic import BaseModel, Field
from typing import Literal, Union
client = genai.Client()

class SpamDetails(BaseModel):
    reason: str = Field(description="The reason why the content is considered spam.")
    spam_type: Literal["phishing", "scam", "unsolicited promotion", "other"]

class NotSpamDetails(BaseModel):
    summary: str = Field(description="A brief summary of the content.")
    is_safe: bool = Field(description="Whether the content is safe for all audiences.")

class ModerationResult(BaseModel):
    decision: Union[SpamDetails, NotSpamDetails]

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format=ModerationResult.model_json_schema(),
)

parsed_output = ModerationResult.model_validate_json(interaction.outputs[-1].text)
print(parsed_output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import { z } from 'zod';
const client = new GoogleGenAI({});

const moderationSchema = z.object({
    decision: z.union([
        z.object({
            reason: z.string().describe('The reason why the content is considered spam.'),
            spam_type: z.enum(['phishing', 'scam', 'unsolicited promotion', 'other']).describe('The type of spam.'),
        }).describe('Details for content classified as spam.'),
        z.object({
            summary: z.string().describe('A brief summary of the content.'),
            is_safe: z.boolean().describe('Whether the content is safe for all audiences.'),
        }).describe('Details for content classified as not spam.'),
    ]),
});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: "Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format: z.toJSONSchema(moderationSchema),
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    "response_format": {
        "type": "object",
        "properties": {
            "decision": {
                "type": "object",
                "properties": {
                    "reason": {"type": "string", "description": "The reason why the content is considered spam."},
                    "spam_type": {"type": "string", "description": "The type of spam."}
                },
                "required": ["reason", "spam_type"]
            }
        },
        "required": ["decision"]
    }
}'

সরঞ্জাম এবং কাঠামোগত আউটপুট একত্রিত করা

একটি টুল দ্বারা প্রাপ্ত তথ্যের উপর ভিত্তি করে একটি নির্ভরযোগ্য JSON অবজেক্ট পেতে বিল্ট-ইন টুলগুলিকে স্ট্রাকচার্ড আউটপুটের সাথে একত্রিত করুন।

পাইথন

from google import genai
from pydantic import BaseModel, Field
from typing import Literal, Union

client = genai.Client()

class SpamDetails(BaseModel):
    reason: str = Field(description="The reason why the content is considered spam.")
    spam_type: Literal["phishing", "scam", "unsolicited promotion", "other"]

class NotSpamDetails(BaseModel):
    summary: str = Field(description="A brief summary of the content.")
    is_safe: bool = Field(description="Whether the content is safe for all audiences.")

class ModerationResult(BaseModel):
    decision: Union[SpamDetails, NotSpamDetails]

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Moderate the following content: 'Congratulations! You've won a free cruise. Click here to claim your prize: www.definitely-not-a-scam.com'",
    response_format=ModerationResult.model_json_schema(),
    tools=[{"type": "url_context"}]
)

parsed_output = ModerationResult.model_validate_json(interaction.outputs[-1].text)
print(parsed_output)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import { z } from 'zod'; // Assuming zod is used for schema generation, or define manually
const client = new GoogleGenAI({});

const obj = z.object({
    winning_team: z.string(),
    score: z.string(),
});
const schema = z.toJSONSchema(obj);

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Who won the last euro?',
    tools: [{ type: 'google_search' }],
    response_format: schema,
});
console.log(interaction.outputs[0].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Who won the last euro?",
    "tools": [{"type": "google_search"}],
    "response_format": {
        "type": "object",
        "properties": {
            "winning_team": {"type": "string"},
            "score": {"type": "string"}
        }
    }
}'

উন্নত বৈশিষ্ট্য

এছাড়াও অতিরিক্ত অগ্রিম বৈশিষ্ট্য রয়েছে যা আপনাকে ইন্টারঅ্যাকশন API এর সাথে কাজ করার ক্ষেত্রে আরও নমনীয়তা দেয়।

স্ট্রিমিং

উত্তরগুলি তৈরি হওয়ার সাথে সাথে ক্রমবর্ধমানভাবে গ্রহণ করুন।

পাইথন

from google import genai

client = genai.Client()

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)
        elif chunk.delta.type == "thought":
            print(chunk.delta.thought, end="", flush=True)
    elif chunk.event_type == "interaction.complete":
        print(f"\n\n--- Stream Finished ---")
        print(f"Total Tokens: {chunk.interaction.usage.total_tokens}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

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' && 'text' in chunk.delta) {
            process.stdout.write(chunk.delta.text);
        } else if (chunk.delta.type === 'thought' && 'thought' in chunk.delta) {
            process.stdout.write(chunk.delta.thought);
        }
    } else if (chunk.event_type === 'interaction.complete') {
        console.log('\n\n--- Stream Finished ---');
        console.log(`Total Tokens: ${chunk.interaction.usage.total_tokens}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions?alt=sse" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Explain quantum entanglement in simple terms.",
    "stream": true
}'

কনফিগারেশন

generation_config দিয়ে মডেলের আচরণ কাস্টমাইজ করুন।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Tell me a story about a brave knight.",
    generation_config={
        "temperature": 0.7,
        "max_output_tokens": 500,
        "thinking_level": "low",
    }
)

print(interaction.outputs[-1].text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Tell me a story about a brave knight.',
    generation_config: {
        temperature: 0.7,
        max_output_tokens: 500,
        thinking_level: 'low',
    }
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Tell me a story about a brave knight.",
    "generation_config": {
        "temperature": 0.7,
        "max_output_tokens": 500,
        "thinking_level": "low"
    }
}'

ভাবছি

জেমিনি ২.৫ এবং নতুন মডেলগুলি প্রতিক্রিয়া তৈরি করার আগে "চিন্তা" নামক একটি অভ্যন্তরীণ যুক্তি প্রক্রিয়া ব্যবহার করে। এটি মডেলটিকে গণিত, কোডিং এবং বহু-পদক্ষেপ যুক্তির মতো জটিল কাজের জন্য আরও ভাল উত্তর তৈরি করতে সহায়তা করে।

চিন্তাভাবনার স্তর

thinking_level প্যারামিটার আপনাকে মডেলের যুক্তির গভীরতা নিয়ন্ত্রণ করতে দেয়:

স্তর বিবরণ সমর্থিত মডেল
minimal বেশিরভাগ প্রশ্নের জন্য "কোনও চিন্তাভাবনা নেই" সেটিংটি মেলে। কিছু ক্ষেত্রে, মডেলগুলি খুব কম চিন্তা করতে পারে। বিলম্ব এবং খরচ কমিয়ে দেয়। শুধুমাত্র ফ্ল্যাশ মডেল
(যেমন জেমিনি ৩ ফ্ল্যাশ)
low সহজ নির্দেশনা অনুসরণ এবং চ্যাটের জন্য বিলম্ব এবং খরচ সাশ্রয়কে অগ্রাধিকার দেয় এমন হালকা যুক্তি। সকল চিন্তাভাবনার মডেল
medium বেশিরভাগ কাজের জন্য ভারসাম্যপূর্ণ চিন্তাভাবনা। শুধুমাত্র ফ্ল্যাশ মডেল
(যেমন জেমিনি ৩ ফ্ল্যাশ)
high (ডিফল্ট) যুক্তির গভীরতা সর্বাধিক করে। মডেলটি প্রথম টোকেনে পৌঁছাতে উল্লেখযোগ্যভাবে বেশি সময় নিতে পারে, তবে আউটপুট আরও সাবধানতার সাথে যুক্তিযুক্ত হবে। সকল চিন্তাভাবনার মডেল

চিন্তাভাবনার সারাংশ

মডেলের চিন্তাভাবনাকে প্রতিক্রিয়া আউটপুটগুলিতে চিন্তাভাবনা ব্লক ( type: "thought" ) হিসাবে উপস্থাপন করা হয়। thinking_summaries প্যারামিটার ব্যবহার করে চিন্তাভাবনা প্রক্রিয়ার মানুষের পাঠযোগ্য সারাংশ গ্রহণ করা হবে কিনা তা আপনি নিয়ন্ত্রণ করতে পারেন:

মূল্য বিবরণ
auto (ডিফল্ট) উপলব্ধ হলে চিন্তার সারাংশ প্রদান করে।
none চিন্তার সারাংশ অক্ষম করে।

পাইথন

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input="Solve this step by step: What is 15% of 240?",
    generation_config={
        "thinking_level": "high",
        "thinking_summaries": "auto"
    }
)

for output in interaction.outputs:
    if output.type == "thought":
        print(f"Thinking: {output.summary}")
    elif output.type == "text":
        print(f"Answer: {output.text}")

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: 'Solve this step by step: What is 15% of 240?',
    generation_config: {
        thinking_level: 'high',
        thinking_summaries: 'auto'
    }
});

for (const output of interaction.outputs) {
    if (output.type === 'thought') {
        console.log(`Thinking: ${output.summary}`);
    } else if (output.type === 'text') {
        console.log(`Answer: ${output.text}`);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": "Solve this step by step: What is 15% of 240?",
    "generation_config": {
        "thinking_level": "high",
        "thinking_summaries": "auto"
    }
}'

প্রতিটি চিন্তা ব্লকে একটি signature ক্ষেত্র (অভ্যন্তরীণ যুক্তির অবস্থার একটি ক্রিপ্টোগ্রাফিক হ্যাশ) এবং একটি ঐচ্ছিক summary ক্ষেত্র (মডেলের যুক্তির একটি মানব-পঠনযোগ্য সারাংশ) থাকে। signature সর্বদা উপস্থিত থাকে, তবে একটি চিন্তা ব্লকে এই ক্ষেত্রে কোনও সারাংশ ছাড়াই কেবল একটি স্বাক্ষর থাকতে পারে:

  • সহজ অনুরোধ : মডেলটি সারাংশ তৈরি করার জন্য যথেষ্ট যুক্তি দেয়নি
  • thinking_summaries: "none" : সারাংশ স্পষ্টভাবে অক্ষম করা হয়েছে

আপনার কোডে সর্বদা চিন্তার ব্লকগুলি পরিচালনা করা উচিত যেখানে summary খালি বা অনুপস্থিত। কথোপকথনের ইতিহাস ম্যানুয়ালি পরিচালনা করার সময় (স্টেটলেস মোড), সত্যতা যাচাই করার জন্য পরবর্তী অনুরোধগুলিতে আপনাকে অবশ্যই চিন্তার ব্লকগুলিকে তাদের স্বাক্ষর সহ অন্তর্ভুক্ত করতে হবে।

ফাইল নিয়ে কাজ করা

দূরবর্তী ফাইলগুলির সাথে কাজ করা

API কলে সরাসরি দূরবর্তী URL ব্যবহার করে ফাইল অ্যাক্সেস করুন।

পাইথন

from google import genai
client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {
            "type": "image",
            "uri": "https://github.com/<github-path>/cats-and-dogs.jpg",
        },
        {"type": "text", "text": "Describe what you see."}
    ],
)
for output in interaction.outputs:
    if output.type == "text":
        print(output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        {
            type: 'image',
            uri: 'https://github.com/<github-path>/cats-and-dogs.jpg',
        },
        { type: 'text', text: 'Describe what you see.' }
    ],
});
for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
    }
}

বিশ্রাম

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {
            "type": "image",
            "uri": "https://github.com/<github-path>/cats-and-dogs.jpg"
        },
        {"type": "text", "text": "Describe what you see."}
    ]
}'

জেমিনি ফাইলস এপিআই নিয়ে কাজ করা

ফাইলগুলি ব্যবহার করার আগে Gemini Files API- তে আপলোড করুন।

পাইথন

from google import genai
import time
import requests
client = genai.Client()

# 1. Download the file
url = "https://github.com/philschmid/gemini-samples/raw/refs/heads/main/assets/cats-and-dogs.jpg"
response = requests.get(url)
with open("cats-and-dogs.jpg", "wb") as f:
    f.write(response.content)

# 2. Upload to Gemini Files API
file = client.files.upload(file="cats-and-dogs.jpg")

# 3. Wait for processing
while client.files.get(name=file.name).state != "ACTIVE":
    time.sleep(2)

# 4. Use in Interaction
interaction = client.interactions.create(
    model="gemini-3-flash-preview",
    input=[
        {
            "type": "image",
            "uri": file.uri,
        },
        {"type": "text", "text": "Describe what you see."}
    ],
)
for output in interaction.outputs:
    if output.type == "text":
        print(output.text)

জাভাস্ক্রিপ্ট

import { GoogleGenAI } from '@google/genai';
import * as fs from 'fs';
import fetch from 'node-fetch';
const client = new GoogleGenAI({});

// 1. Download the file
const url = 'https://github.com/philschmid/gemini-samples/raw/refs/heads/main/assets/cats-and-dogs.jpg';
const filename = 'cats-and-dogs.jpg';
const response = await fetch(url);
const buffer = await response.buffer();
fs.writeFileSync(filename, buffer);

// 2. Upload to Gemini Files API
const myfile = await client.files.upload({ file: filename, config: { mimeType: 'image/jpeg' } });

// 3. Wait for processing
while ((await client.files.get({ name: myfile.name })).state !== 'ACTIVE') {
    await new Promise(resolve => setTimeout(resolve, 2000));
}

// 4. Use in Interaction
const interaction = await client.interactions.create({
    model: 'gemini-3-flash-preview',
    input: [
        { type: 'image', uri: myfile.uri, },
        { type: 'text', text: 'Describe what you see.' }
    ],
});
for (const output of interaction.outputs) {
    if (output.type === 'text') {
        console.log(output.text);
    }
}

বিশ্রাম

# 1. Upload the file (Requires File API setup)
# See https://ai.google.dev/gemini-api/docs/files for details.
# Assume FILE_URI is obtained from the upload step.

curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "Content-Type: application/json" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-d '{
    "model": "gemini-3-flash-preview",
    "input": [
        {"type": "image", "uri": "FILE_URI"},
        {"type": "text", "text": "Describe what you see."}
    ]
}'

ডেটা মডেল

আপনি API Reference থেকে ডেটা মডেল সম্পর্কে আরও জানতে পারবেন। নিচে প্রধান উপাদানগুলির একটি উচ্চ স্তরের ওভারভিউ দেওয়া হল।

মিথষ্ক্রিয়া

সম্পত্তি আদর্শ বিবরণ
id string মিথস্ক্রিয়ার জন্য অনন্য শনাক্তকারী।
model / agent string ব্যবহৃত মডেল বা এজেন্ট। শুধুমাত্র একটি প্রদান করা যেতে পারে।
input Content[] প্রদত্ত ইনপুট।
outputs Content[] মডেলের প্রতিক্রিয়া।
tools Tool[] ব্যবহৃত সরঞ্জাম।
previous_interaction_id string প্রসঙ্গের জন্য পূর্ববর্তী ইন্টারঅ্যাকশনের আইডি।
stream boolean মিথস্ক্রিয়াটি স্ট্রিমিং হচ্ছে কিনা।
status string স্থিতি: completed , in_progress , requires_action , failed , ইত্যাদি।
background boolean মিথস্ক্রিয়াটি ব্যাকগ্রাউন্ড মোডে আছে কিনা।
store boolean মিথস্ক্রিয়া সংরক্ষণ করা হবে কিনা। ডিফল্ট: true । অপ্ট আউট করতে false সেট করুন।
usage ব্যবহার ইন্টারঅ্যাকশন অনুরোধের টোকেন ব্যবহার।

সমর্থিত মডেল এবং এজেন্ট

মডেলের নাম আদর্শ মডেল আইডি
জেমিনি ২.৫ প্রো মডেল gemini-2.5-pro
জেমিনি 2.5 ফ্ল্যাশ মডেল gemini-2.5-flash
জেমিনি ২.৫ ফ্ল্যাশ-লাইট মডেল gemini-2.5-flash-lite
জেমিনি ৩ প্রো প্রিভিউ মডেল gemini-3-pro-preview
জেমিনি ৩ ফ্ল্যাশ প্রিভিউ মডেল gemini-3-flash-preview
গভীর গবেষণা প্রিভিউ এজেন্ট deep-research-pro-preview-12-2025

ইন্টারঅ্যাকশন API কীভাবে কাজ করে

ইন্টারঅ্যাকশন API একটি কেন্দ্রীয় রিসোর্সকে কেন্দ্র করে তৈরি করা হয়েছে: Interaction । একটি Interaction একটি কথোপকথন বা কাজের সম্পূর্ণ মোড়কে প্রতিনিধিত্ব করে। এটি একটি সেশন রেকর্ড হিসেবে কাজ করে, যাতে একটি ইন্টারঅ্যাকশনের সম্পূর্ণ ইতিহাস থাকে, যার মধ্যে সমস্ত ব্যবহারকারীর ইনপুট, মডেল চিন্তাভাবনা, টুল কল, টুল ফলাফল এবং চূড়ান্ত মডেল আউটপুট অন্তর্ভুক্ত থাকে।

যখন আপনি interactions.create এ কল করেন, তখন আপনি একটি নতুন Interaction রিসোর্স তৈরি করছেন।

সার্ভার-সাইড স্টেট ম্যানেজমেন্ট

কথোপকথন চালিয়ে যাওয়ার জন্য আপনি previous_interaction_id প্যারামিটার ব্যবহার করে পরবর্তী কলে একটি সম্পূর্ণ ইন্টারঅ্যাকশনের id ব্যবহার করতে পারেন। সার্ভার কথোপকথনের ইতিহাস পুনরুদ্ধার করতে এই আইডি ব্যবহার করে, আপনাকে সম্পূর্ণ চ্যাট ইতিহাস পুনরায় পাঠাতে হবে না।

শুধুমাত্র কথোপকথনের ইতিহাস (ইনপুট এবং আউটপুট) previous_interaction_id ব্যবহার করে সংরক্ষণ করা হয়। অন্যান্য প্যারামিটারগুলি ইন্টারঅ্যাকশন-স্কোপযুক্ত এবং শুধুমাত্র আপনি বর্তমানে যে নির্দিষ্ট ইন্টারঅ্যাকশন তৈরি করছেন তার ক্ষেত্রে প্রযোজ্য:

  • tools
  • system_instruction
  • ( generation_config , temperature , ইত্যাদি thinking_level )

এর অর্থ হল, যদি আপনি চান যে আপনি প্রতিটি নতুন ইন্টারঅ্যাকশনে এই প্যারামিটারগুলি পুনরায় নির্দিষ্ট করুন, তাহলে এই সার্ভার-সাইড স্টেট ম্যানেজমেন্ট ঐচ্ছিক; আপনি প্রতিটি অনুরোধে সম্পূর্ণ কথোপকথনের ইতিহাস পাঠিয়ে স্টেটলেস মোডেও কাজ করতে পারেন।

তথ্য সংরক্ষণ এবং ধারণ

ডিফল্টরূপে, সার্ভার-সাইড স্টেট ম্যানেজমেন্ট বৈশিষ্ট্যগুলি ( previous_interaction_id সহ), ব্যাকগ্রাউন্ড এক্সিকিউশন ( background=true ব্যবহার করে) এবং পর্যবেক্ষণযোগ্যতার উদ্দেশ্যে ব্যবহার সহজ করার জন্য সমস্ত ইন্টারঅ্যাকশন অবজেক্ট ( store=true ) সংরক্ষণ করা হয়।

  • পেইড টিয়ার : ইন্টারঅ্যাকশন ৫৫ দিনের জন্য সংরক্ষণ করা হয়।
  • বিনামূল্যে স্তর : মিথস্ক্রিয়া 1 দিনের জন্য রাখা হয়।

যদি আপনি এটি না চান, তাহলে আপনার অনুরোধে store=false সেট করতে পারেন। এই নিয়ন্ত্রণটি স্টেট ম্যানেজমেন্ট থেকে আলাদা; আপনি যেকোনো ইন্টারঅ্যাকশনের জন্য স্টোরেজ থেকে বেরিয়ে যেতে পারেন। তবে মনে রাখবেন যে store=false background=true এর সাথে সামঞ্জস্যপূর্ণ নয় এবং পরবর্তী টার্নের জন্য previous_interaction_id ব্যবহার করা থেকে বিরত রাখে।

API Reference এ পাওয়া delete পদ্ধতি ব্যবহার করে আপনি যেকোনো সময় সঞ্চিত ইন্টারঅ্যাকশন মুছে ফেলতে পারেন। আপনি যদি ইন্টারঅ্যাকশন আইডি জানেন তবেই কেবল ইন্টারঅ্যাকশন মুছে ফেলতে পারবেন।

ধরে রাখার সময়কাল শেষ হওয়ার পরে, আপনার ডেটা স্বয়ংক্রিয়ভাবে মুছে ফেলা হবে।

ইন্টারঅ্যাকশন বস্তুগুলি শর্তাবলী অনুসারে প্রক্রিয়া করা হয়।

সেরা অনুশীলন

  • ক্যাশে হিট রেট : কথোপকথন চালিয়ে যাওয়ার জন্য previous_interaction_id ব্যবহার করলে সিস্টেমটি কথোপকথনের ইতিহাসের জন্য আরও সহজে অন্তর্নিহিত ক্যাশিং ব্যবহার করতে পারে, যা কর্মক্ষমতা উন্নত করে এবং খরচ কমায়।
  • মিশ্র মিথস্ক্রিয়া : কথোপকথনের মধ্যে এজেন্ট এবং মডেল মিথস্ক্রিয়াগুলিকে মিশ্রিত করার এবং মেলানোর নমনীয়তা আপনার আছে। উদাহরণস্বরূপ, আপনি প্রাথমিক তথ্য সংগ্রহের জন্য ডিপ রিসার্চ এজেন্টের মতো একটি বিশেষায়িত এজেন্ট ব্যবহার করতে পারেন, এবং তারপরে সারসংক্ষেপ বা পুনরায় ফর্ম্যাট করার মতো ফলো-আপ কাজের জন্য একটি স্ট্যান্ডার্ড জেমিনি মডেল ব্যবহার করতে পারেন, এই পদক্ষেপগুলিকে previous_interaction_id এর সাথে সংযুক্ত করে।

SDK গুলি

ইন্টারেকশন API অ্যাক্সেস করার জন্য আপনি Google GenAI SDK-এর সর্বশেষ সংস্করণ ব্যবহার করতে পারেন।

  • পাইথনে, এটি 1.55.0 সংস্করণ থেকে শুরু করে google-genai প্যাকেজ।
  • জাভাস্ক্রিপ্টে, এটি @google/genai প্যাকেজ যা 1.33.0 সংস্করণ থেকে শুরু।

SDK গুলি কীভাবে ইনস্টল করবেন সে সম্পর্কে আপনি লাইব্রেরি পৃষ্ঠায় আরও জানতে পারবেন।

সীমাবদ্ধতা

  • বিটা স্ট্যাটাস : ইন্টারঅ্যাকশন API বিটা/প্রিভিউতে রয়েছে। বৈশিষ্ট্য এবং স্কিমা পরিবর্তন হতে পারে।
  • অসমর্থিত বৈশিষ্ট্য : নিম্নলিখিত বৈশিষ্ট্যগুলি এখনও সমর্থিত নয় তবে শীঘ্রই আসছে:

  • আউটপুট অর্ডারিং : বিল্ট-ইন টুলগুলির ( google_search এবং url_context ) জন্য কন্টেন্ট অর্ডারিং কখনও কখনও ভুল হতে পারে, টুল এক্সিকিউশন এবং ফলাফলের আগে টেক্সট প্রদর্শিত হতে পারে। এটি একটি পরিচিত সমস্যা এবং এটি সমাধানের প্রক্রিয়া চলছে।

  • টুলের সমন্বয় : MCP, ফাংশন কল এবং বিল্ট-ইন টুলের সমন্বয় এখনও সমর্থিত নয় তবে শীঘ্রই আসছে।

  • রিমোট এমসিপি : জেমিনি ৩ রিমোট এমসিপি সমর্থন করে না, এটি শীঘ্রই আসছে।

ব্রেকিং পরিবর্তনগুলি

ইন্টারঅ্যাকশন API বর্তমানে প্রাথমিক বিটা পর্যায়ে রয়েছে। আমরা বাস্তব-বিশ্বের ব্যবহার এবং ডেভেলপারদের প্রতিক্রিয়ার উপর ভিত্তি করে API ক্ষমতা, রিসোর্স স্কিমা এবং SDK ইন্টারফেসগুলি সক্রিয়ভাবে বিকাশ এবং পরিমার্জন করছি।

ফলস্বরূপ, ব্রেকিং পরিবর্তনগুলি ঘটতে পারে । আপডেটগুলিতে নিম্নলিখিত পরিবর্তনগুলি অন্তর্ভুক্ত থাকতে পারে:

  • ইনপুট এবং আউটপুটের জন্য স্কিম।
  • SDK পদ্ধতির স্বাক্ষর এবং বস্তুর কাঠামো।
  • নির্দিষ্ট বৈশিষ্ট্য আচরণ।

উৎপাদন কাজের চাপের জন্য, আপনার স্ট্যান্ডার্ড generateContent API ব্যবহার করা চালিয়ে যাওয়া উচিত। এটি স্থিতিশীল স্থাপনার জন্য প্রস্তাবিত পথ হিসাবে রয়ে গেছে এবং সক্রিয়ভাবে বিকাশ এবং রক্ষণাবেক্ষণ অব্যাহত থাকবে।

প্রতিক্রিয়া

ইন্টারঅ্যাকশন API তৈরির জন্য আপনার মতামত অত্যন্ত গুরুত্বপূর্ণ। অনুগ্রহ করে আমাদের Google AI ডেভেলপার কমিউনিটি ফোরামে আপনার মতামত শেয়ার করুন, বাগ রিপোর্ট করুন, অথবা বৈশিষ্ট্যগুলির জন্য অনুরোধ করুন।

এরপর কি?