Live API - WebSockets API reference

লাইভ এপিআই হলো একটি স্টেটফুল এপিআই যা ওয়েবসকেটস ব্যবহার করে। এই অংশে আপনি ওয়েবসকেটস এপিআই সম্পর্কে আরও বিস্তারিত তথ্য পাবেন।

অধিবেশন

একটি ওয়েবসকেট সংযোগ ক্লায়েন্ট এবং জেমিনি সার্ভারের মধ্যে একটি সেশন স্থাপন করে। ক্লায়েন্ট একটি নতুন সংযোগ শুরু করার পর, সেশনটি সার্ভারের সাথে নিম্নলিখিত উদ্দেশ্যে বার্তা আদান-প্রদান করতে পারে:

  • জেমিনি সার্ভারে টেক্সট, অডিও বা ভিডিও পাঠান।
  • জেমিনি সার্ভার থেকে অডিও, টেক্সট বা ফাংশন কল অনুরোধ গ্রহণ করুন।

ওয়েবসকেট সংযোগ

একটি সেশন শুরু করতে, এই ওয়েবসকেট এন্ডপয়েন্টে সংযোগ করুন:

wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent

সেশন কনফিগারেশন

WebSocket সংযোগ স্থাপনের পর পাঠানো প্রাথমিক বার্তাটি সেশন কনফিগারেশন নির্ধারণ করে, যার মধ্যে মডেল, জেনারেশন প্যারামিটার, সিস্টেম নির্দেশাবলী এবং টুলস অন্তর্ভুক্ত থাকে।

সংযোগ খোলা থাকা অবস্থায় আপনি কনফিগারেশন আপডেট করতে পারবেন না। তবে, সেশন রিজাম্পশন মেকানিজমের মাধ্যমে সেশন পজ ও রিজুম করার সময় আপনি মডেল ছাড়া অন্যান্য কনফিগারেশন প্যারামিটারগুলো পরিবর্তন করতে পারবেন।

নিম্নলিখিত উদাহরণ কনফিগারেশনটি দেখুন। মনে রাখবেন যে SDK-গুলিতে নামের কেসিং ভিন্ন হতে পারে। আপনি এখানে পাইথন SDK কনফিগারেশন অপশনগুলো দেখে নিতে পারেন।


{
  "model": string,
  "generationConfig": {
    "candidateCount": integer,
    "maxOutputTokens": integer,
    "temperature": number,
    "topP": number,
    "topK": integer,
    "presencePenalty": number,
    "frequencyPenalty": number,
    "responseModalities": [string],
    "speechConfig": object,
    "mediaResolution": object,
    "translationConfig": object
  },
  "systemInstruction": string,
  "tools": [object]
}

API ফিল্ড সম্পর্কে আরও তথ্যের জন্য, generationConfig দেখুন।

বার্তা পাঠান

WebSocket সংযোগের মাধ্যমে বার্তা আদান-প্রদান করতে, ক্লায়েন্টকে একটি খোলা WebSocket সংযোগের মাধ্যমে একটি JSON অবজেক্ট পাঠাতে হবে। JSON অবজেক্টটিতে নিম্নলিখিত অবজেক্ট সেট থেকে ঠিক একটি ফিল্ড থাকতে হবে:


{
  "setup": BidiGenerateContentSetup,
  "clientContent": BidiGenerateContentClientContent,
  "realtimeInput": BidiGenerateContentRealtimeInput,
  "toolResponse": BidiGenerateContentToolResponse
}

সমর্থিত ক্লায়েন্ট বার্তা

নিম্নলিখিত সারণীতে সমর্থিত ক্লায়েন্ট বার্তাগুলি দেখুন:

বার্তা বর্ণনা
BidiGenerateContentSetup প্রথম মেসেজে সেশন কনফিগারেশন পাঠানো হবে।
BidiGenerateContentClientContent ক্লায়েন্টের কাছ থেকে প্রাপ্ত বর্তমান কথোপকথনের ক্রমবর্ধমান বিষয়বস্তু হালনাগাদ।
BidiGenerateContentRealtimeInput রিয়েল টাইম অডিও, ভিডিও, বা টেক্সট ইনপুট
BidiGenerateContentToolResponse সার্ভার থেকে প্রাপ্ত ToolCallMessage এর প্রতিক্রিয়া

বার্তা গ্রহণ করুন

জেমিনি থেকে বার্তা গ্রহণ করতে, ওয়েবসকেট 'message' ইভেন্টের জন্য লিসেন করুন এবং তারপরে সমর্থিত সার্ভার বার্তাগুলির সংজ্ঞা অনুযায়ী ফলাফলটি পার্স করুন।

নিম্নলিখিতগুলি দেখুন:

async with client.aio.live.connect(model='...', config=config) as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
        print(message)

সার্ভার মেসেজে একটি usageMetadata ফিল্ড থাকতে পারে, কিন্তু এছাড়া এটি BidiGenerateContentServerMessage মেসেজের অন্য ফিল্ডগুলোর মধ্যে ঠিক একটি অন্তর্ভুক্ত করবে। ( messageType ইউনিয়নটি JSON-এ প্রকাশ করা হয় না, তাই ফিল্ডটি মেসেজের শীর্ষ-স্তরে প্রদর্শিত হবে।)

বার্তা এবং ঘটনা

কার্যকলাপ শেষ

এই প্রকারে কোনো ক্ষেত্র নেই।

ব্যবহারকারীর কার্যকলাপের সমাপ্তি নির্দেশ করে।

কার্যকলাপ পরিচালনা

ব্যবহারকারীর কার্যকলাপ পরিচালনার বিভিন্ন উপায়।

এনাম
ACTIVITY_HANDLING_UNSPECIFIED অনির্দিষ্ট থাকলে, ডিফল্ট আচরণ হলো START_OF_ACTIVITY_INTERRUPTS
START_OF_ACTIVITY_INTERRUPTS যদি সত্য হয়, তাহলে কার্যকলাপ শুরু হলে মডেলের প্রতিক্রিয়া বাধাগ্রস্ত হবে (একে "বার্জ ইন"ও বলা হয়)। বাধাগ্রস্ত হওয়ার মুহূর্তে মডেলের বর্তমান প্রতিক্রিয়াটি বন্ধ হয়ে যাবে। এটিই ডিফল্ট আচরণ।
NO_INTERRUPTION মডেলের প্রতিক্রিয়া ব্যাহত হবে না।

কার্যকলাপ শুরু

এই প্রকারে কোনো ক্ষেত্র নেই।

ব্যবহারকারীর কার্যকলাপের সূচনা নির্দেশ করে।

অডিও ট্রান্সক্রিপশন কনফিগারেশন

অডিও ট্রান্সক্রিপশন কনফিগারেশন।

ক্ষেত্র
languageCodes[]

string

ঐচ্ছিক। BCP-47 ভাষা কোড যা অডিওতে উপস্থিত ভাষাগুলো সম্পর্কে ইঙ্গিত দেয়। এটি বাদ দিলে বা খালি রাখলে, ডিফল্টরূপে স্বয়ংক্রিয় ভাষা শনাক্তকরণ ব্যবহৃত হবে।

customVocabulary[]

string

ঐচ্ছিক। স্পিচ রিকগনিশন মডেলকে নির্দিষ্ট পদ (পণ্যের নাম, বিশেষ্য পদ, পারিভাষিক শব্দ) শনাক্ত করার দিকে প্রভাবিত করার জন্য নিজস্ব শব্দভাণ্ডারের একটি তালিকা।

wordTimestamp

bool

ঐচ্ছিক। এটি ওয়ার্ড-স্তরের টাইমস্ট্যাম্প তৈরি কনফিগার করে।

diarization

bool

ঐচ্ছিক। স্পিকার ডায়ারাইজেশন কনফিগার করে।

mode

Mode

ঐচ্ছিক। ট্রান্সক্রিপশন মোড কনফিগার করে। সমর্থিত মান: VERBATIM , SMART । নির্দিষ্ট না করা হলে, ডিফল্ট হিসেবে VERBATIM ট্রান্সক্রিপশন ব্যবহৃত হয়। SMART মোডে, মডেলটি সাবলীলতার অভাব দূর করে (অপ্রয়োজনীয় শব্দ, পুনরাবৃত্তি এবং ভুল শুরু বাদ দিয়ে), হালকা ব্যাকরণগত পরিমার্জন করে, স্বয়ংক্রিয়ভাবে ফরম্যাটিং করে (প্যারাগ্রাফ, বুলেট পয়েন্ট, সংখ্যাযুক্ত তালিকা) এবং ব্যবহারকারীর ছোটখাটো সম্পাদনা (ইনলাইন স্ব-সংশোধন) করে। টাইমস্ট্যাম্প এবং ডায়ারাইজেশন SMART মোডের সাথে সামঞ্জস্যপূর্ণ নয়।

মোড

ট্রান্সক্রিপশন মোড।

এনাম
MODE_UNSPECIFIED অনির্দিষ্ট ট্রান্সক্রিপশন মোড।
VERBATIM হুবহু প্রতিলিপি মোড।
SMART স্মার্ট ট্রান্সক্রিপশন মোড।

স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণ

কার্যকলাপের স্বয়ংক্রিয় সনাক্তকরণ কনফিগার করে।

ক্ষেত্র
disabled

bool

ঐচ্ছিক। যদি এটি সক্রিয় থাকে (যা ডিফল্টরূপে চালু থাকে), তাহলে শনাক্তকৃত ভয়েস এবং টেক্সট ইনপুট কার্যকলাপ হিসেবে গণ্য হবে। যদি এটি নিষ্ক্রিয় থাকে, তাহলে ক্লায়েন্টকে অবশ্যই কার্যকলাপ সংকেত পাঠাতে হবে।

startOfSpeechSensitivity

StartSensitivity

ঐচ্ছিক। এটি নির্ধারণ করে যে কথা শনাক্ত হওয়ার সম্ভাবনা কতটা।

prefixPaddingMs

int32

ঐচ্ছিক। বক্তব্য শুরু হওয়ার আগে শনাক্তকৃত বক্তব্যের প্রয়োজনীয় সময়কাল। এই মান যত কম হবে, বক্তব্য শুরু শনাক্তকরণ তত বেশি সংবেদনশীল হবে এবং ছোট বক্তব্যও শনাক্ত করা যাবে। তবে, এতে ভুল শনাক্তকরণের সম্ভাবনাও বেড়ে যায়।

endOfSpeechSensitivity

EndSensitivity

ঐচ্ছিক। শনাক্তকৃত বক্তব্য শেষ হওয়ার সম্ভাবনা কতটুকু, তা নির্ধারণ করে।

silenceDurationMs

int32

ঐচ্ছিক। কথা শেষ হওয়ার আগে শনাক্তকৃত কথাবিহীন অংশের (যেমন নীরবতা) প্রয়োজনীয় সময়কাল। এই মান যত বেশি হবে, ব্যবহারকারীর কাজে বাধা না দিয়ে কথার বিরতি তত দীর্ঘ হতে পারবে, কিন্তু এতে মডেলের ল্যাটেন্সি বেড়ে যাবে।

বিডিজেনারেট কনটেন্ট ক্লায়েন্ট কনটেন্ট

ক্লায়েন্টের কাছ থেকে পাঠানো বর্তমান কথোপকথনের ক্রমবর্ধমান হালনাগাদ। এখানকার সমস্ত বিষয়বস্তু নিঃশর্তভাবে কথোপকথনের ইতিহাসে যুক্ত করা হয় এবং মডেলকে বিষয়বস্তু তৈরি করার জন্য নির্দেশনার অংশ হিসেবে ব্যবহৃত হয়।

এখানে একটি বার্তা দিলে চলমান মডেল তৈরির প্রক্রিয়াটি বাধাগ্রস্ত হবে।

ক্ষেত্র
turns[]

Content

ঐচ্ছিক। মডেলের সাথে চলমান কথোপকথনের সাথে যুক্ত বিষয়বস্তু।

একক-টার্ন কোয়েরির ক্ষেত্রে, এটি একটি একক ইনস্ট্যান্স। একাধিক-টার্ন কোয়েরির ক্ষেত্রে, এটি একটি পুনরাবৃত্ত ক্ষেত্র যা কথোপকথনের ইতিহাস এবং সর্বশেষ অনুরোধ ধারণ করে।

turnComplete

bool

ঐচ্ছিক। যদি 'true' হয়, তবে এটি নির্দেশ করে যে সার্ভারে কন্টেন্ট তৈরি বর্তমানে জমা হওয়া প্রম্পট থেকে শুরু হবে। অন্যথায়, সার্ভার তৈরি শুরু করার আগে অতিরিক্ত বার্তার জন্য অপেক্ষা করবে।

বিডিজেনারেট কনটেন্ট রিয়েলটাইম ইনপুট

ব্যবহারকারীর ইনপুট যা রিয়েল টাইমে পাঠানো হয়।

বিভিন্ন মাধ্যম (অডিও, ভিডিও এবং টেক্সট) যুগপৎ প্রবাহ হিসেবে পরিচালিত হয়। এই প্রবাহগুলোর মধ্যে ক্রমবিন্যাস নিশ্চিত করা হয় না।

এটি BidiGenerateContentClientContent থেকে কয়েকটি দিক দিয়ে আলাদা:

  • মডেল তৈরির জন্য নিরবচ্ছিন্নভাবে পাঠানো যেতে পারে।
  • যদি BidiGenerateContentClientContent এবং BidiGenerateContentRealtimeInput এর মধ্যে ডেটা এলোমেলোভাবে মেশানোর প্রয়োজন হয়, তবে সার্ভার সর্বোত্তম প্রতিক্রিয়ার জন্য অপ্টিমাইজ করার চেষ্টা করে, কিন্তু এর কোনো নিশ্চয়তা নেই।
  • পালা শেষ হওয়ার সময় স্পষ্টভাবে নির্দিষ্ট করা থাকে না, বরং তা ব্যবহারকারীর কার্যকলাপ থেকে নির্ধারিত হয় (যেমন, বক্তৃতা শেষ হওয়া)।
  • পালা শেষ হওয়ার আগেও, মডেল থেকে দ্রুত প্রতিক্রিয়া শুরু করার জন্য ডেটা পর্যায়ক্রমে প্রক্রিয়াজাত করা হয়।
ক্ষেত্র
mediaChunks[]

Blob

ঐচ্ছিক। মিডিয়া ইনপুটের জন্য ইনলাইন করা বাইট ডেটা। একাধিক mediaChunks সমর্থিত নয়, প্রথমটি ছাড়া বাকি সব উপেক্ষা করা হবে।

অপ্রচলিত: এর পরিবর্তে audio , video বা text ব্যবহার করুন।

audio

Blob

ঐচ্ছিক। এগুলো রিয়েলটাইম অডিও ইনপুট স্ট্রিম গঠন করে।

video

Blob

ঐচ্ছিক। এগুলো রিয়েলটাইম ভিডিও ইনপুট স্ট্রিম গঠন করে।

activityStart

ActivityStart

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

activityEnd

ActivityEnd

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

mediaResolution

MediaResolution

ঐচ্ছিক। যে মিডিয়া রেজোলিউশনটি ব্যবহার করা হবে। যদি নির্দিষ্ট করে না দেওয়া হয়, তাহলে setup.generationConfig.mediaResolution ব্যবহৃত হবে অথবা সেটআপ প্রদান করা না হলে একটি ডিফল্ট ব্যবহৃত হবে।

audioStreamEnd

bool

