Firebase. AI. Chat
An object that represents a back-and-forth chat with a model, capturing the history and saving the context in memory between each message sent.
Summary
Public attributes | |
|---|---|
History => chatHistory | IReadOnlyList<ModelContent >The previous content from the chat that has been successfully sent and received from the model. |
Public functions | |
|---|---|
SendMessageAsync(ModelContent content, CancellationToken cancellationToken) | Task<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
SendMessageAsync(string text, CancellationToken cancellationToken) | Task<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
SendMessageAsync(IEnumerable<ModelContent > content, CancellationToken cancellationToken) | Task<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
SendMessageStreamAsync(ModelContent content, CancellationToken cancellationToken) | IAsyncEnumerable<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
SendMessageStreamAsync(string text, CancellationToken cancellationToken) | IAsyncEnumerable<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
SendMessageStreamAsync(IEnumerable<ModelContent > content, CancellationToken cancellationToken) | IAsyncEnumerable<GenerateContentResponse >Sends a message using the existing history of this chat as context. |
Public attributes
History
IReadOnlyList<ModelContent>History=>chatHistory
The previous content from the chat that has been successfully sent and received from the model.
This will be provided to the model for each message sent as context for the discussion.
Public functions
SendMessageAsync
Task<GenerateContentResponse>SendMessageAsync(ModelContentcontent,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | The model's response if no error occurred. |
SendMessageAsync
Task<GenerateContentResponse>SendMessageAsync(stringtext,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | The model's response if no error occurred. |
SendMessageAsync
Task<GenerateContentResponse>SendMessageAsync(IEnumerable<ModelContent>content,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | The model's response if no error occurred. |
SendMessageStreamAsync
IAsyncEnumerable<GenerateContentResponse>SendMessageStreamAsync(ModelContentcontent,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | A stream of generated content responses from the model. |
SendMessageStreamAsync
IAsyncEnumerable<GenerateContentResponse>SendMessageStreamAsync(stringtext,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | A stream of generated content responses from the model. |
SendMessageStreamAsync
IAsyncEnumerable<GenerateContentResponse>SendMessageStreamAsync(IEnumerable<ModelContent>content,CancellationTokencancellationToken)
Sends a message using the existing history of this chat as context.
If successful, the message and response will be added to the history. If unsuccessful, history will remain unchanged.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
| ||||
| Exceptions |
| ||||
| Returns | A stream of generated content responses from the model. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-24 UTC.