Skip to content

Dialogues API

Manage conversations with threading and state management.

Create Dialogue

Create a new dialogue.

Endpoint

http
POST /dialogue

Authentication

Bearer token (via Authorization header)

Request Body

FieldTypeRequiredDescription
namespacestringNoOptional namespace for user isolation (e.g., userId)
threadOfstringNoParent dialogue ID if this is a thread
messageobjectNoSingle message to add
message.idstringNoCustom message ID (auto-generated if not provided)
message.contentstringYesMessage content
message.rolestringYesMessage role (user, assistant, system)
message.namestringNoOptional name for the speaker
message.createdstringNoCustom creation timestamp (ISO 8601)
message.tagsstring[]NoMessage tags
message.metadataobjectNoMessage metadata (immutable after creation)
messagesarrayNoArray of messages (treated as history)
messages[].idstringNoCustom message ID
messages[].contentstringYesMessage content
messages[].rolestringYesMessage role
messages[].namestringNoOptional speaker name
messages[].createdstringNoCustom creation timestamp
messages[].tagsstring[]NoMessage tags
messages[].metadataobjectNoMessage metadata
stateobjectNoCustom state data
metadataobjectNoCustom metadata (immutable after creation)
tagsstring[]NoTags for the dialogue

Response

typescript
{
  id: string;
  projectId: string;
  threadOf?: string;
  totalMessages: number;
  threadCount?: number;
  status: string;
  tags: string[];
  metadata: Record<string, any>;
  created: string;
  modified: string;
  messages: Message[];  // Created messages returned
}

Behavior

  • Authenticated via bearer token
  • To create a thread: Set threadOf to parent dialogue's ID
  • messages[] treated as history and added first (in order)
  • message (singular) added after messages[] if both provided
  • Maximum 25 messages in initial creation
  • Returns dialogue with created messages

Field Mutability

User-settable on creation:

  • namespace - Optional namespace for user isolation
  • threadOf - Parent dialogue reference
  • tags - Categorization tags
  • metadata - Custom metadata (⚠️ immutable after creation)
  • messages/message - Initial conversation history
  • state - Initial state data

System-managed (read-only):

  • id - Auto-generated identifier
  • projectId - Your project identifier
  • status - Dialogue status (active, ended, canceled, expired)
  • totalMessages - Message count
  • threadCount - Number of child threads
  • lastMessageCreated - Timestamp of most recent message
  • created - Creation timestamp
  • modified - Last modification timestamp

Important Restrictions

  • Dialogue metadata is immutable after creation - it cannot be updated via PUT /dialogue/
  • Once a dialogue status is "ended", you cannot add messages or update it
  • Use tags (mutable) for categorization that may change
  • Use state (mutable) for data that changes during conversation

Constraints

  • Maximum 25 messages in initial creation
  • Messages are immutable after creation
  • Dialogue IDs are auto-generated

Use Cases

  • New Conversation: Omit threadOf to create a root dialogue
  • Threaded Reply: Include threadOf to branch from existing dialogue
  • Import History: Use messages array to restore conversation context

Errors

StatusError CodeDescription
400TOO_MANY_MESSAGESExceeds 25 message limit on creation
400INVALID_INPUTInvalid input data or format
401N/AUnauthorized - invalid or missing API key
404PROJECT_NOT_FOUNDProject does not exist
404PARENT_DIALOGUE_NOT_FOUNDParent dialogue not found (for threads)
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X POST https://api.dialoguedb.com/dialogue \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Hello"}]
  }'
bash
curl -X POST https://api.dialoguedb.com/dialogue \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "threadOf": "dlg_abc123xyz",
    "message": {"role": "user", "content": "Follow-up question"}
  }'
typescript
const dialogue = await fetch('https://api.dialoguedb.com/dialogue', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    message: {
      role: 'user',
      content: 'Hello'
    },
    metadata: {
      userId: 'user_123',
      channel: 'web'
    },
    tags: ['support']
  })
});
typescript
const dialogue = await client.dialogues.create({
  message: {
    role: 'user',
    content: 'Hello'
  },
  metadata: {
    userId: 'user_123'
  }
});

Update Dialogue

Update an existing dialogue's mutable properties and optionally add messages.

Endpoint

http
PUT /dialogue/{id}

Authentication

Bearer token (via Authorization header)

Path Parameters

ParameterTypeRequiredDescription
idstringYesDialogue ID (identifier)

Request Body