ঐচ্ছিক। এটি নির্দেশ করে যে অডিও প্রবাহ শেষ হয়ে গেছে, যেমন মাইক্রোফোন বন্ধ করার কারণে।

এটি শুধুমাত্র তখনই পাঠানো উচিত যখন স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণ সক্রিয় থাকে (যা ডিফল্টরূপে চালু থাকে)।

ক্লায়েন্ট একটি অডিও বার্তা পাঠিয়ে স্ট্রিমটি পুনরায় চালু করতে পারেন।

text

string

ঐচ্ছিক। এগুলো রিয়েলটাইম টেক্সট ইনপুট স্ট্রিম গঠন করে।

বিডিজেনারেট কনটেন্ট সার্ভার কন্টেন্ট

ক্লায়েন্টের বার্তার প্রতিক্রিয়ায় মডেল দ্বারা তৈরি ক্রমবর্ধমান সার্ভার আপডেট।

কন্টেন্ট যত দ্রুত সম্ভব তৈরি করা হয়, রিয়েল টাইমে নয়। ক্লায়েন্টরা চাইলে তা বাফার করে রিয়েল টাইমে প্লে করতে পারেন।

ক্ষেত্র
generationComplete

bool

শুধুমাত্র আউটপুট। যদি 'true' হয়, তবে এটি নির্দেশ করে যে মডেলটি তৈরি করা শেষ হয়েছে।

মডেল তৈরির সময় বাধাগ্রস্ত হলে, বাধাগ্রস্ত টার্নে 'generation_complete' বার্তাটি আসবে না, বরং এটি 'interrupted > turn_complete' ধাপে ধাপে সম্পন্ন হবে।

যখন মডেল রিয়েলটাইম প্লেব্যাক চালু করে, তখন generation_complete এবং turn_complete-এর মধ্যে একটি বিলম্ব ঘটে, যা প্লেব্যাক শেষ হওয়ার জন্য মডেলের অপেক্ষার কারণে হয়ে থাকে।

turnComplete

bool

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

interrupted

bool

শুধুমাত্র আউটপুট। যদি সত্য হয়, তবে এটি নির্দেশ করে যে একটি ক্লায়েন্ট বার্তা বর্তমান মডেল তৈরি প্রক্রিয়াকে বাধাগ্রস্ত করেছে। যদি ক্লায়েন্ট রিয়েল টাইমে কন্টেন্টটি প্লে করে, তবে এটি থামার এবং বর্তমান প্লেব্যাক কিউ খালি করার একটি ভালো সংকেত।

groundingMetadata

GroundingMetadata

শুধুমাত্র আউটপুট। তৈরি করা কন্টেন্টের জন্য মেটাডেটা গ্রাউন্ডিং করা হচ্ছে।

inputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। অডিও ট্রান্সক্রিপশন ইনপুট করুন। ট্রান্সক্রিপশনটি সার্ভারের অন্যান্য বার্তা থেকে স্বাধীনভাবে পাঠানো হয় এবং এর কোনো নিশ্চিত ক্রম নেই।

interimInputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। ব্যবহারকারী কথা বলার সময়েই স্বল্প বিলম্বের ট্রান্সক্রিপশন আপডেট হয়। এই ফিল্ডটি ঘন ঘন আপডেট করা হতে পারে।

outputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। অডিও ট্রান্সক্রিপশন আউটপুট করুন। এই ট্রান্সক্রিপশনগুলো সার্ভারের জেনারেশন আউটপুটের অংশ। এই টার্নের সর্বশেষ আউটপুট ট্রান্সক্রিপশনটি generationComplete বা interrupted আগে পাঠানো হয়, যার পরে turnComplete পাঠানো হয়। ট্রান্সক্রিপশন এবং অন্যান্য modelTurn আউটপুটের মধ্যে কোনো নির্দিষ্ট ক্রমের নিশ্চয়তা নেই, তবে সার্ভার সংশ্লিষ্ট অডিও আউটপুটের কাছাকাছি সময়ে ট্রান্সক্রিপশনগুলো পাঠানোর চেষ্টা করে।

urlContextMetadata

UrlContextMetadata

waitingForInput

bool

শুধুমাত্র আউটপুট। যদি এটি সত্য হয়, তবে এটি নির্দেশ করে যে মডেলটি কোনো কন্টেন্ট তৈরি করছে না কারণ এটি ব্যবহারকারীর কাছ থেকে আরও ইনপুটের জন্য অপেক্ষা করছে, যেমন—এটি আশা করছে যে ব্যবহারকারী কথা বলতে থাকবে।

speechState
(deprecated)

SpeechState

শুধুমাত্র আউটপুট। অপ্রচলিত: এর পরিবর্তে VoiceActivity ব্যবহার করুন।

realtimeInput.audio তে স্পিচ ডিটেকশনের বর্তমান অবস্থা নির্দেশ করে। অবস্থা অপরিবর্তিত থাকলে এটি সেট করা নেই বা শূন্য।

interactionStatus

InteractionStatus

শুধুমাত্র আউটপুট। লাইভ সেশনের বর্তমান কার্যকলাপের অবস্থা। এটি সর্বদা turnComplete সাথে পাঠানো হয়।

modelTurn

Content

শুধুমাত্র আউটপুট। ব্যবহারকারীর সাথে বর্তমান কথোপকথনের অংশ হিসেবে মডেলটি যে বিষয়বস্তু তৈরি করেছে।

বিডিজেনারেট কনটেন্ট সার্ভার মেসেজ

BidiGenerateContent কলটির প্রতিক্রিয়া বার্তা।

ক্ষেত্র
usageMetadata

UsageMetadata

শুধুমাত্র আউটপুট। প্রতিক্রিয়া(গুলো) সম্পর্কিত ব্যবহারের মেটাডেটা।

ইউনিয়ন ফিল্ড messageType বার্তার ধরণ। messageType নিম্নলিখিতগুলির মধ্যে কেবল একটি হতে পারে:
setupComplete

BidiGenerateContentSetupComplete

শুধুমাত্র আউটপুট। সেটআপ সম্পন্ন হলে ক্লায়েন্টের পাঠানো BidiGenerateContentSetup মেসেজের জবাবে এটি পাঠানো হয়।

serverContent

BidiGenerateContentServerContent

শুধুমাত্র আউটপুট। ক্লায়েন্টের বার্তার জবাবে মডেল দ্বারা তৈরি বিষয়বস্তু।

toolCall

BidiGenerateContentToolCall

শুধুমাত্র আউটপুট। ক্লায়েন্টকে functionCalls সম্পাদন করতে এবং মিলে যাওয়া id সহ প্রতিক্রিয়াগুলো ফেরত দিতে অনুরোধ করা হচ্ছে।

toolCallCancellation

BidiGenerateContentToolCallCancellation

শুধুমাত্র আউটপুট। ক্লায়েন্টের জন্য বিজ্ঞপ্তি যে, নির্দিষ্ট id s সহ পূর্বে জারি করা একটি ToolCallMessage বাতিল করা উচিত।

goAway

GoAway

শুধুমাত্র আউটপুট। একটি বিজ্ঞপ্তি যে সার্ভারটি শীঘ্রই সংযোগ বিচ্ছিন্ন করবে।

sessionResumptionUpdate

SessionResumptionUpdate

শুধুমাত্র আউটপুট। সেশন পুনরায় চালুর অবস্থার হালনাগাদ।

BidiGenerateContentSetup

এই বার্তাটি প্রথম (এবং শুধুমাত্র প্রথম) BidiGenerateContentClientMessage এ পাঠানো হবে। এতে এমন কনফিগারেশন রয়েছে যা স্ট্রিমিং RPC চলাকালীন প্রযোজ্য থাকবে।

অতিরিক্ত কোনো বার্তা পাঠানোর আগে ক্লায়েন্টদের BidiGenerateContentSetupComplete বার্তাটির জন্য অপেক্ষা করা উচিত।

ক্ষেত্র
model

string

আবশ্যক। মডেলের রিসোর্স নাম। এটি মডেলের ব্যবহারের জন্য একটি আইডি হিসেবে কাজ করে।

ফরম্যাট: models/{model}

generationConfig

GenerationConfig

ঐচ্ছিক। জেনারেশন কনফিগারেশন।

নিম্নলিখিত ক্ষেত্রগুলি সমর্থিত নয়:

  • responseLogprobs
  • responseMimeType
  • logprobs
  • responseSchema
  • responseJsonSchema
  • stopSequence
  • skipResponseCache
  • routingConfig
  • audioTimestamp
systemInstruction

Content

ঐচ্ছিক। ব্যবহারকারী মডেলটির জন্য সিস্টেম নির্দেশাবলী প্রদান করেছেন।

দ্রষ্টব্য: শুধুমাত্র লেখা খণ্ড খণ্ড করে ব্যবহার করা হবে এবং প্রতিটি খণ্ডের বিষয়বস্তু একটি পৃথক অনুচ্ছেদে থাকবে।

tools[]

Tool

ঐচ্ছিক। পরবর্তী প্রতিক্রিয়া তৈরি করতে মডেলটি Tools ব্যবহার করতে পারে তার একটি তালিকা।

Tool হলো এক খণ্ড কোড যা সিস্টেমকে বাহ্যিক সিস্টেমের সাথে যোগাযোগ করে এমন কোনো কাজ বা একাধিক কাজ সম্পাদন করতে সক্ষম করে, যা মডেলের জ্ঞান ও পরিধির বাইরে থাকে।

realtimeInputConfig

RealtimeInputConfig

ঐচ্ছিক। রিয়েলটাইম ইনপুট পরিচালনার পদ্ধতি নির্ধারণ করে।

sessionResumption

SessionResumptionConfig

ঐচ্ছিক। সেশন পুনরায় চালু করার পদ্ধতি নির্ধারণ করে।

অন্তর্ভুক্ত করা হলে, সার্ভার SessionResumptionUpdate বার্তা পাঠাবে।

contextWindowCompression

ContextWindowCompressionConfig

ঐচ্ছিক। একটি কনটেক্সট উইন্ডো কম্প্রেশন মেকানিজম কনফিগার করে।

অন্তর্ভুক্ত করা হলে, কনটেক্সটের আকার কনফিগার করা দৈর্ঘ্য অতিক্রম করলে সার্ভার স্বয়ংক্রিয়ভাবে তা কমিয়ে দেবে।

inputAudioTranscription

AudioTranscriptionConfig

ঐচ্ছিক। সেট করা থাকলে, ভয়েস ইনপুটের ট্রান্সক্রিপশন চালু হয়। কনফিগার করা থাকলে, ট্রান্সক্রিপশনটি ইনপুট অডিও ভাষার সাথে সামঞ্জস্যপূর্ণ হয়।

outputAudioTranscription

AudioTranscriptionConfig

ঐচ্ছিক। সেট করা থাকলে, মডেলের অডিও আউটপুটের ট্রান্সক্রিপশন চালু হয়। কনফিগার করা থাকলে, ট্রান্সক্রিপশনটি আউটপুট অডিওর জন্য নির্দিষ্ট করা ভাষা কোডের সাথে সামঞ্জস্যপূর্ণ হয়।

proactivity

ProactivityConfig

ঐচ্ছিক। মডেলটির সক্রিয়তা নির্ধারণ করে।

এর ফলে মডেলটি ইনপুটের প্রতি সক্রিয়ভাবে সাড়া দিতে এবং অপ্রাসঙ্গিক ইনপুট উপেক্ষা করতে পারে।

historyConfig

HistoryConfig

ঐচ্ছিক। ক্লায়েন্ট এবং সার্ভারের মধ্যে হিস্ট্রি আদান-প্রদান কনফিগার করে।

বিডি জেনারেট কনটেন্ট সেটআপ সম্পূর্ণ

এই প্রকারে কোনো ক্ষেত্র নেই।

ক্লায়েন্টের কাছ থেকে আসা একটি BidiGenerateContentSetup বার্তার জবাবে পাঠানো হয়েছে।

BidiGenerateContentToolCall

ক্লায়েন্টকে functionCalls সম্পাদন করতে এবং মিলে যাওয়া id সহ প্রতিক্রিয়াগুলো ফেরত দিতে অনুরোধ করা হচ্ছে।

ক্ষেত্র
functionCalls[]

FunctionCall

শুধুমাত্র আউটপুট। যে ফাংশন কলটি কার্যকর করা হবে।

BidiGenerateContentToolCallCancellation

ক্লায়েন্টের জন্য বিজ্ঞপ্তি যে, নির্দিষ্ট id s সহ পূর্বে জারি করা একটি ToolCallMessage কার্যকর করা উচিত হয়নি এবং তা বাতিল করা উচিত। যদি সেই টুল কলগুলির কোনো পার্শ্ব-প্রতিক্রিয়া থাকে, তবে ক্লায়েন্টরা টুল কলগুলি পূর্বাবস্থায় ফিরিয়ে আনার চেষ্টা করতে পারে। এই বার্তাটি শুধুমাত্র তখনই প্রদর্শিত হয় যখন ক্লায়েন্টরা সার্ভারের পালাবদলে বাধা দেয়।

ক্ষেত্র
ids[]

string

শুধুমাত্র আউটপুট। বাতিল করার জন্য টুল কলগুলোর আইডি।

বিডিজেনারেট কনটেন্ট টুল রেসপন্স

সার্ভার থেকে প্রাপ্ত একটি ToolCall -এর জবাবে ক্লায়েন্ট কর্তৃক উৎপন্ন প্রতিক্রিয়া। প্রতিটি FunctionResponse অবজেক্টকে তার id ফিল্ডের মাধ্যমে সংশ্লিষ্ট FunctionCall অবজেক্টের সাথে মেলানো হয়।

উল্লেখ্য যে, ইউনারি এবং সার্ভার-স্ট্রিমিং GenerateContent API-গুলিতে ফাংশন কলিং ঘটে Content অংশগুলি বিনিময়ের মাধ্যমে, অন্যদিকে বাইডি GenerateContent API-গুলিতে ফাংশন কলিং এই বিশেষ মেসেজ সেটের মাধ্যমে সম্পন্ন হয়।

ক্ষেত্র
functionResponses[]

FunctionResponse

ঐচ্ছিক। ফাংশন কলগুলোর প্রতিক্রিয়া।

বিডিজেনারেট কনটেন্ট ট্রান্সক্রিপশন

অডিওর (ইনপুট বা আউটপুট) ট্রান্সক্রিপশন।

ক্ষেত্র
text

string

প্রতিলিপি পাঠ্য।

languageCode

string

প্রতিলিপির বিসিপি-৪৭ ভাষা কোড।

ContextWindowCompressionConfig

কনটেক্সট উইন্ডো কম্প্রেশন সক্ষম করে — এটি মডেলের কনটেক্সট উইন্ডোকে এমনভাবে পরিচালনা করার একটি পদ্ধতি, যাতে এটি একটি নির্দিষ্ট দৈর্ঘ্য অতিক্রম না করে।

ক্ষেত্র
ইউনিয়ন ফিল্ড compressionMechanism । ব্যবহৃত কনটেক্সট উইন্ডো কম্প্রেশন মেকানিজম। compressionMechanism নিম্নলিখিতগুলির মধ্যে কেবল একটি হতে পারে:
slidingWindow

SlidingWindow

একটি স্লাইডিং-উইন্ডো ব্যবস্থা।

triggerTokens

int64

একটি টার্ন শুরু করার আগে কনটেক্সট উইন্ডো কম্প্রেশন চালু করার জন্য প্রয়োজনীয় টোকেনের সংখ্যা।

