Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
The ChatSession class is used to make multiturn send message requests. You can instantiate this class by using the startChat method in the GenerativeModel class. The sendMessage method makes an async call to get the response of a chat message at at once. The sendMessageStream method makes an async call to stream the response of a chat message as it's being generated.
constchat=generativeModel.startChat();constresult1=awaitchat.sendMessage("How can I learn more about Node.js?");console.log('Response: ',JSON.stringify(result1.response));constresult2=awaitchat.sendMessage("What about python?");console.log('Response: ',JSON.stringify(result2.response));
constchat=generativeModel.startChat();constchatInput="How can I learn more about Node.js?";constresult=awaitchat.sendMessageStream(chatInput);forawait(constitemofresult.stream){console.log(item.candidates[0].content.parts[0].text);}constresponse=awaitresult.response;console.log('aggregated response: ',JSON.stringify(result.response));
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["# Class ChatSession (1.9.0)\n\nThe `ChatSession` class is used to make multiturn send message requests. You can instantiate this class by using the `startChat` method in the `GenerativeModel` class. The `sendMessage` method makes an async call to get the response of a chat message at at once. The `sendMessageStream` method makes an async call to stream the response of a chat message as it's being generated.\n\nPackage\n-------\n\n[@google-cloud/vertexai](../overview.html)\n\nConstructors\n------------\n\n### (constructor)(request, requestOptions)\n\n constructor(request: StartChatSessionRequest, requestOptions?: RequestOptions);\n\nConstructs a new instance of the `ChatSession` class\n\nProperties\n----------\n\n### requestOptions\n\n protected readonly requestOptions?: RequestOptions;\n\nMethods\n-------\n\n### getHistory()\n\n getHistory(): Promise\u003cContent[]\u003e;\n\n### sendMessage(request)\n\n sendMessage(request: string | Array\u003cstring | Part\u003e): Promise\u003cGenerateContentResult\u003e;\n\nMakes an async call to send chat message.\n\nThe response is returned in [GenerateContentResult.response](/vertex-ai/generative-ai/docs/reference/nodejs/latest/vertexai/generatecontentresult).\n\n**Example** \n\n\n const chat = generativeModel.startChat();\n const result1 = await chat.sendMessage(\"How can I learn more about Node.js?\");\n console.log('Response: ', JSON.stringify(result1.response));\n\n const result2 = await chat.sendMessage(\"What about python?\");\n console.log('Response: ', JSON.stringify(result2.response));\n\n### sendMessageStream(request)\n\n sendMessageStream(request: string | Array\u003cstring | Part\u003e): Promise\u003cStreamGenerateContentResult\u003e;\n\nMakes an async call to stream send message.\n\nThe response is streamed chunk by chunk in [StreamGenerateContentResult.stream](/vertex-ai/generative-ai/docs/reference/nodejs/latest/vertexai/streamgeneratecontentresult). The aggregated response is avaliable in [StreamGenerateContentResult.response](/vertex-ai/generative-ai/docs/reference/nodejs/latest/vertexai/streamgeneratecontentresult) after all chunks are returned.\n\n**Example** \n\n\n const chat = generativeModel.startChat();\n const chatInput = \"How can I learn more about Node.js?\";\n const result = await chat.sendMessageStream(chatInput);\n for await (const item of result.stream) {\n console.log(item.candidates[0].content.parts[0].text);\n }\n const response = await result.response;\n console.log('aggregated response: ', JSON.stringify(result.response));"]]