FieldTypeRequiredDescription
tagsstring[]NoTags for the dialogue (replaces existing)
labelstringNoHuman-readable label (max 128 chars)
stateobjectNoState data (merged with existing state)
messageobjectNoSingle message to add
messagesarrayNoArray of messages to add (max 25)

Response

typescript
{
  id: string;
  projectId: string;
  namespace?: string;
  threadOf?: string;
  totalMessages: number;
  threadCount?: number;
  status: string;
  tags: string[];
  metadata: Record<string, any>;  // Immutable - set at creation
  created: string;
  modified: string;
  messages: Message[];            // Created messages (if any provided)
  state: Record<string, any>;     // Current state data
}

Behavior

  • Updates mutable fields: tags, label, state
  • Adds messages if message or messages provided
  • Tags are replaced entirely (not merged)
  • State is merged with existing state (PATCH semantics)
  • Metadata cannot be updated - it is immutable after dialogue creation
  • Cannot modify existing messages or status through this endpoint

Metadata Immutability

Dialogue metadata is set at creation and cannot be changed. If you need mutable data:

  • Use tags for categorization that may change
  • Use label for a human-readable identifier
  • Use state for conversation-specific data that changes

Errors

StatusError CodeDescription
400MISSING_PARAMETERMissing required dialogue ID
400INVALID_INPUTInvalid metadata or tags format
401N/AUnauthorized - invalid or missing API key
404DIALOGUE_NOT_FOUNDDialogue does not exist
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X PUT https://api.dialoguedb.com/dialogue/dlg_abc123xyz \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "tags": ["support", "resolved"],
    "label": "Support Request #123"
  }'
bash
curl -X PUT https://api.dialoguedb.com/dialogue/dlg_abc123xyz \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "state": { "step": "completed", "resolution": "refunded" },
    "message": { "role": "assistant", "content": "Your refund has been processed." }
  }'
typescript
const updated = await fetch(
  `https://api.dialoguedb.com/dialogue/${dialogueId}`,
  {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      tags: ['support', 'resolved'],
      state: { status: 'completed' }
    })
  }
).then(r => r.json());
typescript
const updated = await client.dialogues.update(dialogueId, {
  tags: ['support', 'resolved'],
  label: 'Resolved Support Ticket'
});

List Dialogues

Retrieve dialogues with pagination and filtering.

Endpoint

http
GET /dialogue

Authentication

Bearer token (via Authorization header)

Query Parameters

ParameterTypeRequiredDescription
querystringNoQuery template (default: "default", use "threads" for thread listing)
threadOfstringNoParent dialogue ID (when query="threads")
namespacestringNoFilter by namespace
datestringNoFilter by date
limitnumberNoMax items to return per page
orderstringNoSort order ("asc" or "desc")
nextstringNoPagination token for next page

Response

typescript
{
  items: Dialogue[];
  next?: string; // Pagination token if more results exist
}

Behavior

  • Results scoped to your project
  • Sorted by creation date (descending by default)
  • Paginated automatically - use next cursor for additional pages
  • Filter to threads using threadOf parameter

Errors

StatusError CodeDescription
401N/AUnauthorized - invalid or missing API key
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X GET "https://api.dialoguedb.com/dialogue?limit=20&order=desc" \
  -H "Authorization: Bearer YOUR_API_KEY"
bash
curl -X GET "https://api.dialoguedb.com/dialogue?query=threads&threadOf=dlg_abc123xyz" \
  -H "Authorization: Bearer YOUR_API_KEY"