এটি কোয়ালিটি ও ল্যাটেন্সির মধ্যে ভারসাম্য রক্ষা করতে ব্যবহার করা যেতে পারে, কারণ ছোট কনটেক্সট উইন্ডোর ফলে মডেলের প্রতিক্রিয়া দ্রুততর হতে পারে। তবে, যেকোনো কম্প্রেশন অপারেশনের কারণে সাময়িকভাবে ল্যাটেন্সি বেড়ে যায়, তাই এগুলো ঘন ঘন চালু করা উচিত নয়।

সেট করা না থাকলে, ডিফল্ট হিসেবে মডেলের কনটেক্সট উইন্ডো লিমিটের ৮০% ব্যবহৃত হয়। এর ফলে পরবর্তী ইউজার রিকোয়েস্ট বা মডেল রেসপন্সের জন্য ২০% জায়গা অবশিষ্ট থাকে।

EndSensitive

বক্তৃতার সমাপ্তি কীভাবে শনাক্ত করা হবে তা নির্ধারণ করে।

এনাম
END_SENSITIVITY_UNSPECIFIED ডিফল্ট মান হলো END_SENSITIVITY_HIGH।
END_SENSITIVITY_HIGH স্বয়ংক্রিয় সনাক্তকরণ প্রায়শই বক্তৃতা শেষ করে দেয়।
END_SENSITIVITY_LOW স্বয়ংক্রিয় সনাক্তকরণ ব্যবস্থা বক্তৃতা শেষ হওয়ার ঘটনা কমই ঘটে।

চলে যাও

সার্ভারটি শীঘ্রই সংযোগ বিচ্ছিন্ন করবে বলে একটি বিজ্ঞপ্তি।

ক্ষেত্র
timeLeft

Duration

সংযোগটি বাতিল (ABORTED) হিসেবে সমাপ্ত হওয়ার আগে অবশিষ্ট সময়।

এই সময়কাল কখনোই মডেল-নির্দিষ্ট একটি ন্যূনতম সময়ের চেয়ে কম হবে না, যা মডেলটির জন্য নির্ধারিত হারের সীমার সাথে উল্লেখ করা হবে।

হিস্টোরিকনফিগ

ইতিহাস কনফিগারেশন।

এই বার্তাটি সেশন কনফিগারেশনে BidiGenerateContentSetup.historyConfig হিসেবে অন্তর্ভুক্ত থাকে। এটি হিস্ট্রি বার্তার আদান-প্রদান কনফিগার করে।

ক্ষেত্র
initialHistoryInClientContent

bool

ঐচ্ছিক। যদি এটি সত্য হয়, setupComplete পাঠানোর পর, সার্ভার অপেক্ষা করবে এবং turnComplete true না হওয়া পর্যন্ত প্রথমে clientContent বার্তাগুলো প্রসেস করবে। এই প্রাথমিক প্রক্রিয়াটি কোনো মডেল কল ট্রিগার করবে না এবং এটি role MODEL দিয়ে শেষ হতে পারে। turnComplete true হওয়ার পর, ক্লায়েন্ট realtimeInput মাধ্যমে রিয়েলটাইম কথোপকথন শুরু করতে পারবে।

প্রোঅ্যাকটিভিটিকনফিগ

সক্রিয়তা বৈশিষ্ট্যগুলির জন্য কনফিগারেশন।

ক্ষেত্র
proactiveAudio

bool

ঐচ্ছিক। এটি সক্রিয় করা হলে, মডেলটি সর্বশেষ প্রম্পটের উত্তর দিতে অস্বীকার করতে পারে। উদাহরণস্বরূপ, এটি মডেলটিকে অপ্রাসঙ্গিক কথাবার্তা উপেক্ষা করার অথবা ব্যবহারকারী এখনও কোনো অনুরোধ না করলে নীরব থাকার সুযোগ দেয়।

রিয়েলটাইমইনপুটকনফিগ

BidiGenerateContent এ রিয়েলটাইম ইনপুট আচরণ কনফিগার করে।

ক্ষেত্র
automaticActivityDetection

AutomaticActivityDetection

ঐচ্ছিক। সেট করা না থাকলে, স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণ ডিফল্টরূপে সক্রিয় থাকে। যদি স্বয়ংক্রিয় ভয়েস সনাক্তকরণ নিষ্ক্রিয় করা থাকে, তবে ক্লায়েন্টকে অবশ্যই কার্যকলাপ সংকেত পাঠাতে হবে।

activityHandling

ActivityHandling

ঐচ্ছিক। কোনো কার্যকলাপের প্রভাব নির্ধারণ করে।

turnCoverage

TurnCoverage

ঐচ্ছিক। ব্যবহারকারীর পালায় কোন কোন ইনপুট অন্তর্ভুক্ত হবে তা নির্ধারণ করে।

সেশনরিজাম্পশনকনফিগ

সেশন পুনরায় শুরু করার কনফিগারেশন।

এই বার্তাটি সেশন কনফিগারেশনে BidiGenerateContentSetup.sessionResumption হিসেবে অন্তর্ভুক্ত থাকে। কনফিগার করা থাকলে, সার্ভার SessionResumptionUpdate বার্তা পাঠাবে।

ক্ষেত্র
handle

string

পূর্ববর্তী সেশনের হ্যান্ডেল। এটি উপস্থিত না থাকলে একটি নতুন সেশন তৈরি করা হয়।

পূর্ববর্তী সংযোগগুলিতে থাকা SessionResumptionUpdate.token ভ্যালু থেকে সেশন হ্যান্ডেলগুলি আসে।

সেশনপুনরায় শুরু আপডেট

সেশন পুনরায় চালুর অবস্থার হালনাগাদ।

শুধুমাত্র তখনই পাঠানো হবে যদি BidiGenerateContentSetup.sessionResumption সেট করা থাকে।

ক্ষেত্র
newHandle

string

নতুন হ্যান্ডেল যা এমন একটি অবস্থাকে নির্দেশ করে যা পুনরায় চালু করা যেতে পারে। যদি resumable = false হয়, তবে এটি খালি থাকবে।

resumable

bool

এই পর্যায়ে বর্তমান সেশনটি পুনরায় শুরু করা সম্ভব হলে সত্য।

সেশনের কিছু নির্দিষ্ট পর্যায়ে সেশন পুনরায় শুরু করা সম্ভব নয়। উদাহরণস্বরূপ, যখন মডেলটি ফাংশন কল সম্পাদন করে বা জেনারেট করে। এই অবস্থায় (পূর্ববর্তী সেশন টোকেন ব্যবহার করে) সেশন পুনরায় শুরু করলে কিছু ডেটা নষ্ট হবে। এই ক্ষেত্রে, newHandle খালি থাকবে এবং resumable false হবে।

স্লাইডিং উইন্ডো

SlidingWindow মেথডটি কনটেক্সট উইন্ডোর শুরুর দিকের কন্টেন্ট বাদ দিয়ে কাজ করে। এর ফলে প্রাপ্ত কনটেক্সটটি সর্বদা একটি USER রোলের টার্নের শুরু থেকে শুরু হবে। সিস্টেম ইনস্ট্রাকশন এবং যেকোনো BidiGenerateContentSetup.prefixTurns সর্বদা ফলাফলের শুরুতে থেকে যাবে।

ক্ষেত্র
targetTokens

int64

সংরক্ষণ করার জন্য টোকেনের লক্ষ্যমাত্রা সংখ্যা। ডিফল্ট মান হলো trigger_tokens/2।

কনটেক্সট উইন্ডোর অংশবিশেষ বাদ দিলে সাময়িকভাবে ল্যাটেন্সি বেড়ে যায়, তাই ঘন ঘন কম্প্রেশন অপারেশন এড়াতে এই মানটি ক্যালিব্রেট করা উচিত।

স্টার্টসেনসিটিভিটি

বক্তৃতার শুরু কীভাবে শনাক্ত করা হবে তা নির্ধারণ করে।

এনাম
START_SENSITIVITY_UNSPECIFIED ডিফল্ট মান হলো START_SENSITIVITY_HIGH।
START_SENSITIVITY_HIGH স্বয়ংক্রিয় সনাক্তকরণ ব্যবস্থা আরও ঘন ঘন বক্তৃতার শুরু সনাক্ত করবে।
START_SENSITIVITY_LOW স্বয়ংক্রিয় সনাক্তকরণ ব্যবস্থার মাধ্যমে বক্তৃতার শুরু কমই শনাক্ত করা যাবে।

টার্ন কভারেজ

ব্যবহারকারীর পালায় কোন কোন ইনপুট অন্তর্ভুক্ত হবে সে সম্পর্কিত বিকল্পসমূহ।

এনাম
TURN_COVERAGE_UNSPECIFIED অনির্দিষ্ট থাকলে, মডেলের উপর ভিত্তি করে একটি ডিফল্ট আচরণ নির্বাচিত হয়। যেমন, Gemini 2.5-এর জন্য ডিফল্ট হলো TURN_INCLUDES_ONLY_ACTIVITY , আর Gemini 3.1 ও তার পরবর্তী সংস্করণগুলোর জন্য এটি হলো TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO
TURN_INCLUDES_ONLY_ACTIVITY শেষ টার্নের পর থেকে হওয়া কার্যকলাপ অন্তর্ভুক্ত, তবে নিষ্ক্রিয়তা (যেমন অডিও স্ট্রিমে নীরবতা) বাদ দেওয়া হয়েছে।
TURN_INCLUDES_ALL_INPUT শেষ চালের পর থেকে সমস্ত রিয়েল-টাইম ইনপুট অন্তর্ভুক্ত, যার মধ্যে নিষ্ক্রিয়তাও (যেমন অডিও স্ট্রিমে নীরবতা) রয়েছে।
TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO শেষ পালা থেকে অডিও কার্যকলাপ এবং সমস্ত ভিডিও অন্তর্ভুক্ত। স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণের ক্ষেত্রে, অডিও কার্যকলাপ বলতে কথাবার্তা বোঝায় এবং নীরবতা এর অন্তর্ভুক্ত নয়।

অনুবাদ কনফিগারেশন

অনুবাদ বৈশিষ্ট্যগুলির জন্য কনফিগারেশন।

ক্ষেত্র
targetLanguageCode

string

আবশ্যক। অনুবাদের জন্য লক্ষ্য ভাষা। সমর্থিত মানগুলি হলো BCP-47 ভাষা কোড (যেমন "en", "es", "fr")।

echoTargetLanguage

bool

ঐচ্ছিক। যদি 'true' হয়, তাহলে টার্গেট ভাষা বলা হলে মডেলটি অডিও তৈরি করবে, অর্থাৎ এটি ইনপুটটি হুবহু পুনরাবৃত্তি করবে। যদি 'false' হয়, তাহলে আমরা টার্গেট ভাষার জন্য কোনো অডিও তৈরি করব না।

ইউআরএলকনটেক্সটমেটাডেটা

ইউআরএল কনটেক্সট পুনরুদ্ধার টুল সম্পর্কিত মেটাডেটা।

ক্ষেত্র
urlMetadata[]

UrlMetadata

ইউআরএল কনটেক্সটের তালিকা।

ব্যবহার মেটাডেটা

প্রতিক্রিয়া(গুলো) সম্পর্কিত ব্যবহারের মেটাডেটা।

ক্ষেত্র
promptTokenCount

int32

শুধুমাত্র আউটপুট। প্রম্পটে থাকা টোকেনের সংখ্যা। যখন cachedContent সেট করা থাকে, তখনও এটিই মোট কার্যকর প্রম্পট সাইজ, অর্থাৎ এর মধ্যে ক্যাশ করা কন্টেন্টের টোকেন সংখ্যাও অন্তর্ভুক্ত থাকে।

cachedContentTokenCount

int32

প্রম্পটের ক্যাশ করা অংশে (ক্যাশ করা বিষয়বস্তু) থাকা টোকেনের সংখ্যা

responseTokenCount

int32

শুধুমাত্র আউটপুট। তৈরি হওয়া সমস্ত সম্ভাব্য উত্তরের মোট টোকেন সংখ্যা।

toolUsePromptTokenCount

int32

শুধুমাত্র আউটপুট। টুল-ব্যবহারের প্রম্পট(গুলি)-তে উপস্থিত টোকেনের সংখ্যা।

thoughtsTokenCount

int32

শুধুমাত্র আউটপুট। চিন্তন মডেলগুলোর জন্য চিন্তার টোকেনের সংখ্যা।

totalTokenCount

int32

শুধুমাত্র আউটপুট। জেনারেশন অনুরোধের জন্য মোট টোকেন সংখ্যা (প্রম্পট + সম্ভাব্য প্রতিক্রিয়া)।

promptTokensDetails[]

ModalityTokenCount

শুধুমাত্র আউটপুট। অনুরোধের ইনপুটে প্রক্রিয়াকৃত মোডালিটিগুলোর তালিকা।

cacheTokensDetails[]

ModalityTokenCount

শুধুমাত্র আউটপুট। অনুরোধ ইনপুটে থাকা ক্যাশ করা কন্টেন্টের মোডালিটির তালিকা।

responseTokensDetails[]

ModalityTokenCount

শুধুমাত্র আউটপুট। প্রতিক্রিয়ায় ফেরত আসা মোডালিটিগুলোর তালিকা।

toolUsePromptTokensDetails[]

ModalityTokenCount

শুধুমাত্র আউটপুট। টুল-ব্যবহারের অনুরোধের ইনপুটগুলোর জন্য যে মোডালিটিগুলো প্রক্রিয়া করা হয়েছিল, তার তালিকা।

ক্ষণস্থায়ী প্রমাণীকরণ টোকেন

AuthTokenService.CreateToken কল করে ক্ষণস্থায়ী প্রমাণীকরণ টোকেন পাওয়া যায় এবং তারপর তা GenerativeService.BidiGenerateContentConstrained এর সাথে ব্যবহার করা যায়। এর জন্য টোকেনটিকে হয় একটি access_token কোয়েরি প্যারামিটারে পাস করতে হয়, অথবা একটি HTTP Authorization হেডারের শুরুতে " Token " উপসর্গ যোগ করে পাস করতে হয়।

CreateAuthTokenRequest

একটি ক্ষণস্থায়ী প্রমাণীকরণ টোকেন তৈরি করুন।

ক্ষেত্র
authToken

AuthToken

তৈরির জন্য টোকেনটি প্রয়োজন।

অথটোকেন

একটি ক্ষণস্থায়ী প্রমাণীকরণ টোকেন তৈরি করার অনুরোধ।

ক্ষেত্র
name

string

শুধুমাত্র আউটপুট। শনাক্তকারী। টোকেনটি নিজে।

expireTime

Timestamp

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। একটি ঐচ্ছিক সময়, যার পরে প্রাপ্ত টোকেনটি ব্যবহার করার সময় BidiGenerateContent সেশনের বার্তাগুলি প্রত্যাখ্যান করা হবে। (এই সময়ের পরে Gemini আগেভাগেই সেশনটি বন্ধ করে দিতে পারে।)

সেট করা না থাকলে, এটি স্বয়ংক্রিয়ভাবে ৩০ মিনিট ভবিষ্যতের সময় দেখাবে। সেট করা থাকলে, এই মানটি অবশ্যই ২০ ঘণ্টার কম ভবিষ্যতের হতে হবে।

newSessionExpireTime

