ChatSession class
Stay organized with collections
Save and categorize content based on your preferences.
ChatSession class that enables sending chat messages and stores history of sent and received messages so far.
Signature:
export declare class ChatSession
Constructors
Properties
Methods
ChatSession.(constructor)
Constructs a new instance of the ChatSession
class
Signature:
constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
Parameters
ChatSession.model
Signature:
model: string;
ChatSession.params
Signature:
params?: StartChatParams | undefined;
ChatSession.requestOptions
Signature:
requestOptions?: RequestOptions | undefined;
ChatSession.getHistory()
Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history.
Signature:
getHistory(): Promise<Content[]>;
Returns:
Promise<Content[]>
ChatSession.sendMessage()
Sends a chat message and receives a non-streaming GenerateContentResult
Signature:
sendMessage(request: string | Array<string | Part>): Promise<GenerateContentResult>;
Parameters
Parameter |
Type |
Description |
request |
string | Array<string | Part> |
|
Returns:
Promise<GenerateContentResult>
ChatSession.sendMessageStream()
Sends a chat message and receives the response as a GenerateContentStreamResult containing an iterable stream and a response promise.
Signature:
sendMessageStream(request: string | Array<string | Part>): Promise<GenerateContentStreamResult>;
Parameters
Parameter |
Type |
Description |
request |
string | Array<string | Part> |
|
Returns:
Promise<GenerateContentStreamResult>
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[null,null,["Last updated 2025-08-07 UTC."],[],[],null,["# ChatSession class that enables sending chat messages and stores history of sent and received messages so far.\n\n**Signature:** \n\n export declare class ChatSession \n\nConstructors\n------------\n\n| Constructor | Modifiers | Description |\n|------------------------------------------------------------------------------------------------------------------------|-----------|------------------------------------------------------|\n| [(constructor)(apiSettings, model, chromeAdapter, params, requestOptions)](./ai.chatsession.md#chatsessionconstructor) | | Constructs a new instance of the `ChatSession` class |\n\nProperties\n----------\n\n| Property | Modifiers | Type | Description |\n|-----------------------------------------------------------------|-----------|-----------------------------------------------------------------------------------|-------------|\n| [model](./ai.chatsession.md#chatsessionmodel) | | string | |\n| [params](./ai.chatsession.md#chatsessionparams) | | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \\| undefined | |\n| [requestOptions](./ai.chatsession.md#chatsessionrequestoptions) | | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \\| undefined | |\n\nMethods\n-------\n\n| Method | Modifiers | Description |\n|--------------------------------------------------------------------------------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getHistory()](./ai.chatsession.md#chatsessiongethistory) | | Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history. |\n| [sendMessage(request)](./ai.chatsession.md#chatsessionsendmessage) | | Sends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface) |\n| [sendMessageStream(request)](./ai.chatsession.md#chatsessionsendmessagestream) | | Sends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise. |\n\nChatSession.(constructor)\n-------------------------\n\nConstructs a new instance of the `ChatSession` class\n\n**Signature:** \n\n constructor(apiSettings: ApiSettings, model: string, chromeAdapter?: ChromeAdapter | undefined, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);\n\n#### Parameters\n\n| Parameter | Type | Description |\n|----------------|-----------------------------------------------------------------------------------|-------------|\n| apiSettings | ApiSettings | |\n| model | string | |\n| chromeAdapter | [ChromeAdapter](./ai.chromeadapter.md#chromeadapter_interface) \\| undefined | |\n| params | [StartChatParams](./ai.startchatparams.md#startchatparams_interface) \\| undefined | |\n| requestOptions | [RequestOptions](./ai.requestoptions.md#requestoptions_interface) \\| undefined | |\n\nChatSession.model\n-----------------\n\n**Signature:** \n\n model: string;\n\nChatSession.params\n------------------\n\n**Signature:** \n\n params?: StartChatParams | undefined;\n\nChatSession.requestOptions\n--------------------------\n\n**Signature:** \n\n requestOptions?: RequestOptions | undefined;\n\nChatSession.getHistory()\n------------------------\n\nGets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history.\n\n**Signature:** \n\n getHistory(): Promise\u003cContent[]\u003e;\n\n**Returns:**\n\nPromise\\\u003c[Content](./ai.content.md#content_interface)\\[\\]\\\u003e\n\nChatSession.sendMessage()\n-------------------------\n\nSends a chat message and receives a non-streaming [GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface)\n\n**Signature:** \n\n sendMessage(request: string | Array\u003cstring | Part\u003e): Promise\u003cGenerateContentResult\u003e;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|---------------------------------------------------|-------------|\n| request | string \\| Array\\\u003cstring \\| [Part](./ai.md#part)\\\u003e | |\n\n**Returns:**\n\nPromise\\\u003c[GenerateContentResult](./ai.generatecontentresult.md#generatecontentresult_interface)\\\u003e\n\nChatSession.sendMessageStream()\n-------------------------------\n\nSends a chat message and receives the response as a [GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface) containing an iterable stream and a response promise.\n\n**Signature:** \n\n sendMessageStream(request: string | Array\u003cstring | Part\u003e): Promise\u003cGenerateContentStreamResult\u003e;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|---------------------------------------------------|-------------|\n| request | string \\| Array\\\u003cstring \\| [Part](./ai.md#part)\\\u003e | |\n\n**Returns:**\n\nPromise\\\u003c[GenerateContentStreamResult](./ai.generatecontentstreamresult.md#generatecontentstreamresult_interface)\\\u003e"]]