Session persistence
Contents
[
Hide
]
You can save a chat session to disk and load it later to continue the conversation.
Saving a session
api.SaveChatSession(sessionId, filePath: "my-session.json");
If you omit filePath, the session is saved using the session ID as the file name (in the current working directory or a default location, depending on the implementation). The saved file contains the conversation state (e.g. message history and context) so it can be restored later.
Loading a session
string sessionId = await api.LoadChatSession("my-session.json");
This restores the session and returns its identifier. You can then send new messages to that session with SendMessageToSessionAsync(sessionId, message).
Typical use
- Start a chat with
StartNewChatAsyncor use an existing session. - Exchange messages with
SendMessageToSessionAsync. - When you want to pause, call
SaveChatSession(sessionId, filePath). - Later, call
LoadChatSession(filePath)to get the session ID and continue the conversation.
This is useful for long-running conversations, resumable chats, or persisting state across application restarts.