Timestamp

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। যে সময়ের পর এই অনুরোধের ফলে প্রাপ্ত টোকেন ব্যবহার করে নতুন লাইভ এপিআই সেশনগুলো প্রত্যাখ্যান করা হবে।

সেট করা না থাকলে এটি স্বয়ংক্রিয়ভাবে ভবিষ্যতের ৬০ সেকেন্ড সময় নেয়। সেট করা থাকলে, এই মানটি অবশ্যই ভবিষ্যতের ২০ ঘণ্টার কম হতে হবে।

fieldMask

FieldMask

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। যদি field_mask খালি থাকে এবং bidiGenerateContentSetup উপস্থিত না থাকে, তাহলে কার্যকর BidiGenerateContentSetup বার্তাটি লাইভ এপিআই সংযোগ থেকে নেওয়া হয়।

যদি field_mask খালি থাকে এবং bidiGenerateContentSetup উপস্থিত থাকে , তাহলে এই অনুরোধে কার্যকর BidiGenerateContentSetup বার্তাটি সম্পূর্ণরূপে bidiGenerateContentSetup থেকেই নেওয়া হয়। লাইভ এপিআই সংযোগ থেকে আসা সেটআপ বার্তাটি উপেক্ষা করা হয়।

যদি field_mask খালি না থাকে, তাহলে bidiGenerateContentSetup থেকে সংশ্লিষ্ট ফিল্ডগুলো Live API সংযোগের সেটআপ বার্তার ফিল্ডগুলোকে ওভাররাইট করবে।

ইউনিয়ন ফিল্ড config । ফলাফলস্বরূপ প্রাপ্ত টোকেনের জন্য মেথড-নির্দিষ্ট কনফিগারেশন। config নিম্নলিখিতগুলির মধ্যে কেবল একটি হতে পারে:
bidiGenerateContentSetup

BidiGenerateContentSetup

ঐচ্ছিক। শুধুমাত্র ইনপুট। অপরিবর্তনীয়। BidiGenerateContent জন্য নির্দিষ্ট কনফিগারেশন।

uses

int32

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

সাধারণ প্রকার সম্পর্কে আরও তথ্য

সাধারণভাবে ব্যবহৃত API রিসোর্স টাইপ Blob , Content , FunctionCall , FunctionResponse , GenerationConfig , GroundingMetadata , ModalityTokenCount এবং Tool সম্পর্কে আরও তথ্যের জন্য, Generating content দেখুন।

,

লাইভ এপিআই হলো একটি স্টেটফুল এপিআই যা ওয়েবসকেটস ব্যবহার করে। এই অংশে আপনি ওয়েবসকেটস এপিআই সম্পর্কে আরও বিস্তারিত তথ্য পাবেন।

অধিবেশন

একটি ওয়েবসকেট সংযোগ ক্লায়েন্ট এবং জেমিনি সার্ভারের মধ্যে একটি সেশন স্থাপন করে। ক্লায়েন্ট একটি নতুন সংযোগ শুরু করার পর, সেশনটি সার্ভারের সাথে নিম্নলিখিত উদ্দেশ্যে বার্তা আদান-প্রদান করতে পারে:

  • জেমিনি সার্ভারে টেক্সট, অডিও বা ভিডিও পাঠান।
  • জেমিনি সার্ভার থেকে অডিও, টেক্সট বা ফাংশন কল অনুরোধ গ্রহণ করুন।

ওয়েবসকেট সংযোগ

একটি সেশন শুরু করতে, এই ওয়েবসকেট এন্ডপয়েন্টে সংযোগ করুন:

wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent

সেশন কনফিগারেশন

WebSocket সংযোগ স্থাপনের পর পাঠানো প্রাথমিক বার্তাটি সেশন কনফিগারেশন নির্ধারণ করে, যার মধ্যে মডেল, জেনারেশন প্যারামিটার, সিস্টেম নির্দেশাবলী এবং টুলস অন্তর্ভুক্ত থাকে।

সংযোগ খোলা থাকা অবস্থায় আপনি কনফিগারেশন আপডেট করতে পারবেন না। তবে, সেশন রিজাম্পশন মেকানিজমের মাধ্যমে সেশন পজ ও রিজুম করার সময় আপনি মডেল ছাড়া অন্যান্য কনফিগারেশন প্যারামিটারগুলো পরিবর্তন করতে পারবেন।

নিম্নলিখিত উদাহরণ কনফিগারেশনটি দেখুন। মনে রাখবেন যে SDK-গুলিতে নামের কেসিং ভিন্ন হতে পারে। আপনি এখানে পাইথন SDK কনফিগারেশন অপশনগুলো দেখে নিতে পারেন।


{
  "model": string,
  "generationConfig": {
    "candidateCount": integer,
    "maxOutputTokens": integer,
    "temperature": number,
    "topP": number,
    "topK": integer,
    "presencePenalty": number,
    "frequencyPenalty": number,
    "responseModalities": [string],
    "speechConfig": object,
    "mediaResolution": object,
    "translationConfig": object
  },
  "systemInstruction": string,
  "tools": [object]
}

API ফিল্ড সম্পর্কে আরও তথ্যের জন্য, generationConfig দেখুন।

বার্তা পাঠান

WebSocket সংযোগের মাধ্যমে বার্তা আদান-প্রদান করতে, ক্লায়েন্টকে একটি খোলা WebSocket সংযোগের মাধ্যমে একটি JSON অবজেক্ট পাঠাতে হবে। JSON অবজেক্টটিতে নিম্নলিখিত অবজেক্ট সেট থেকে ঠিক একটি ফিল্ড থাকতে হবে:


{
  "setup": BidiGenerateContentSetup,
  "clientContent": BidiGenerateContentClientContent,
  "realtimeInput": BidiGenerateContentRealtimeInput,
  "toolResponse": BidiGenerateContentToolResponse
}

সমর্থিত ক্লায়েন্ট বার্তা

নিম্নলিখিত সারণীতে সমর্থিত ক্লায়েন্ট বার্তাগুলি দেখুন:

বার্তা বর্ণনা
BidiGenerateContentSetup প্রথম মেসেজে সেশন কনফিগারেশন পাঠানো হবে।
BidiGenerateContentClientContent ক্লায়েন্টের কাছ থেকে প্রাপ্ত বর্তমান কথোপকথনের ক্রমবর্ধমান বিষয়বস্তু হালনাগাদ।
BidiGenerateContentRealtimeInput রিয়েল টাইম অডিও, ভিডিও, বা টেক্সট ইনপুট
BidiGenerateContentToolResponse সার্ভার থেকে প্রাপ্ত ToolCallMessage এর প্রতিক্রিয়া

বার্তা গ্রহণ করুন

জেমিনি থেকে বার্তা গ্রহণ করতে, ওয়েবসকেট 'message' ইভেন্টের জন্য লিসেন করুন এবং তারপরে সমর্থিত সার্ভার বার্তাগুলির সংজ্ঞা অনুযায়ী ফলাফলটি পার্স করুন।

নিম্নলিখিতগুলি দেখুন:

async with client.aio.live.connect(model='...', config=config) as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
        print(message)

সার্ভার মেসেজে একটি usageMetadata ফিল্ড থাকতে পারে, কিন্তু এছাড়া এটি BidiGenerateContentServerMessage মেসেজের অন্য ফিল্ডগুলোর মধ্যে ঠিক একটি অন্তর্ভুক্ত করবে। ( messageType ইউনিয়নটি JSON-এ প্রকাশ করা হয় না, তাই ফিল্ডটি মেসেজের শীর্ষ-স্তরে প্রদর্শিত হবে।)

বার্তা এবং ঘটনা

কার্যকলাপ শেষ

এই প্রকারে কোনো ক্ষেত্র নেই।

ব্যবহারকারীর কার্যকলাপের সমাপ্তি নির্দেশ করে।

কার্যকলাপ পরিচালনা

ব্যবহারকারীর কার্যকলাপ পরিচালনার বিভিন্ন উপায়।

এনাম
ACTIVITY_HANDLING_UNSPECIFIED অনির্দিষ্ট থাকলে, ডিফল্ট আচরণ হলো START_OF_ACTIVITY_INTERRUPTS
START_OF_ACTIVITY_INTERRUPTS যদি সত্য হয়, তাহলে কার্যকলাপ শুরু হলে মডেলের প্রতিক্রিয়া বাধাগ্রস্ত হবে (একে "বার্জ ইন"ও বলা হয়)। বাধাগ্রস্ত হওয়ার মুহূর্তে মডেলের বর্তমান প্রতিক্রিয়াটি বন্ধ হয়ে যাবে। এটিই ডিফল্ট আচরণ।
NO_INTERRUPTION মডেলের প্রতিক্রিয়া ব্যাহত হবে না।

কার্যকলাপ শুরু

এই প্রকারে কোনো ক্ষেত্র নেই।

ব্যবহারকারীর কার্যকলাপের সূচনা নির্দেশ করে।

অডিও ট্রান্সক্রিপশন কনফিগারেশন

অডিও ট্রান্সক্রিপশন কনফিগারেশন।

ক্ষেত্র
languageCodes[]

string

ঐচ্ছিক। BCP-47 ভাষা কোড যা অডিওতে উপস্থিত ভাষাগুলো সম্পর্কে ইঙ্গিত দেয়। এটি বাদ দিলে বা খালি রাখলে, ডিফল্টরূপে স্বয়ংক্রিয় ভাষা শনাক্তকরণ ব্যবহৃত হবে।

customVocabulary[]

string

ঐচ্ছিক। স্পিচ রিকগনিশন মডেলকে নির্দিষ্ট পদ (পণ্যের নাম, বিশেষ্য পদ, পারিভাষিক শব্দ) শনাক্ত করার দিকে প্রভাবিত করার জন্য নিজস্ব শব্দভাণ্ডারের একটি তালিকা।

wordTimestamp

bool

ঐচ্ছিক। এটি ওয়ার্ড-স্তরের টাইমস্ট্যাম্প তৈরি কনফিগার করে।

diarization

bool

ঐচ্ছিক। স্পিকার ডায়ারাইজেশন কনফিগার করে।

mode

Mode

ঐচ্ছিক। ট্রান্সক্রিপশন মোড কনফিগার করে। সমর্থিত মান: VERBATIM , SMART । নির্দিষ্ট না করা হলে, ডিফল্ট হিসেবে VERBATIM ট্রান্সক্রিপশন ব্যবহৃত হয়। SMART মোডে, মডেলটি সাবলীলতার অভাব দূর করে (অপ্রয়োজনীয় শব্দ, পুনরাবৃত্তি এবং ভুল শুরু বাদ দিয়ে), হালকা ব্যাকরণগত পরিমার্জন করে, স্বয়ংক্রিয়ভাবে ফরম্যাটিং করে (প্যারাগ্রাফ, বুলেট পয়েন্ট, সংখ্যাযুক্ত তালিকা) এবং ব্যবহারকারীর ছোটখাটো সম্পাদনা (ইনলাইন স্ব-সংশোধন) করে। টাইমস্ট্যাম্প এবং ডায়ারাইজেশন SMART মোডের সাথে সামঞ্জস্যপূর্ণ নয়।

মোড

ট্রান্সক্রিপশন মোড।

এনাম
MODE_UNSPECIFIED অনির্দিষ্ট ট্রান্সক্রিপশন মোড।
VERBATIM হুবহু প্রতিলিপি মোড।
SMART স্মার্ট ট্রান্সক্রিপশন মোড।

স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণ

কার্যকলাপের স্বয়ংক্রিয় সনাক্তকরণ কনফিগার করে।

ক্ষেত্র
disabled

bool

ঐচ্ছিক। যদি এটি সক্রিয় থাকে (যা ডিফল্টরূপে চালু থাকে), তাহলে শনাক্তকৃত ভয়েস এবং টেক্সট ইনপুট কার্যকলাপ হিসেবে গণ্য হবে। যদি এটি নিষ্ক্রিয় থাকে, তাহলে ক্লায়েন্টকে অবশ্যই কার্যকলাপ সংকেত পাঠাতে হবে।

startOfSpeechSensitivity

StartSensitivity

ঐচ্ছিক। এটি নির্ধারণ করে যে কথা শনাক্ত হওয়ার সম্ভাবনা কতটা।

prefixPaddingMs

int32

ঐচ্ছিক। বক্তব্য শুরু হওয়ার আগে শনাক্তকৃত বক্তব্যের প্রয়োজনীয় সময়কাল। এই মান যত কম হবে, বক্তব্য শুরু শনাক্তকরণ তত বেশি সংবেদনশীল হবে এবং ছোট বক্তব্যও শনাক্ত করা যাবে। তবে, এতে ভুল শনাক্তকরণের সম্ভাবনাও বেড়ে যায়।

endOfSpeechSensitivity

EndSensitivity

ঐচ্ছিক। শনাক্তকৃত বক্তব্য শেষ হওয়ার সম্ভাবনা কতটুকু, তা নির্ধারণ করে।

silenceDurationMs

int32

ঐচ্ছিক। কথা শেষ হওয়ার আগে শনাক্তকৃত কথাবিহীন অংশের (যেমন নীরবতা) প্রয়োজনীয় সময়কাল। এই মান যত বেশি হবে, ব্যবহারকারীর কাজে বাধা না দিয়ে কথার বিরতি তত দীর্ঘ হতে পারবে, কিন্তু এতে মডেলের ল্যাটেন্সি বেড়ে যাবে।

বিডিজেনারেট কনটেন্ট ক্লায়েন্ট কনটেন্ট

ক্লায়েন্টের কাছ থেকে পাঠানো বর্তমান কথোপকথনের ক্রমবর্ধমান হালনাগাদ। এখানকার সমস্ত বিষয়বস্তু নিঃশর্তভাবে কথোপকথনের ইতিহাসে যুক্ত করা হয় এবং মডেলকে বিষয়বস্তু তৈরি করার জন্য নির্দেশনার অংশ হিসেবে ব্যবহৃত হয়।

এখানে একটি বার্তা দিলে চলমান মডেল তৈরির প্রক্রিয়াটি বাধাগ্রস্ত হবে।

ক্ষেত্র
turns[]

Content

ঐচ্ছিক। মডেলের সাথে চলমান কথোপকথনের সাথে যুক্ত বিষয়বস্তু।

একক-টার্ন কোয়েরির ক্ষেত্রে, এটি একটি একক ইনস্ট্যান্স। একাধিক-টার্ন কোয়েরির ক্ষেত্রে, এটি একটি পুনরাবৃত্ত ক্ষেত্র যা কথোপকথনের ইতিহাস এবং সর্বশেষ অনুরোধ ধারণ করে।

turnComplete

bool

ঐচ্ছিক। যদি 'true' হয়, তবে এটি নির্দেশ করে যে সার্ভারে কন্টেন্ট তৈরি বর্তমানে জমা হওয়া প্রম্পট থেকে শুরু হবে। অন্যথায়, সার্ভার তৈরি শুরু করার আগে অতিরিক্ত বার্তার জন্য অপেক্ষা করবে।

বিডিজেনারেট কনটেন্ট রিয়েলটাইম ইনপুট

ব্যবহারকারীর ইনপুট যা রিয়েল টাইমে পাঠানো হয়।

বিভিন্ন মাধ্যম (অডিও, ভিডিও এবং টেক্সট) যুগপৎ প্রবাহ হিসেবে পরিচালিত হয়। এই প্রবাহগুলোর মধ্যে ক্রমবিন্যাস নিশ্চিত করা হয় না।