typescript
const { items, next } = await fetch(
  'https://api.dialoguedb.com/dialogue?limit=20',
  {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
).then(r => r.json());
typescript
const { items, next } = await client.dialogues.list({
  limit: 20,
  order: 'desc'
});

Get Dialogue

Retrieve dialogue metadata by ID with the first 10 messages.

Endpoint

http
GET /dialogue/{id}

Authentication

Bearer token (via Authorization header)

Path Parameters

ParameterTypeRequiredDescription
idstringYesDialogue ID (identifier)

Response

typescript
{
  id: string;
  projectId: string;
  threadOf?: string; // If this dialogue is a thread
  threadCount?: number;
  totalMessages: number;
  lastMessageCreated?: string;
  status: "active" | "canceled" | "expired" | "deleted";
  expired: boolean;
  tags: string[];
  metadata: Record<string, any>;
  created: string;
  modified: string;
  messages: Message[];  // First 10 messages
}

Behavior

  • Returns dialogue with up to 10 most recent messages
  • For complete message history, use GET /dialogue/{id}/messages
  • totalMessages field shows total count (not just returned messages)

Errors

StatusError CodeDescription
400MISSING_PARAMETERMissing required dialogue ID
401N/AUnauthorized - invalid or missing API key
404DIALOGUE_NOT_FOUNDDialogue does not exist
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X GET https://api.dialoguedb.com/dialogue/dlg_abc123xyz \
  -H "Authorization: Bearer YOUR_API_KEY"
typescript
const dialogue = await fetch(
  `https://api.dialoguedb.com/dialogue/${dialogueId}`,
  {
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
).then(r => r.json());
typescript
const dialogue = await client.dialogues.get(dialogueId);

Delete Dialogue

Delete a dialogue by ID.

Endpoint

http
DELETE /dialogue/{id}

Authentication

Bearer token (via Authorization header)

Path Parameters

ParameterTypeRequiredDescription
idstringYesDialogue ID (identifier)

Response

typescript
{
  success: boolean;
  id: string;
}

Behavior

  • Permanently deletes the dialogue
  • Messages within this dialogue remain accessible
  • Child threads (if any) remain accessible
  • This operation cannot be undone

Warnings

  • Irreversible: Deleted dialogues cannot be recovered
  • Messages persist: Use DELETE /dialogue/{id}/messages/{messageId} to remove messages
  • Threads unaffected: Child threads remain as independent dialogues
  • PUT /dialogue/{id}/end - Mark dialogue as ended (prevents further messages)
  • DELETE /dialogue/{dialogueId}/messages/{messageId} - Delete individual messages

Ended Dialogues

After ending a dialogue, you cannot add new messages or update the dialogue. State can still be updated via PUT /dialogue/{id}/state. This action is reversible - contact support if needed.

Errors

StatusError CodeDescription
400MISSING_PARAMETERMissing required dialogue ID
401N/AUnauthorized - invalid or missing API key
404DIALOGUE_NOT_FOUNDDialogue does not exist
409DIALOGUE_IMMUTABLECannot delete immutable dialogue (check project settings)
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X DELETE https://api.dialoguedb.com/dialogue/dlg_abc123xyz \
  -H "Authorization: Bearer YOUR_API_KEY"
typescript
const result = await fetch(
  `https://api.dialoguedb.com/dialogue/${dialogueId}`,
  {
    method: 'DELETE',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
).then(r => r.json());
typescript
await client.dialogues.delete(dialogueId);

Dialogue Actions

Perform actions on a dialogue.

Endpoint

http
PUT /dialogue/{id}/{action}

Authentication

Bearer token (via Authorization header)

Path Parameters

ParameterTypeRequiredDescription
idstringYesDialogue ID (identifier)
actionstringYesAction to perform: "end", "compact", or "continue"

Actions

end

Marks the dialogue as ended/closed. Finalizes the conversation and returns updated dialogue state.

compact

Summarizes/compacts the dialogue. Generates a summary of the conversation, useful for reducing token count while preserving context.

continue

Creates a new dialogue continuing from this one. (Note: Currently returns empty object, future implementation planned)

Response

Action-specific response object.

Errors

StatusError CodeDescription
400MISSING_PARAMETERMissing required dialogue ID
400INVALID_ACTIONUnsupported action (must be: end, compact, or continue)
401N/AUnauthorized - invalid or missing API key
404DIALOGUE_NOT_FOUNDDialogue does not exist
429RATE_LIMIT_EXCEEDEDToo many requests - retry with backoff
500INTERNAL_ERRORServer error - contact support with requestId

See Error Handling for complete error reference.

Examples

bash
curl -X PUT https://api.dialoguedb.com/dialogue/dlg_abc123xyz/end \
  -H "Authorization: Bearer YOUR_API_KEY"
bash
curl -X PUT https://api.dialoguedb.com/dialogue/dlg_abc123xyz/compact \
  -H "Authorization: Bearer YOUR_API_KEY"
typescript
// End dialogue
const result = await fetch(
  `https://api.dialoguedb.com/dialogue/${dialogueId}/end`,
  {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
).then(r => r.json());

// Compact dialogue
const summary = await fetch(
  `https://api.dialoguedb.com/dialogue/${dialogueId}/compact`,
  {
    method: 'PUT',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY'
    }
  }
).then(r => r.json());
typescript
// End dialogue
await client.dialogues.action(dialogueId, 'end');

// Compact dialogue
const summary = await client.dialogues.action(dialogueId, 'compact');

Built with DialogueDB