Import & Export
Overview
Section titled “Overview”Chatty the Lab supports importing and exporting chat conversations in JSON format. This enables sharing conversations between sessions, backing up data, and migrating chats.
Export format
Section titled “Export format”When exporting a chat, the frontend serializes it to JSON with the following structure:
{ "model_name": "GPT-4", "title": "Medical Q&A", "context_text": "You are a medical assistant.", "messages": [ { "role": "system", "content": "You are a medical assistant." }, { "role": "user", "content": "What is hypertension?" }, { "role": "assistant", "content": "Hypertension is a condition..." } ]}| Field | Type | Description |
|---|---|---|
model_name | string | The model used in the original chat |
title | string | Display title of the chat |
context_text | string? | System prompt / context (optional) |
messages | array | Ordered list of messages |
messages[].role | string | One of system, user, assistant |
messages[].content | string | Message text |
Downloading a chat
Section titled “Downloading a chat”The frontend provides a download button that:
- Serializes the active chat’s data (model name, title, context, messages) to JSON
- Creates a Blob and triggers a browser download
- The file is named after the chat title (e.g.,
Medical Q&A.json)
No backend call is needed for export — all data is already available in the frontend stores.
Importing a chat
Section titled “Importing a chat”Endpoint
Section titled “Endpoint”POST /api/sessions/{session_id}/chats/importAuthorization: Bearer <token>Content-Type: application/jsonRequest body
Section titled “Request body”{ "model_name": "GPT-4", "title": "Imported: Medical Q&A", "context_text": "You are a medical assistant.", "messages": [ { "role": "system", "content": "You are a medical assistant." }, { "role": "user", "content": "What is hypertension?" }, { "role": "assistant", "content": "Hypertension is a condition..." } ]}What happens on import
Section titled “What happens on import”- The backend verifies session ownership
- Determines the next available
positionin the session - Creates a new
chatsrow - Inserts all messages in order, preserving
roleandcontent - Returns the full
ChatWithMessagesobject
Response
Section titled “Response”{ "id": "uuid-of-new-chat", "session_id": "uuid-of-session", "position": 2, "model_name": "GPT-4", "title": "Imported: Medical Q&A", "context_text": "You are a medical assistant.", "created_at": "2026-03-23T10:00:00Z", "messages": [ { "id": "uuid", "chat_id": "uuid-of-new-chat", "position": 0, "role": "system", "content": "You are a medical assistant.", "created_at": "2026-03-23T10:00:00Z" } ]}Frontend API call
Section titled “Frontend API call”The frontend uses the api.chats.import() method:
const imported = await api.chats.import(token, sessionId, { model_name: chatData.model_name, title: chatData.title, context_text: chatData.context_text, messages: chatData.messages});Use cases
Section titled “Use cases”- Backup and restore: Export important conversations and re-import them later
- Cross-session sharing: Import a chat from one session into another to continue with a different model set
- Collaboration: Share JSON files with colleagues who can import them into their own sessions
- Reproducibility: Save and share the exact conversation history for research purposes