এটি BidiGenerateContentClientContent থেকে কয়েকটি দিক দিয়ে আলাদা:

  • মডেল তৈরির জন্য নিরবচ্ছিন্নভাবে পাঠানো যেতে পারে।
  • যদি BidiGenerateContentClientContent এবং BidiGenerateContentRealtimeInput এর মধ্যে ডেটা এলোমেলোভাবে মেশানোর প্রয়োজন হয়, তবে সার্ভার সর্বোত্তম প্রতিক্রিয়ার জন্য অপ্টিমাইজ করার চেষ্টা করে, কিন্তু এর কোনো নিশ্চয়তা নেই।
  • পালা শেষ হওয়ার সময় স্পষ্টভাবে নির্দিষ্ট করা থাকে না, বরং তা ব্যবহারকারীর কার্যকলাপ থেকে নির্ধারিত হয় (যেমন, বক্তৃতা শেষ হওয়া)।
  • পালা শেষ হওয়ার আগেও, মডেল থেকে দ্রুত প্রতিক্রিয়া শুরু করার জন্য ডেটা পর্যায়ক্রমে প্রক্রিয়াজাত করা হয়।
ক্ষেত্র
mediaChunks[]

Blob

ঐচ্ছিক। মিডিয়া ইনপুটের জন্য ইনলাইন করা বাইট ডেটা। একাধিক mediaChunks সমর্থিত নয়, প্রথমটি ছাড়া বাকি সব উপেক্ষা করা হবে।

অপ্রচলিত: এর পরিবর্তে audio , video বা text ব্যবহার করুন।

audio

Blob

ঐচ্ছিক। এগুলো রিয়েলটাইম অডিও ইনপুট স্ট্রিম গঠন করে।

video

Blob

ঐচ্ছিক। এগুলো রিয়েলটাইম ভিডিও ইনপুট স্ট্রিম গঠন করে।

activityStart

ActivityStart

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

activityEnd

ActivityEnd

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

mediaResolution

MediaResolution

ঐচ্ছিক। যে মিডিয়া রেজোলিউশনটি ব্যবহার করা হবে। যদি নির্দিষ্ট করে না দেওয়া হয়, তাহলে setup.generationConfig.mediaResolution ব্যবহৃত হবে অথবা সেটআপ প্রদান করা না হলে একটি ডিফল্ট ব্যবহৃত হবে।

audioStreamEnd

bool

ঐচ্ছিক। এটি নির্দেশ করে যে অডিও প্রবাহ শেষ হয়ে গেছে, যেমন মাইক্রোফোন বন্ধ করার কারণে।

এটি শুধুমাত্র তখনই পাঠানো উচিত যখন স্বয়ংক্রিয় কার্যকলাপ সনাক্তকরণ সক্রিয় থাকে (যা ডিফল্টরূপে চালু থাকে)।

ক্লায়েন্ট একটি অডিও বার্তা পাঠিয়ে স্ট্রিমটি পুনরায় চালু করতে পারেন।

text

string

ঐচ্ছিক। এগুলো রিয়েলটাইম টেক্সট ইনপুট স্ট্রিম গঠন করে।

বিডিজেনারেট কনটেন্ট সার্ভার কন্টেন্ট

ক্লায়েন্টের বার্তার প্রতিক্রিয়ায় মডেল দ্বারা তৈরি ক্রমবর্ধমান সার্ভার আপডেট।

কন্টেন্ট যত দ্রুত সম্ভব তৈরি করা হয়, রিয়েল টাইমে নয়। ক্লায়েন্টরা চাইলে তা বাফার করে রিয়েল টাইমে প্লে করতে পারেন।

ক্ষেত্র
generationComplete

bool

শুধুমাত্র আউটপুট। যদি 'true' হয়, তবে এটি নির্দেশ করে যে মডেলটি তৈরি করা শেষ হয়েছে।

মডেল তৈরির সময় বাধাগ্রস্ত হলে, বাধাগ্রস্ত টার্নে 'generation_complete' বার্তাটি আসবে না, বরং এটি 'interrupted > turn_complete' ধাপে ধাপে সম্পন্ন হবে।

যখন মডেল রিয়েলটাইম প্লেব্যাক চালু করে, তখন generation_complete এবং turn_complete-এর মধ্যে একটি বিলম্ব ঘটে, যা প্লেব্যাক শেষ হওয়ার জন্য মডেলের অপেক্ষার কারণে হয়ে থাকে।

turnComplete

bool

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

interrupted

bool

শুধুমাত্র আউটপুট। যদি সত্য হয়, তবে এটি নির্দেশ করে যে একটি ক্লায়েন্ট বার্তা বর্তমান মডেল তৈরি প্রক্রিয়াকে বাধাগ্রস্ত করেছে। যদি ক্লায়েন্ট রিয়েল টাইমে কন্টেন্টটি প্লে করে, তবে এটি থামার এবং বর্তমান প্লেব্যাক কিউ খালি করার একটি ভালো সংকেত।

groundingMetadata

GroundingMetadata

শুধুমাত্র আউটপুট। তৈরি করা কন্টেন্টের জন্য মেটাডেটা গ্রাউন্ডিং করা হচ্ছে।

inputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। অডিও ট্রান্সক্রিপশন ইনপুট করুন। ট্রান্সক্রিপশনটি সার্ভারের অন্যান্য বার্তা থেকে স্বাধীনভাবে পাঠানো হয় এবং এর কোনো নিশ্চিত ক্রম নেই।

interimInputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। ব্যবহারকারী কথা বলার সময়েই স্বল্প বিলম্বের ট্রান্সক্রিপশন আপডেট হয়। এই ফিল্ডটি ঘন ঘন আপডেট করা হতে পারে।

outputTranscription

BidiGenerateContentTranscription

শুধুমাত্র আউটপুট। অডিও ট্রান্সক্রিপশন আউটপুট করুন। এই ট্রান্সক্রিপশনগুলো সার্ভারের জেনারেশন আউটপুটের অংশ। এই টার্নের সর্বশেষ আউটপুট ট্রান্সক্রিপশনটি generationComplete বা interrupted আগে পাঠানো হয়, যার পরে turnComplete পাঠানো হয়। ট্রান্সক্রিপশন এবং অন্যান্য modelTurn আউটপুটের মধ্যে কোনো নির্দিষ্ট ক্রমের নিশ্চয়তা নেই, তবে সার্ভার সংশ্লিষ্ট অডিও আউটপুটের কাছাকাছি সময়ে ট্রান্সক্রিপশনগুলো পাঠানোর চেষ্টা করে।

urlContextMetadata

UrlContextMetadata

waitingForInput

bool

শুধুমাত্র আউটপুট। যদি এটি সত্য হয়, তবে এটি নির্দেশ করে যে মডেলটি কোনো কন্টেন্ট তৈরি করছে না কারণ এটি ব্যবহারকারীর কাছ থেকে আরও ইনপুটের জন্য অপেক্ষা করছে, যেমন—এটি আশা করছে যে ব্যবহারকারী কথা বলতে থাকবে।

speechState
(deprecated)

SpeechState

শুধুমাত্র আউটপুট। অপ্রচলিত: এর পরিবর্তে VoiceActivity ব্যবহার করুন।

realtimeInput.audio তে স্পিচ ডিটেকশনের বর্তমান অবস্থা নির্দেশ করে। অবস্থা অপরিবর্তিত থাকলে এটি সেট করা নেই বা শূন্য।

interactionStatus

InteractionStatus

Output only. The current activity status of the live session. Always sent alongside turnComplete .

modelTurn

Content

Output only. The content that the model has generated as part of the current conversation with the user.

BidiGenerateContentServerMessage

Response message for the BidiGenerateContent call.

ক্ষেত্র
usageMetadata

UsageMetadata

Output only. Usage metadata about the response(s).

Union field messageType . The type of the message. messageType can be only one of the following:
setupComplete

BidiGenerateContentSetupComplete

Output only. Sent in response to a BidiGenerateContentSetup message from the client when setup is complete.

serverContent

BidiGenerateContentServerContent

Output only. Content generated by the model in response to client messages.

toolCall

BidiGenerateContentToolCall

Output only. Request for the client to execute the functionCalls and return the responses with the matching id s.

toolCallCancellation

BidiGenerateContentToolCallCancellation

Output only. Notification for the client that a previously issued ToolCallMessage with the specified id s should be cancelled.

goAway

GoAway

Output only. A notice that the server will soon disconnect.

sessionResumptionUpdate

SessionResumptionUpdate

Output only. Update of the session resumption state.

BidiGenerateContentSetup

Message to be sent in the first (and only in the first) BidiGenerateContentClientMessage . Contains configuration that will apply for the duration of the streaming RPC.

Clients should wait for a BidiGenerateContentSetupComplete message before sending any additional messages.

ক্ষেত্র
model

string

Required. The model's resource name. This serves as an ID for the Model to use.

Format: models/{model}

generationConfig

GenerationConfig

Optional. Generation config.

The following fields are not supported:

  • responseLogprobs
  • responseMimeType
  • logprobs
  • responseSchema
  • responseJsonSchema
  • stopSequence
  • skipResponseCache
  • routingConfig
  • audioTimestamp
systemInstruction

Content

Optional. The user provided system instructions for the model.

Note: Only text should be used in parts and content in each part will be in a separate paragraph.

tools[]

Tool

Optional. A list of Tools the model may use to generate the next response.

A Tool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model.

realtimeInputConfig

RealtimeInputConfig

Optional. Configures the handling of realtime input.

sessionResumption

SessionResumptionConfig

Optional. Configures session resumption mechanism.

If included, the server will send SessionResumptionUpdate messages.

contextWindowCompression

ContextWindowCompressionConfig

Optional. Configures a context window compression mechanism.

If included, the server will automatically reduce the size of the context when it exceeds the configured length.

inputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of voice input. The transcription aligns with the input audio language, if configured.

outputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of the model's audio output. The transcription aligns with the language code specified for the output audio, if configured.

proactivity

ProactivityConfig

Optional. Configures the proactivity of the model.

This allows the model to respond proactively to the input and to ignore irrelevant input.

historyConfig

HistoryConfig

Optional. Configures the exchange of history between the client and the server.

BidiGenerateContentSetupComplete

এই প্রকারে কোনো ক্ষেত্র নেই।

Sent in response to a BidiGenerateContentSetup message from the client.

BidiGenerateContentToolCall

Request for the client to execute the functionCalls and return the responses with the matching id s.

ক্ষেত্র
functionCalls[]

FunctionCall

Output only. The function call to be executed.

BidiGenerateContentToolCallCancellation

Notification for the client that a previously issued ToolCallMessage with the specified id s should not have been executed and should be cancelled. If there were side-effects to those tool calls, clients may attempt to undo the tool calls. This message occurs only in cases where the clients interrupt server turns.

ক্ষেত্র
ids[]

string

Output only. The ids of the tool calls to be cancelled.

BidiGenerateContentToolResponse

Client generated response to a ToolCall received from the server. Individual FunctionResponse objects are matched to the respective FunctionCall objects by the id field.

Note that in the unary and server-streaming GenerateContent APIs function calling happens by exchanging the Content parts, while in the bidi GenerateContent APIs function calling happens over these dedicated set of messages.

ক্ষেত্র
functionResponses[]

FunctionResponse

Optional. The response to the function calls.

BidiGenerateContentTranscription

Transcription of audio (input or output).

ক্ষেত্র
text

string

Transcription text.

languageCode

string

The BCP-47 language code of the transcription.

ContextWindowCompressionConfig

Enables context window compression — a mechanism for managing the model's context window so that it does not exceed a given length.

ক্ষেত্র
Union field compressionMechanism . The context window compression mechanism used. compressionMechanism can be only one of the following:
slidingWindow

SlidingWindow

A sliding-window mechanism.

triggerTokens

int64

The number of tokens (before running a turn) required to trigger a context window compression.

This can be used to balance quality against latency as shorter context windows may result in faster model responses. However, any compression operation will cause a temporary latency increase, so they should not be triggered frequently.

If not set, the default is 80% of the model's context window limit. This leaves 20% for the next user request/model response.

EndSensitivity

Determines how end of speech is detected.

এনাম
END_SENSITIVITY_UNSPECIFIED The default is END_SENSITIVITY_HIGH.
END_SENSITIVITY_HIGH Automatic detection ends speech more often.
END_SENSITIVITY_LOW Automatic detection ends speech less often.

GoAway

A notice that the server will soon disconnect.

ক্ষেত্র
timeLeft

Duration

The remaining time before the connection will be terminated as ABORTED.

This duration will never be less than a model-specific minimum, which will be specified together with the rate limits for the model.

HistoryConfig

History configuration.

This message is included in the session configuration as BidiGenerateContentSetup.historyConfig . Configures the exchange of history messages.

ক্ষেত্র
initialHistoryInClientContent

bool

Optional. If true, after sending setupComplete , the server will wait and at first process clientContent messages until turnComplete is true . This initial history will not trigger a model call and may end with role MODEL . After turnComplete is true , the client can start the realtime conversation via realtimeInput .

ProactivityConfig

Config for proactivity features.

ক্ষেত্র
proactiveAudio

bool

Optional. If enabled, the model can reject responding to the last prompt. For example, this allows the model to ignore out of context speech or to stay silent if the user did not make a request, yet.

RealtimeInputConfig

Configures the realtime input behavior in BidiGenerateContent .

ক্ষেত্র
automaticActivityDetection

AutomaticActivityDetection

Optional. If not set, automatic activity detection is enabled by default. If automatic voice detection is disabled, the client must send activity signals.

activityHandling

ActivityHandling

Optional. Defines what effect activity has.

turnCoverage

TurnCoverage

Optional. Defines which input is included in the user's turn.

SessionResumptionConfig

Session resumption configuration.

This message is included in the session configuration as BidiGenerateContentSetup.sessionResumption . If configured, the server will send SessionResumptionUpdate messages.

ক্ষেত্র
handle

string

The handle of a previous session. If not present then a new session is created.

Session handles come from SessionResumptionUpdate.token values in previous connections.

SessionResumptionUpdate

Update of the session resumption state.

Only sent if BidiGenerateContentSetup.sessionResumption was set.

ক্ষেত্র
newHandle

string

New handle that represents a state that can be resumed. Empty if resumable =false.

resumable

bool

True if the current session can be resumed at this point.

Resumption is not possible at some points in the session. For example, when the model is executing function calls or generating. Resuming the session (using a previous session token) in such a state will result in some data loss. In these cases, newHandle will be empty and resumable will be false.

SlidingWindow

The SlidingWindow method operates by discarding content at the beginning of the context window. The resulting context will always begin at the start of a USER role turn. System instructions and any BidiGenerateContentSetup.prefixTurns will always remain at the beginning of the result.

ক্ষেত্র
targetTokens

int64

The target number of tokens to keep. The default value is trigger_tokens/2.

Discarding parts of the context window causes a temporary latency increase so this value should be calibrated to avoid frequent compression operations.

StartSensitivity

Determines how start of speech is detected.

এনাম
START_SENSITIVITY_UNSPECIFIED The default is START_SENSITIVITY_HIGH.
START_SENSITIVITY_HIGH Automatic detection will detect the start of speech more often.
START_SENSITIVITY_LOW Automatic detection will detect the start of speech less often.

TurnCoverage

Options about which input is included in the user's turn.

