Skip to content

Import & Export

Chatty the Lab supports importing and exporting chat conversations in JSON format. This enables sharing conversations between sessions, backing up data, and migrating chats.

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..." }
]
}
FieldTypeDescription
model_namestringThe model used in the original chat
titlestringDisplay title of the chat
context_textstring?System prompt / context (optional)
messagesarrayOrdered list of messages
messages[].rolestringOne of system, user, assistant
messages[].contentstringMessage text

The frontend provides a download button that:

  1. Serializes the active chat’s data (model name, title, context, messages) to JSON
  2. Creates a Blob and triggers a browser download
  3. 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.

POST /api/sessions/{session_id}/chats/import
Authorization: Bearer <token>
Content-Type: application/json
{
"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..." }
]
}
  1. The backend verifies session ownership
  2. Determines the next available position in the session
  3. Creates a new chats row
  4. Inserts all messages in order, preserving role and content
  5. Returns the full ChatWithMessages object
{
"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"
}
]
}

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
});
  • 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