এনাম
TURN_COVERAGE_UNSPECIFIED If unspecified, a default behavior is selected based on the model. Eg, for Gemini 2.5, the default is TURN_INCLUDES_ONLY_ACTIVITY , while for Gemini 3.1 and onwards, it's TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO .
TURN_INCLUDES_ONLY_ACTIVITY Includes activity since the last turn, excluding inactivity (eg silence on the audio stream).
TURN_INCLUDES_ALL_INPUT Includes all realtime input since the last turn, including inactivity (eg silence on the audio stream).
TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO Includes audio activity and all video since the last turn. With automatic activity detection, audio activity means speech and excludes silence.

TranslationConfig

Config for translation features.

ক্ষেত্র
targetLanguageCode

string

Required. The target language for translation. Supported values are BCP-47 language codes (eg "en", "es", "fr").

echoTargetLanguage

bool

Optional. If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language.

UrlContextMetadata

Metadata related to url context retrieval tool.

ক্ষেত্র
urlMetadata[]

UrlMetadata

List of url context.

UsageMetadata

Usage metadata about response(s).

ক্ষেত্র
promptTokenCount

int32

Output only. Number of tokens in the prompt. When cachedContent is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content.

cachedContentTokenCount

int32

Number of tokens in the cached part of the prompt (the cached content)

responseTokenCount

int32

Output only. Total number of tokens across all the generated response candidates.

toolUsePromptTokenCount

int32

Output only. Number of tokens present in tool-use prompt(s).

thoughtsTokenCount

int32

Output only. Number of tokens of thoughts for thinking models.

totalTokenCount

int32

Output only. Total token count for the generation request (prompt + response candidates).

promptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed in the request input.

cacheTokensDetails[]

ModalityTokenCount

Output only. List of modalities of the cached content in the request input.

responseTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were returned in the response.

toolUsePromptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed for tool-use request inputs.

Ephemeral authentication tokens

Ephemeral authentication tokens can be obtained by calling AuthTokenService.CreateToken and then used with GenerativeService.BidiGenerateContentConstrained , either by passing the token in an access_token query parameter, or in an HTTP Authorization header with " Token " prefixed to it.

CreateAuthTokenRequest

Create an ephemeral authentication token.

ক্ষেত্র
authToken

AuthToken

Required. The token to create.

AuthToken

A request to create an ephemeral authentication token.

ক্ষেত্র
name

string

Output only. Identifier. The token itself.

expireTime

Timestamp

Optional. Input only. Immutable. An optional time after which, when using the resulting token, messages in BidiGenerateContent sessions will be rejected. (Gemini may preemptively close the session after this time.)

If not set then this defaults to 30 minutes in the future. If set, this value must be less than 20 hours in the future.

newSessionExpireTime

Timestamp

Optional. Input only. Immutable. The time after which new Live API sessions using the token resulting from this request will be rejected.

If not set this defaults to 60 seconds in the future. If set, this value must be less than 20 hours in the future.

fieldMask

FieldMask

Optional. Input only. Immutable. If field_mask is empty, and bidiGenerateContentSetup is not present, then the effective BidiGenerateContentSetup message is taken from the Live API connection.

If field_mask is empty, and bidiGenerateContentSetup is present, then the effective BidiGenerateContentSetup message is taken entirely from bidiGenerateContentSetup in this request. The setup message from the Live API connection is ignored.

If field_mask is not empty, then the corresponding fields from bidiGenerateContentSetup will overwrite the fields from the setup message in the Live API connection.

Union field config . The method-specific configuration for the resulting token. config can be only one of the following:
bidiGenerateContentSetup

BidiGenerateContentSetup

Optional. Input only. Immutable. Configuration specific to BidiGenerateContent .

uses

int32

Optional. Input only. Immutable. The number of times the token can be used. If this value is zero then no limit is applied. Resuming a Live API session does not count as a use. If unspecified, the default is 1.

More information on common types

For more information on the commonly-used API resource types Blob , Content , FunctionCall , FunctionResponse , GenerationConfig , GroundingMetadata , ModalityTokenCount , and Tool , see Generating content .

,

The Live API is a stateful API that uses WebSockets . In this section, you'll find additional details regarding the WebSockets API.

Sessions

A WebSocket connection establishes a session between the client and the Gemini server. After a client initiates a new connection the session can exchange messages with the server to:

  • Send text, audio, or video to the Gemini server.
  • Receive audio, text, or function call requests from the Gemini server.

WebSocket connection

To start a session, connect to this websocket endpoint:

wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent

Session configuration

The initial message sent after establishing the WebSocket connection sets the session configuration, which includes the model, generation parameters, system instructions, and tools.

You cannot update the configuration while the connection is open. However, you can change the configuration parameters, except the model, when pausing and resuming via the session resumption mechanism .

See the following example configuration. Note that the name casing in SDKs may vary. You can look up the Python SDK configuration options here .


{
  "model": string,
  "generationConfig": {
    "candidateCount": integer,
    "maxOutputTokens": integer,
    "temperature": number,
    "topP": number,
    "topK": integer,
    "presencePenalty": number,
    "frequencyPenalty": number,
    "responseModalities": [string],
    "speechConfig": object,
    "mediaResolution": object,
    "translationConfig": object
  },
  "systemInstruction": string,
  "tools": [object]
}

For more information on the API field, see generationConfig .

বার্তা পাঠান

To exchange messages over the WebSocket connection, the client must send a JSON object over an open WebSocket connection. The JSON object must have exactly one of the fields from the following object set:


{
  "setup": BidiGenerateContentSetup,
  "clientContent": BidiGenerateContentClientContent,
  "realtimeInput": BidiGenerateContentRealtimeInput,
  "toolResponse": BidiGenerateContentToolResponse
}

Supported client messages

See the supported client messages in the following table:

বার্তা বর্ণনা
BidiGenerateContentSetup Session configuration to be sent in the first message
BidiGenerateContentClientContent Incremental content update of the current conversation delivered from the client
BidiGenerateContentRealtimeInput Real time audio, video, or text input
BidiGenerateContentToolResponse Response to a ToolCallMessage received from the server

Receive messages

To receive messages from Gemini, listen for the WebSocket 'message' event, and then parse the result according to the definition of the supported server messages.

See the following:

async with client.aio.live.connect(model='...', config=config) as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
        print(message)

Server messages may have a usageMetadata field but will otherwise include exactly one of the other fields from the BidiGenerateContentServerMessage message. (The messageType union is not expressed in JSON so the field will appear at the top-level of the message.)

Messages and events

ActivityEnd

এই প্রকারে কোনো ক্ষেত্র নেই।

Marks the end of user activity.

ActivityHandling

The different ways of handling user activity.

এনাম
ACTIVITY_HANDLING_UNSPECIFIED If unspecified, the default behavior is START_OF_ACTIVITY_INTERRUPTS .
START_OF_ACTIVITY_INTERRUPTS If true, start of activity will interrupt the model's response (also called "barge in"). The model's current response will be cut-off in the moment of the interruption. This is the default behavior.
NO_INTERRUPTION The model's response will not be interrupted.

ActivityStart

এই প্রকারে কোনো ক্ষেত্র নেই।

Marks the start of user activity.

AudioTranscriptionConfig

The audio transcription configuration.

ক্ষেত্র
languageCodes[]

string

Optional. BCP-47 language codes providing hints about the languages present in the audio. If omitted or empty, defaults to automatic language detection.

customVocabulary[]

string

Optional. A list of custom vocabulary phrases to bias the speech recognition model toward recognizing specific terms (product names, proper nouns, jargon).

wordTimestamp

bool

Optional. Configures word-level timestamp generation.

diarization

bool

Optional. Configures speaker diarization.

mode

Mode

Optional. Configures transcription mode. Supported values: VERBATIM , SMART . If unspecified, defaults to VERBATIM transcription. In SMART mode, the model performs disfluency removal (eliminating filler words, repetitions, and false starts), light grammatical cleanup, automatic formatting (paragraphs, bullet points, numbered lists), and minor user edits (inline self-corrections). Timestamps and diarization are incompatible with mode SMART .

মোড

Transcription mode.

এনাম
MODE_UNSPECIFIED Unspecified transcription mode.
VERBATIM Verbatim transcription mode.
SMART Smart transcription mode.

AutomaticActivityDetection

Configures automatic detection of activity.

ক্ষেত্র
disabled

bool

Optional. If enabled (the default), detected voice and text input count as activity. If disabled, the client must send activity signals.

startOfSpeechSensitivity

StartSensitivity

Optional. Determines how likely speech is to be detected.

prefixPaddingMs

int32

Optional. The required duration of detected speech before start-of-speech is committed. The lower this value, the more sensitive the start-of-speech detection is and shorter speech can be recognized. However, this also increases the probability of false positives.

endOfSpeechSensitivity

EndSensitivity

Optional. Determines how likely detected speech is ended.

silenceDurationMs

int32

Optional. The required duration of detected non-speech (eg silence) before end-of-speech is committed. The larger this value, the longer speech gaps can be without interrupting the user's activity but this will increase the model's latency.

BidiGenerateContentClientContent

Incremental update of the current conversation delivered from the client. All of the content here is unconditionally appended to the conversation history and used as part of the prompt to the model to generate content.

A message here will interrupt any current model generation.

ক্ষেত্র
turns[]

Content

Optional. The content appended to the current conversation with the model.

For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains conversation history and the latest request.

turnComplete

bool

Optional. If true, indicates that the server content generation should start with the currently accumulated prompt. Otherwise, the server awaits additional messages before starting generation.

BidiGenerateContentRealtimeInput

User input that is sent in real time.

The different modalities (audio, video and text) are handled as concurrent streams. The ordering across these streams is not guaranteed.

This is different from BidiGenerateContentClientContent in a few ways:

  • Can be sent continuously without interruption to model generation.
  • If there is a need to mix data interleaved across the BidiGenerateContentClientContent and the BidiGenerateContentRealtimeInput , the server attempts to optimize for best response, but there are no guarantees.
  • End of turn is not explicitly specified, but is rather derived from user activity (for example, end of speech).
  • Even before the end of turn, the data is processed incrementally to optimize for a fast start of the response from the model.
ক্ষেত্র
mediaChunks[]

Blob

Optional. Inlined bytes data for media input. Multiple mediaChunks are not supported, all but the first will be ignored.

DEPRECATED: Use one of audio , video , or text instead.

audio

Blob

Optional. These form the realtime audio input stream.

video

Blob

Optional. These form the realtime video input stream.

activityStart

ActivityStart

Optional. Marks the start of user activity. This can only be sent if automatic (ie server-side) activity detection is disabled.

activityEnd

ActivityEnd

Optional. Marks the end of user activity. This can only be sent if automatic (ie server-side) activity detection is disabled.

mediaResolution

MediaResolution

Optional. The media resolution to use. If not specified, setup.generationConfig.mediaResolution is used or a default if the setup is not provided.

audioStreamEnd

bool

Optional. Indicates that the audio stream has ended, eg because the microphone was turned off.

This should only be sent when automatic activity detection is enabled (which is the default).

The client can reopen the stream by sending an audio message.

text

string

Optional. These form the realtime text input stream.

BidiGenerateContentServerContent

Incremental server update generated by the model in response to client messages.

Content is generated as quickly as possible, and not in real time. Clients may choose to buffer and play it out in real time.

ক্ষেত্র
generationComplete

bool

Output only. If true, indicates that the model is done generating.

When model is interrupted while generating there will be no 'generation_complete' message in interrupted turn, it will go through 'interrupted > turn_complete'.

When model assumes realtime playback there will be delay between generation_complete and turn_complete that is caused by model waiting for playback to finish.

turnComplete

bool

Output only. If true, indicates that the model has completed its turn. Generation will only start in response to additional client messages. Note when playback status reporting is enabled, this is emitted only when the playback status indicates that the playback is done. Future playback status of the same generation will be ignored.

interrupted

bool

Output only. If true, indicates that a client message has interrupted current model generation. If the client is playing out the content in real time, this is a good signal to stop and empty the current playback queue.

groundingMetadata

GroundingMetadata

Output only. Grounding metadata for the generated content.

inputTranscription

BidiGenerateContentTranscription

Output only. Input audio transcription. The transcription is sent independently of the other server messages and there is no guaranteed ordering.

interimInputTranscription

BidiGenerateContentTranscription

Output only. Low latency transcription updated while the user is speaking. This field is subject to frequent updates.

outputTranscription

BidiGenerateContentTranscription

Output only. Output audio transcription. These transcriptions are part of the Generation output of the server. The last output transcription of this turn is sent before either generationComplete or interrupted , which in turn are followed by turnComplete . There is no guaranteed exact ordering between transcriptions and other modelTurn output but the server tries to send the transcripts close to the corresponding audio output.

urlContextMetadata

UrlContextMetadata

waitingForInput

bool

Output only. If true, indicates that the model is not generating content because it is waiting for more input from the user, eg because it expects the user to continue talking.

speechState
(deprecated)

SpeechState

Output only. DEPRECATED: Use VoiceActivity instead.

Indicates the current state of speech detection on realtimeInput.audio . Not set or zero if the state is unchanged.

interactionStatus

InteractionStatus

Output only. The current activity status of the live session. Always sent alongside turnComplete .

modelTurn

Content

Output only. The content that the model has generated as part of the current conversation with the user.

BidiGenerateContentServerMessage

Response message for the BidiGenerateContent call.

ক্ষেত্র
usageMetadata

UsageMetadata

Output only. Usage metadata about the response(s).

Union field messageType . The type of the message. messageType can be only one of the following:
setupComplete

BidiGenerateContentSetupComplete

Output only. Sent in response to a BidiGenerateContentSetup message from the client when setup is complete.

serverContent

BidiGenerateContentServerContent

Output only. Content generated by the model in response to client messages.

toolCall

BidiGenerateContentToolCall

Output only. Request for the client to execute the functionCalls and return the responses with the matching id s.

toolCallCancellation

BidiGenerateContentToolCallCancellation

Output only. Notification for the client that a previously issued ToolCallMessage with the specified id s should be cancelled.

goAway

GoAway

Output only. A notice that the server will soon disconnect.

sessionResumptionUpdate

SessionResumptionUpdate

Output only. Update of the session resumption state.

BidiGenerateContentSetup

Message to be sent in the first (and only in the first) BidiGenerateContentClientMessage . Contains configuration that will apply for the duration of the streaming RPC.

Clients should wait for a BidiGenerateContentSetupComplete message before sending any additional messages.

ক্ষেত্র
model

string

Required. The model's resource name. This serves as an ID for the Model to use.

Format: models/{model}

generationConfig

GenerationConfig

Optional. Generation config.

The following fields are not supported:

  • responseLogprobs
  • responseMimeType
  • logprobs
  • responseSchema
  • responseJsonSchema
  • stopSequence
  • skipResponseCache
  • routingConfig
  • audioTimestamp
systemInstruction

Content

Optional. The user provided system instructions for the model.

Note: Only text should be used in parts and content in each part will be in a separate paragraph.

tools[]

Tool

Optional. A list of Tools the model may use to generate the next response.

A Tool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model.

realtimeInputConfig

RealtimeInputConfig

Optional. Configures the handling of realtime input.

sessionResumption

SessionResumptionConfig

Optional. Configures session resumption mechanism.

If included, the server will send SessionResumptionUpdate messages.

contextWindowCompression

ContextWindowCompressionConfig

Optional. Configures a context window compression mechanism.

If included, the server will automatically reduce the size of the context when it exceeds the configured length.

inputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of voice input. The transcription aligns with the input audio language, if configured.

outputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of the model's audio output. The transcription aligns with the language code specified for the output audio, if configured.

proactivity

ProactivityConfig

Optional. Configures the proactivity of the model.

This allows the model to respond proactively to the input and to ignore irrelevant input.

historyConfig

HistoryConfig

Optional. Configures the exchange of history between the client and the server.

BidiGenerateContentSetupComplete

এই প্রকারে কোনো ক্ষেত্র নেই।

Sent in response to a BidiGenerateContentSetup message from the client.

BidiGenerateContentToolCall

Request for the client to execute the functionCalls and return the responses with the matching id s.

ক্ষেত্র
functionCalls[]

FunctionCall

Output only. The function call to be executed.

BidiGenerateContentToolCallCancellation

Notification for the client that a previously issued ToolCallMessage with the specified id s should not have been executed and should be cancelled. If there were side-effects to those tool calls, clients may attempt to undo the tool calls. This message occurs only in cases where the clients interrupt server turns.

ক্ষেত্র
ids[]

string

Output only. The ids of the tool calls to be cancelled.

BidiGenerateContentToolResponse

Client generated response to a ToolCall received from the server. Individual FunctionResponse objects are matched to the respective FunctionCall objects by the id field.

Note that in the unary and server-streaming GenerateContent APIs function calling happens by exchanging the Content parts, while in the bidi GenerateContent APIs function calling happens over these dedicated set of messages.

ক্ষেত্র
functionResponses[]

FunctionResponse

Optional. The response to the function calls.

BidiGenerateContentTranscription

Transcription of audio (input or output).

ক্ষেত্র
text

string

Transcription text.

languageCode

string

The BCP-47 language code of the transcription.

ContextWindowCompressionConfig

Enables context window compression — a mechanism for managing the model's context window so that it does not exceed a given length.

ক্ষেত্র
Union field compressionMechanism . The context window compression mechanism used. compressionMechanism can be only one of the following:
slidingWindow

SlidingWindow

A sliding-window mechanism.

triggerTokens

int64

The number of tokens (before running a turn) required to trigger a context window compression.

This can be used to balance quality against latency as shorter context windows may result in faster model responses. However, any compression operation will cause a temporary latency increase, so they should not be triggered frequently.

If not set, the default is 80% of the model's context window limit. This leaves 20% for the next user request/model response.

EndSensitivity

Determines how end of speech is detected.

এনাম
END_SENSITIVITY_UNSPECIFIED The default is END_SENSITIVITY_HIGH.
END_SENSITIVITY_HIGH Automatic detection ends speech more often.
END_SENSITIVITY_LOW Automatic detection ends speech less often.

GoAway

A notice that the server will soon disconnect.

ক্ষেত্র
timeLeft

Duration

The remaining time before the connection will be terminated as ABORTED.

This duration will never be less than a model-specific minimum, which will be specified together with the rate limits for the model.

HistoryConfig

History configuration.

This message is included in the session configuration as BidiGenerateContentSetup.historyConfig . Configures the exchange of history messages.

ক্ষেত্র
initialHistoryInClientContent

bool

Optional. If true, after sending setupComplete , the server will wait and at first process clientContent messages until turnComplete is true . This initial history will not trigger a model call and may end with role MODEL . After turnComplete is true , the client can start the realtime conversation via realtimeInput .

ProactivityConfig

Config for proactivity features.

ক্ষেত্র
proactiveAudio

bool

Optional. If enabled, the model can reject responding to the last prompt. For example, this allows the model to ignore out of context speech or to stay silent if the user did not make a request, yet.

RealtimeInputConfig

Configures the realtime input behavior in BidiGenerateContent .

ক্ষেত্র
automaticActivityDetection

AutomaticActivityDetection

Optional. If not set, automatic activity detection is enabled by default. If automatic voice detection is disabled, the client must send activity signals.

activityHandling

ActivityHandling

Optional. Defines what effect activity has.

turnCoverage

TurnCoverage

Optional. Defines which input is included in the user's turn.

SessionResumptionConfig

Session resumption configuration.

This message is included in the session configuration as BidiGenerateContentSetup.sessionResumption . If configured, the server will send SessionResumptionUpdate messages.

ক্ষেত্র
handle

string

The handle of a previous session. If not present then a new session is created.

Session handles come from SessionResumptionUpdate.token values in previous connections.

SessionResumptionUpdate

Update of the session resumption state.

Only sent if BidiGenerateContentSetup.sessionResumption was set.

ক্ষেত্র
newHandle

string

New handle that represents a state that can be resumed. Empty if resumable =false.

resumable

bool

True if the current session can be resumed at this point.

Resumption is not possible at some points in the session. For example, when the model is executing function calls or generating. Resuming the session (using a previous session token) in such a state will result in some data loss. In these cases, newHandle will be empty and resumable will be false.

SlidingWindow

The SlidingWindow method operates by discarding content at the beginning of the context window. The resulting context will always begin at the start of a USER role turn. System instructions and any BidiGenerateContentSetup.prefixTurns will always remain at the beginning of the result.

ক্ষেত্র
targetTokens

int64

The target number of tokens to keep. The default value is trigger_tokens/2.

Discarding parts of the context window causes a temporary latency increase so this value should be calibrated to avoid frequent compression operations.

StartSensitivity

Determines how start of speech is detected.

এনাম
START_SENSITIVITY_UNSPECIFIED The default is START_SENSITIVITY_HIGH.
START_SENSITIVITY_HIGH Automatic detection will detect the start of speech more often.
START_SENSITIVITY_LOW Automatic detection will detect the start of speech less often.

TurnCoverage

Options about which input is included in the user's turn.

এনাম
TURN_COVERAGE_UNSPECIFIED If unspecified, a default behavior is selected based on the model. Eg, for Gemini 2.5, the default is TURN_INCLUDES_ONLY_ACTIVITY , while for Gemini 3.1 and onwards, it's TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO .
TURN_INCLUDES_ONLY_ACTIVITY Includes activity since the last turn, excluding inactivity (eg silence on the audio stream).
TURN_INCLUDES_ALL_INPUT Includes all realtime input since the last turn, including inactivity (eg silence on the audio stream).
TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO Includes audio activity and all video since the last turn. With automatic activity detection, audio activity means speech and excludes silence.

TranslationConfig

Config for translation features.

ক্ষেত্র
targetLanguageCode

string

Required. The target language for translation. Supported values are BCP-47 language codes (eg "en", "es", "fr").

echoTargetLanguage

bool

Optional. If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language.

UrlContextMetadata

Metadata related to url context retrieval tool.

ক্ষেত্র
urlMetadata[]

UrlMetadata

List of url context.

UsageMetadata

Usage metadata about response(s).

ক্ষেত্র
promptTokenCount

int32

Output only. Number of tokens in the prompt. When cachedContent is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content.

cachedContentTokenCount

int32

Number of tokens in the cached part of the prompt (the cached content)

responseTokenCount

int32

Output only. Total number of tokens across all the generated response candidates.

toolUsePromptTokenCount

int32

Output only. Number of tokens present in tool-use prompt(s).

thoughtsTokenCount

int32

Output only. Number of tokens of thoughts for thinking models.

totalTokenCount

int32

Output only. Total token count for the generation request (prompt + response candidates).

promptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed in the request input.

cacheTokensDetails[]

ModalityTokenCount

Output only. List of modalities of the cached content in the request input.

responseTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were returned in the response.

toolUsePromptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed for tool-use request inputs.

Ephemeral authentication tokens

Ephemeral authentication tokens can be obtained by calling AuthTokenService.CreateToken and then used with GenerativeService.BidiGenerateContentConstrained , either by passing the token in an access_token query parameter, or in an HTTP Authorization header with " Token " prefixed to it.

CreateAuthTokenRequest

Create an ephemeral authentication token.

ক্ষেত্র
authToken

AuthToken

Required. The token to create.

AuthToken

A request to create an ephemeral authentication token.

ক্ষেত্র
name

string

Output only. Identifier. The token itself.

expireTime

Timestamp

Optional. Input only. Immutable. An optional time after which, when using the resulting token, messages in BidiGenerateContent sessions will be rejected. (Gemini may preemptively close the session after this time.)

If not set then this defaults to 30 minutes in the future. If set, this value must be less than 20 hours in the future.

newSessionExpireTime

Timestamp

Optional. Input only. Immutable. The time after which new Live API sessions using the token resulting from this request will be rejected.

If not set this defaults to 60 seconds in the future. If set, this value must be less than 20 hours in the future.

fieldMask

FieldMask

Optional. Input only. Immutable. If field_mask is empty, and bidiGenerateContentSetup is not present, then the effective BidiGenerateContentSetup message is taken from the Live API connection.

If field_mask is empty, and bidiGenerateContentSetup is present, then the effective BidiGenerateContentSetup message is taken entirely from bidiGenerateContentSetup in this request. The setup message from the Live API connection is ignored.

If field_mask is not empty, then the corresponding fields from bidiGenerateContentSetup will overwrite the fields from the setup message in the Live API connection.

Union field config . The method-specific configuration for the resulting token. config can be only one of the following:
bidiGenerateContentSetup

BidiGenerateContentSetup

Optional. Input only. Immutable. Configuration specific to BidiGenerateContent .

uses

int32

Optional. Input only. Immutable. The number of times the token can be used. If this value is zero then no limit is applied. Resuming a Live API session does not count as a use. If unspecified, the default is 1.

More information on common types

For more information on the commonly-used API resource types Blob , Content , FunctionCall , FunctionResponse , GenerationConfig , GroundingMetadata , ModalityTokenCount , and Tool , see Generating content .

,

The Live API is a stateful API that uses WebSockets . In this section, you'll find additional details regarding the WebSockets API.

Sessions

A WebSocket connection establishes a session between the client and the Gemini server. After a client initiates a new connection the session can exchange messages with the server to:

  • Send text, audio, or video to the Gemini server.
  • Receive audio, text, or function call requests from the Gemini server.

WebSocket connection

To start a session, connect to this websocket endpoint:

wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent

Session configuration

The initial message sent after establishing the WebSocket connection sets the session configuration, which includes the model, generation parameters, system instructions, and tools.

You cannot update the configuration while the connection is open. However, you can change the configuration parameters, except the model, when pausing and resuming via the session resumption mechanism .

See the following example configuration. Note that the name casing in SDKs may vary. You can look up the Python SDK configuration options here .


{
  "model": string,
  "generationConfig": {
    "candidateCount": integer,
    "maxOutputTokens": integer,
    "temperature": number,
    "topP": number,
    "topK": integer,
    "presencePenalty": number,
    "frequencyPenalty": number,
    "responseModalities": [string],
    "speechConfig": object,
    "mediaResolution": object,
    "translationConfig": object
  },
  "systemInstruction": string,
  "tools": [object]
}

For more information on the API field, see generationConfig .

বার্তা পাঠান

To exchange messages over the WebSocket connection, the client must send a JSON object over an open WebSocket connection. The JSON object must have exactly one of the fields from the following object set:


{
  "setup": BidiGenerateContentSetup,
  "clientContent": BidiGenerateContentClientContent,
  "realtimeInput": BidiGenerateContentRealtimeInput,
  "toolResponse": BidiGenerateContentToolResponse
}

Supported client messages

See the supported client messages in the following table:

বার্তা বর্ণনা
BidiGenerateContentSetup Session configuration to be sent in the first message
BidiGenerateContentClientContent Incremental content update of the current conversation delivered from the client
BidiGenerateContentRealtimeInput Real time audio, video, or text input
BidiGenerateContentToolResponse Response to a ToolCallMessage received from the server

Receive messages

To receive messages from Gemini, listen for the WebSocket 'message' event, and then parse the result according to the definition of the supported server messages.

See the following:

async with client.aio.live.connect(model='...', config=config) as session:
    await session.send(input='Hello world!', end_of_turn=True)
    async for message in session.receive():
        print(message)

Server messages may have a usageMetadata field but will otherwise include exactly one of the other fields from the BidiGenerateContentServerMessage message. (The messageType union is not expressed in JSON so the field will appear at the top-level of the message.)

Messages and events

ActivityEnd

এই প্রকারে কোনো ক্ষেত্র নেই।

Marks the end of user activity.

ActivityHandling

The different ways of handling user activity.

এনাম
ACTIVITY_HANDLING_UNSPECIFIED If unspecified, the default behavior is START_OF_ACTIVITY_INTERRUPTS .
START_OF_ACTIVITY_INTERRUPTS If true, start of activity will interrupt the model's response (also called "barge in"). The model's current response will be cut-off in the moment of the interruption. This is the default behavior.
NO_INTERRUPTION The model's response will not be interrupted.

ActivityStart

এই প্রকারে কোনো ক্ষেত্র নেই।

Marks the start of user activity.

AudioTranscriptionConfig

The audio transcription configuration.

ক্ষেত্র
languageCodes[]

string

Optional. BCP-47 language codes providing hints about the languages present in the audio. If omitted or empty, defaults to automatic language detection.

customVocabulary[]

string

Optional. A list of custom vocabulary phrases to bias the speech recognition model toward recognizing specific terms (product names, proper nouns, jargon).

wordTimestamp

bool

Optional. Configures word-level timestamp generation.

diarization

bool

Optional. Configures speaker diarization.

mode

Mode

Optional. Configures transcription mode. Supported values: VERBATIM , SMART . If unspecified, defaults to VERBATIM transcription. In SMART mode, the model performs disfluency removal (eliminating filler words, repetitions, and false starts), light grammatical cleanup, automatic formatting (paragraphs, bullet points, numbered lists), and minor user edits (inline self-corrections). Timestamps and diarization are incompatible with mode SMART .

মোড

Transcription mode.

এনাম
MODE_UNSPECIFIED Unspecified transcription mode.
VERBATIM Verbatim transcription mode.
SMART Smart transcription mode.

AutomaticActivityDetection

Configures automatic detection of activity.

ক্ষেত্র
disabled

bool

Optional. If enabled (the default), detected voice and text input count as activity. If disabled, the client must send activity signals.

startOfSpeechSensitivity

StartSensitivity

Optional. Determines how likely speech is to be detected.

prefixPaddingMs

int32

Optional. The required duration of detected speech before start-of-speech is committed. The lower this value, the more sensitive the start-of-speech detection is and shorter speech can be recognized. However, this also increases the probability of false positives.

endOfSpeechSensitivity

EndSensitivity

Optional. Determines how likely detected speech is ended.

silenceDurationMs

int32

Optional. The required duration of detected non-speech (eg silence) before end-of-speech is committed. The larger this value, the longer speech gaps can be without interrupting the user's activity but this will increase the model's latency.

BidiGenerateContentClientContent

Incremental update of the current conversation delivered from the client. All of the content here is unconditionally appended to the conversation history and used as part of the prompt to the model to generate content.

A message here will interrupt any current model generation.

ক্ষেত্র
turns[]

Content

Optional. The content appended to the current conversation with the model.

For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains conversation history and the latest request.

turnComplete

bool

Optional. If true, indicates that the server content generation should start with the currently accumulated prompt. Otherwise, the server awaits additional messages before starting generation.

BidiGenerateContentRealtimeInput

User input that is sent in real time.

The different modalities (audio, video and text) are handled as concurrent streams. The ordering across these streams is not guaranteed.

This is different from BidiGenerateContentClientContent in a few ways:

  • Can be sent continuously without interruption to model generation.
  • If there is a need to mix data interleaved across the BidiGenerateContentClientContent and the BidiGenerateContentRealtimeInput , the server attempts to optimize for best response, but there are no guarantees.
  • End of turn is not explicitly specified, but is rather derived from user activity (for example, end of speech).
  • Even before the end of turn, the data is processed incrementally to optimize for a fast start of the response from the model.
ক্ষেত্র
mediaChunks[]

Blob

Optional. Inlined bytes data for media input. Multiple mediaChunks are not supported, all but the first will be ignored.

DEPRECATED: Use one of audio , video , or text instead.

audio

Blob

Optional. These form the realtime audio input stream.

video

Blob

Optional. These form the realtime video input stream.

activityStart

ActivityStart

Optional. Marks the start of user activity. This can only be sent if automatic (ie server-side) activity detection is disabled.

activityEnd

ActivityEnd

Optional. Marks the end of user activity. This can only be sent if automatic (ie server-side) activity detection is disabled.

mediaResolution

MediaResolution

Optional. The media resolution to use. If not specified, setup.generationConfig.mediaResolution is used or a default if the setup is not provided.

audioStreamEnd

bool

Optional. Indicates that the audio stream has ended, eg because the microphone was turned off.

This should only be sent when automatic activity detection is enabled (which is the default).

The client can reopen the stream by sending an audio message.

text

string

Optional. These form the realtime text input stream.

BidiGenerateContentServerContent

Incremental server update generated by the model in response to client messages.

Content is generated as quickly as possible, and not in real time. Clients may choose to buffer and play it out in real time.

ক্ষেত্র
generationComplete

bool

Output only. If true, indicates that the model is done generating.

When model is interrupted while generating there will be no 'generation_complete' message in interrupted turn, it will go through 'interrupted > turn_complete'.

When model assumes realtime playback there will be delay between generation_complete and turn_complete that is caused by model waiting for playback to finish.

turnComplete

bool

Output only. If true, indicates that the model has completed its turn. Generation will only start in response to additional client messages. Note when playback status reporting is enabled, this is emitted only when the playback status indicates that the playback is done. Future playback status of the same generation will be ignored.

interrupted

bool

Output only. If true, indicates that a client message has interrupted current model generation. If the client is playing out the content in real time, this is a good signal to stop and empty the current playback queue.

groundingMetadata

GroundingMetadata

Output only. Grounding metadata for the generated content.

inputTranscription

BidiGenerateContentTranscription

Output only. Input audio transcription. The transcription is sent independently of the other server messages and there is no guaranteed ordering.

interimInputTranscription

BidiGenerateContentTranscription

Output only. Low latency transcription updated while the user is speaking. This field is subject to frequent updates.

outputTranscription

BidiGenerateContentTranscription

Output only. Output audio transcription. These transcriptions are part of the Generation output of the server. The last output transcription of this turn is sent before either generationComplete or interrupted , which in turn are followed by turnComplete . There is no guaranteed exact ordering between transcriptions and other modelTurn output but the server tries to send the transcripts close to the corresponding audio output.

urlContextMetadata

UrlContextMetadata

waitingForInput

bool

Output only. If true, indicates that the model is not generating content because it is waiting for more input from the user, eg because it expects the user to continue talking.

speechState
(deprecated)

SpeechState

Output only. DEPRECATED: Use VoiceActivity instead.

Indicates the current state of speech detection on realtimeInput.audio . Not set or zero if the state is unchanged.

interactionStatus

InteractionStatus

Output only. The current activity status of the live session. Always sent alongside turnComplete .

modelTurn

Content

Output only. The content that the model has generated as part of the current conversation with the user.

BidiGenerateContentServerMessage

Response message for the BidiGenerateContent call.

ক্ষেত্র
usageMetadata

UsageMetadata

Output only. Usage metadata about the response(s).

Union field messageType . The type of the message. messageType can be only one of the following:
setupComplete

BidiGenerateContentSetupComplete

Output only. Sent in response to a BidiGenerateContentSetup message from the client when setup is complete.

serverContent

BidiGenerateContentServerContent

Output only. Content generated by the model in response to client messages.

toolCall

BidiGenerateContentToolCall

Output only. Request for the client to execute the functionCalls and return the responses with the matching id s.

toolCallCancellation

BidiGenerateContentToolCallCancellation

Output only. Notification for the client that a previously issued ToolCallMessage with the specified id s should be cancelled.

goAway

GoAway

Output only. A notice that the server will soon disconnect.

sessionResumptionUpdate

SessionResumptionUpdate

Output only. Update of the session resumption state.

BidiGenerateContentSetup

Message to be sent in the first (and only in the first) BidiGenerateContentClientMessage . Contains configuration that will apply for the duration of the streaming RPC.

Clients should wait for a BidiGenerateContentSetupComplete message before sending any additional messages.

ক্ষেত্র
model

string

Required. The model's resource name. This serves as an ID for the Model to use.

Format: models/{model}

generationConfig

GenerationConfig

Optional. Generation config.

The following fields are not supported:

  • responseLogprobs
  • responseMimeType
  • logprobs
  • responseSchema
  • responseJsonSchema
  • stopSequence
  • skipResponseCache
  • routingConfig
  • audioTimestamp
systemInstruction

Content

Optional. The user provided system instructions for the model.

Note: Only text should be used in parts and content in each part will be in a separate paragraph.

tools[]

Tool

Optional. A list of Tools the model may use to generate the next response.

A Tool is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model.

realtimeInputConfig

RealtimeInputConfig

Optional. Configures the handling of realtime input.

sessionResumption

SessionResumptionConfig

Optional. Configures session resumption mechanism.

If included, the server will send SessionResumptionUpdate messages.

contextWindowCompression

ContextWindowCompressionConfig

Optional. Configures a context window compression mechanism.

If included, the server will automatically reduce the size of the context when it exceeds the configured length.

inputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of voice input. The transcription aligns with the input audio language, if configured.

outputAudioTranscription

AudioTranscriptionConfig

Optional. If set, enables transcription of the model's audio output. The transcription aligns with the language code specified for the output audio, if configured.

proactivity

ProactivityConfig

Optional. Configures the proactivity of the model.

This allows the model to respond proactively to the input and to ignore irrelevant input.

historyConfig

HistoryConfig

Optional. Configures the exchange of history between the client and the server.

BidiGenerateContentSetupComplete

এই প্রকারে কোনো ক্ষেত্র নেই।

Sent in response to a BidiGenerateContentSetup message from the client.

BidiGenerateContentToolCall

Request for the client to execute the functionCalls and return the responses with the matching id s.

ক্ষেত্র
functionCalls[]

FunctionCall

Output only. The function call to be executed.

BidiGenerateContentToolCallCancellation

Notification for the client that a previously issued ToolCallMessage with the specified id s should not have been executed and should be cancelled. If there were side-effects to those tool calls, clients may attempt to undo the tool calls. This message occurs only in cases where the clients interrupt server turns.

ক্ষেত্র
ids[]

string

Output only. The ids of the tool calls to be cancelled.

BidiGenerateContentToolResponse

Client generated response to a ToolCall received from the server. Individual FunctionResponse objects are matched to the respective FunctionCall objects by the id field.

Note that in the unary and server-streaming GenerateContent APIs function calling happens by exchanging the Content parts, while in the bidi GenerateContent APIs function calling happens over these dedicated set of messages.

ক্ষেত্র
functionResponses[]

FunctionResponse

Optional. The response to the function calls.

BidiGenerateContentTranscription

Transcription of audio (input or output).

ক্ষেত্র
text

string

Transcription text.

languageCode

string

The BCP-47 language code of the transcription.

ContextWindowCompressionConfig

Enables context window compression — a mechanism for managing the model's context window so that it does not exceed a given length.

ক্ষেত্র
Union field compressionMechanism . The context window compression mechanism used. compressionMechanism can be only one of the following:
slidingWindow

SlidingWindow

A sliding-window mechanism.

triggerTokens

int64

The number of tokens (before running a turn) required to trigger a context window compression.

This can be used to balance quality against latency as shorter context windows may result in faster model responses. However, any compression operation will cause a temporary latency increase, so they should not be triggered frequently.

If not set, the default is 80% of the model's context window limit. This leaves 20% for the next user request/model response.

EndSensitivity

Determines how end of speech is detected.

এনাম
END_SENSITIVITY_UNSPECIFIED The default is END_SENSITIVITY_HIGH.
END_SENSITIVITY_HIGH Automatic detection ends speech more often.
END_SENSITIVITY_LOW Automatic detection ends speech less often.

GoAway

A notice that the server will soon disconnect.

ক্ষেত্র
timeLeft

Duration

The remaining time before the connection will be terminated as ABORTED.

This duration will never be less than a model-specific minimum, which will be specified together with the rate limits for the model.

HistoryConfig

History configuration.

This message is included in the session configuration as BidiGenerateContentSetup.historyConfig . Configures the exchange of history messages.

ক্ষেত্র
initialHistoryInClientContent

bool

Optional. If true, after sending setupComplete , the server will wait and at first process clientContent messages until turnComplete is true . This initial history will not trigger a model call and may end with role MODEL . After turnComplete is true , the client can start the realtime conversation via realtimeInput .

ProactivityConfig

Config for proactivity features.

ক্ষেত্র
proactiveAudio

bool

Optional. If enabled, the model can reject responding to the last prompt. For example, this allows the model to ignore out of context speech or to stay silent if the user did not make a request, yet.

RealtimeInputConfig

Configures the realtime input behavior in BidiGenerateContent .

ক্ষেত্র
automaticActivityDetection

AutomaticActivityDetection

Optional. If not set, automatic activity detection is enabled by default. If automatic voice detection is disabled, the client must send activity signals.

activityHandling

ActivityHandling

Optional. Defines what effect activity has.

turnCoverage

TurnCoverage

Optional. Defines which input is included in the user's turn.

SessionResumptionConfig

Session resumption configuration.

This message is included in the session configuration as BidiGenerateContentSetup.sessionResumption . If configured, the server will send SessionResumptionUpdate messages.

ক্ষেত্র
handle

string

The handle of a previous session. If not present then a new session is created.

Session handles come from SessionResumptionUpdate.token values in previous connections.

SessionResumptionUpdate

Update of the session resumption state.

Only sent if BidiGenerateContentSetup.sessionResumption was set.

ক্ষেত্র
newHandle

string

New handle that represents a state that can be resumed. Empty if resumable =false.

resumable

bool

True if the current session can be resumed at this point.

Resumption is not possible at some points in the session. For example, when the model is executing function calls or generating. Resuming the session (using a previous session token) in such a state will result in some data loss. In these cases, newHandle will be empty and resumable will be false.

SlidingWindow

The SlidingWindow method operates by discarding content at the beginning of the context window. The resulting context will always begin at the start of a USER role turn. System instructions and any BidiGenerateContentSetup.prefixTurns will always remain at the beginning of the result.

ক্ষেত্র
targetTokens

int64

The target number of tokens to keep. The default value is trigger_tokens/2.

Discarding parts of the context window causes a temporary latency increase so this value should be calibrated to avoid frequent compression operations.

StartSensitivity

Determines how start of speech is detected.

এনাম
START_SENSITIVITY_UNSPECIFIED The default is START_SENSITIVITY_HIGH.
START_SENSITIVITY_HIGH Automatic detection will detect the start of speech more often.
START_SENSITIVITY_LOW Automatic detection will detect the start of speech less often.

TurnCoverage

Options about which input is included in the user's turn.

এনাম
TURN_COVERAGE_UNSPECIFIED If unspecified, a default behavior is selected based on the model. Eg, for Gemini 2.5, the default is TURN_INCLUDES_ONLY_ACTIVITY , while for Gemini 3.1 and onwards, it's TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO .
TURN_INCLUDES_ONLY_ACTIVITY Includes activity since the last turn, excluding inactivity (eg silence on the audio stream).
TURN_INCLUDES_ALL_INPUT Includes all realtime input since the last turn, including inactivity (eg silence on the audio stream).
TURN_INCLUDES_AUDIO_ACTIVITY_AND_ALL_VIDEO Includes audio activity and all video since the last turn. With automatic activity detection, audio activity means speech and excludes silence.

TranslationConfig

Config for translation features.

ক্ষেত্র
targetLanguageCode

string

Required. The target language for translation. Supported values are BCP-47 language codes (eg "en", "es", "fr").

echoTargetLanguage

bool

Optional. If true, the model will generate audio when the target language is spoken, essentially it will parrot the input. If false, we will not produce audio for the target language.

UrlContextMetadata

Metadata related to url context retrieval tool.

ক্ষেত্র
urlMetadata[]

UrlMetadata

List of url context.

UsageMetadata

Usage metadata about response(s).

ক্ষেত্র
promptTokenCount

int32

Output only. Number of tokens in the prompt. When cachedContent is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content.

cachedContentTokenCount

int32

Number of tokens in the cached part of the prompt (the cached content)

responseTokenCount

int32

Output only. Total number of tokens across all the generated response candidates.

toolUsePromptTokenCount

int32

Output only. Number of tokens present in tool-use prompt(s).

thoughtsTokenCount

int32

Output only. Number of tokens of thoughts for thinking models.

totalTokenCount

int32

Output only. Total token count for the generation request (prompt + response candidates).

promptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed in the request input.

cacheTokensDetails[]

ModalityTokenCount

Output only. List of modalities of the cached content in the request input.

responseTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were returned in the response.

toolUsePromptTokensDetails[]

ModalityTokenCount

Output only. List of modalities that were processed for tool-use request inputs.

Ephemeral authentication tokens

Ephemeral authentication tokens can be obtained by calling AuthTokenService.CreateToken and then used with GenerativeService.BidiGenerateContentConstrained , either by passing the token in an access_token query parameter, or in an HTTP Authorization header with " Token " prefixed to it.

CreateAuthTokenRequest

Create an ephemeral authentication token.

ক্ষেত্র
authToken

AuthToken

Required. The token to create.

AuthToken

A request to create an ephemeral authentication token.

ক্ষেত্র
name

string

Output only. Identifier. The token itself.

expireTime

Timestamp

Optional. Input only. Immutable. An optional time after which, when using the resulting token, messages in BidiGenerateContent sessions will be rejected. (Gemini may preemptively close the session after this time.)

If not set then this defaults to 30 minutes in the future. If set, this value must be less than 20 hours in the future.

newSessionExpireTime

Timestamp

Optional. Input only. Immutable. The time after which new Live API sessions using the token resulting from this request will be rejected.

If not set this defaults to 60 seconds in the future. If set, this value must be less than 20 hours in the future.

fieldMask

FieldMask

Optional. Input only. Immutable. If field_mask is empty, and bidiGenerateContentSetup is not present, then the effective BidiGenerateContentSetup message is taken from the Live API connection.

If field_mask is empty, and bidiGenerateContentSetup is present, then the effective BidiGenerateContentSetup message is taken entirely from bidiGenerateContentSetup in this request. The setup message from the Live API connection is ignored.

If field_mask is not empty, then the corresponding fields from bidiGenerateContentSetup will overwrite the fields from the setup message in the Live API connection.

Union field config . The method-specific configuration for the resulting token. config can be only one of the following:
bidiGenerateContentSetup

BidiGenerateContentSetup

Optional. Input only. Immutable. Configuration specific to BidiGenerateContent .

uses

int32

Optional. Input only. Immutable. The number of times the token can be used. If this value is zero then no limit is applied. Resuming a Live API session does not count as a use. If unspecified, the default is 1.

More information on common types

For more information on the commonly-used API resource types Blob , Content , FunctionCall , FunctionResponse , GenerationConfig , GroundingMetadata , ModalityTokenCount , and Tool , see Generating content .