Skip to main content
Arcanflows

Conversations API

Create and manage conversations with agents, and retrieve message history.

Overview

Conversations represent chat sessions between users and agents. Each conversation belongs to a single agent and contains an ordered list of messages. Use these endpoints to create conversations, send and retrieve messages, and manage conversation history.

Base URL: /api/v1


Endpoints Summary

MethodEndpointDescription
GET/api/v1/conversationsList all conversations
POST/api/v1/conversationsCreate a new conversation
GET/api/v1/conversations/:idGet conversation details
PUT/api/v1/conversations/:idUpdate a conversation
DELETE/api/v1/conversations/:idDelete a conversation
GET/api/v1/conversations/:id/messagesGet messages in a conversation
GET/api/v1/agents/:agent_id/conversationsList conversations for an agent

List Conversations

GET /api/v1/conversations

Retrieve all conversations for the authenticated user. Supports pagination, sorting, and filtering.

Query Parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
per_pageinteger20Results per page (max 100)
sortstringupdated_atSort field: created_at, updated_at, title
orderstringdescSort order: asc or desc
agent_idstring--Filter by agent ID
searchstring--Search conversation titles
bash
curl -X GET "/api/v1/conversations?page=1&per_page=10&sort=updated_at&order=desc" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Response 200 OK:

json
{
  "conversations": [
    {
      "id": "conv_abc123",
      "title": "Help with onboarding flow",
      "agent_id": "agt_xyz789",
      "agent_name": "Customer Support Bot",
      "message_count": 14,
      "last_message_preview": "Sure, I can walk you through the setup...",
      "created_at": "2025-10-05T09:00:00Z",
      "updated_at": "2025-10-05T09:32:00Z"
    },
    {
      "id": "conv_def456",
      "title": "API integration questions",
      "agent_id": "agt_xyz789",
      "agent_name": "Customer Support Bot",
      "message_count": 8,
      "last_message_preview": "The webhook endpoint accepts POST...",
      "created_at": "2025-10-04T15:20:00Z",
      "updated_at": "2025-10-04T15:45:00Z"
    }
  ],
  "total": 42,
  "page": 1,
  "per_page": 10
}

Create Conversation

POST /api/v1/conversations

Create a new conversation with an agent. Optionally include an initial message.

bash
curl -X POST /api/v1/conversations \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
  -H "Content-Type: application/json" \
  -d '{
    "agent_id": "agt_xyz789",
    "title": "Help with onboarding flow",
    "initial_message": "How do I set up a new user onboarding workflow?"
  }'

Request Body:

FieldTypeRequiredDescription
agent_idstringYesThe agent to converse with
titlestringNoConversation title (auto-generated if omitted)
initial_messagestringNoFirst user message to send immediately
metadataobjectNoCustom key-value metadata

Response 201 Created:

json
{
  "id": "conv_ghi789",
  "title": "Help with onboarding flow",
  "agent_id": "agt_xyz789",
  "agent_name": "Customer Support Bot",
  "message_count": 2,
  "messages": [
    {
      "id": "msg_001",
      "role": "user",
      "content": "How do I set up a new user onboarding workflow?",
      "created_at": "2025-10-06T11:00:00Z"
    },
    {
      "id": "msg_002",
      "role": "assistant",
      "content": "I'd be happy to help you set up an onboarding workflow! Here are the steps...",
      "metadata": {
        "model": "gpt-4o",
        "tokens_prompt": 42,
        "tokens_completion": 187,
        "latency_ms": 1240
      },
      "created_at": "2025-10-06T11:00:01Z"
    }
  ],
  "metadata": {},
  "created_at": "2025-10-06T11:00:00Z",
  "updated_at": "2025-10-06T11:00:01Z"
}

If initial_message is omitted, the conversation is created empty with message_count: 0.


Get Conversation

GET /api/v1/conversations/:id

Retrieve details of a specific conversation.

bash
curl -X GET /api/v1/conversations/conv_abc123 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Response 200 OK:

json
{
  "id": "conv_abc123",
  "title": "Help with onboarding flow",
  "agent_id": "agt_xyz789",
  "agent_name": "Customer Support Bot",
  "message_count": 14,
  "metadata": {},
  "created_at": "2025-10-05T09:00:00Z",
  "updated_at": "2025-10-05T09:32:00Z"
}

Update Conversation

PUT /api/v1/conversations/:id

Update a conversation's title or metadata.

bash
curl -X PUT /api/v1/conversations/conv_abc123 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..." \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Onboarding flow - resolved",
    "metadata": {
      "status": "resolved",
      "tags": ["onboarding", "workflow"]
    }
  }'

Request Body:

FieldTypeRequiredDescription
titlestringNoNew conversation title
metadataobjectNoCustom key-value metadata (merged with existing)

Response 200 OK:

json
{
  "id": "conv_abc123",
  "title": "Onboarding flow - resolved",
  "agent_id": "agt_xyz789",
  "metadata": {
    "status": "resolved",
    "tags": ["onboarding", "workflow"]
  },
  "updated_at": "2025-10-06T11:30:00Z"
}

Delete Conversation

DELETE /api/v1/conversations/:id

Permanently delete a conversation and all its messages. This action cannot be undone.

bash
curl -X DELETE /api/v1/conversations/conv_abc123 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Response 200 OK:

json
{
  "message": "Conversation deleted successfully"
}

Get Messages

GET /api/v1/conversations/:id/messages

Retrieve all messages in a conversation. Messages are returned in chronological order. Supports pagination for long conversations.

Query Parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
per_pageinteger50Messages per page (max 200)
orderstringascSort order: asc (oldest first) or desc (newest first)
bash
curl -X GET "/api/v1/conversations/conv_abc123/messages?page=1&per_page=50&order=asc" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Response 200 OK:

json
{
  "messages": [
    {
      "id": "msg_001",
      "conversation_id": "conv_abc123",
      "role": "system",
      "content": "You are a helpful customer support agent for Arcanflows.",
      "metadata": {},
      "created_at": "2025-10-05T09:00:00Z"
    },
    {
      "id": "msg_002",
      "conversation_id": "conv_abc123",
      "role": "user",
      "content": "How do I set up a new user onboarding workflow?",
      "metadata": {},
      "created_at": "2025-10-05T09:00:05Z"
    },
    {
      "id": "msg_003",
      "conversation_id": "conv_abc123",
      "role": "assistant",
      "content": "I'd be happy to help you set up an onboarding workflow! Here are the steps...",
      "metadata": {
        "model": "gpt-4o",
        "tokens_prompt": 128,
        "tokens_completion": 256,
        "latency_ms": 1540
      },
      "created_at": "2025-10-05T09:00:07Z"
    },
    {
      "id": "msg_004",
      "conversation_id": "conv_abc123",
      "role": "user",
      "content": "Can I add a conditional step based on the user's role?",
      "metadata": {},
      "created_at": "2025-10-05T09:01:20Z"
    },
    {
      "id": "msg_005",
      "conversation_id": "conv_abc123",
      "role": "assistant",
      "content": "Absolutely! You can add conditional branching in your workflow...",
      "metadata": {
        "model": "gpt-4o",
        "tokens_prompt": 412,
        "tokens_completion": 198,
        "latency_ms": 1120
      },
      "created_at": "2025-10-05T09:01:22Z"
    }
  ],
  "total": 14,
  "page": 1,
  "per_page": 50
}

Message Object

FieldTypeDescription
idstringUnique message identifier
conversation_idstringParent conversation ID
rolestringMessage role: user, assistant, or system
contentstringMessage text content
metadataobjectAdditional data (see below)
created_atstringISO 8601 timestamp

Message Metadata (assistant messages)

FieldTypeDescription
modelstringLLM model used (e.g., gpt-4o, claude-3-sonnet)
tokens_promptintegerNumber of prompt tokens consumed
tokens_completionintegerNumber of completion tokens generated
latency_msintegerResponse time in milliseconds
tools_usedarrayList of tool names invoked during this turn

List Conversations by Agent

GET /api/v1/agents/:agent_id/conversations

Retrieve all conversations associated with a specific agent.

Query Parameters:

ParameterTypeDefaultDescription
pageinteger1Page number
per_pageinteger20Results per page (max 100)
sortstringupdated_atSort field: created_at, updated_at
orderstringdescSort order: asc or desc
bash
curl -X GET "/api/v1/agents/agt_xyz789/conversations?page=1&per_page=10" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIs..."

Response 200 OK:

json
{
  "conversations": [
    {
      "id": "conv_abc123",
      "title": "Help with onboarding flow",
      "agent_id": "agt_xyz789",
      "agent_name": "Customer Support Bot",
      "message_count": 14,
      "last_message_preview": "Sure, I can walk you through the setup...",
      "created_at": "2025-10-05T09:00:00Z",
      "updated_at": "2025-10-05T09:32:00Z"
    }
  ],
  "total": 7,
  "page": 1,
  "per_page": 10
}

Conversation Object Reference

FieldTypeDescription
idstringUnique conversation identifier
titlestringConversation title
agent_idstringAssociated agent ID
agent_namestringAgent display name
message_countintegerTotal number of messages
last_message_previewstringTruncated preview of the last message
metadataobjectCustom key-value metadata
created_atstringISO 8601 creation timestamp
updated_atstringISO 8601 last-update timestamp

Error Responses

404 Not Found

Returned when a conversation or agent does not exist, or the user does not have access.

json
{
  "error": {
    "code": "not_found",
    "message": "Conversation not found"
  }
}

403 Forbidden

Returned when the user does not have permission to access the conversation.

json
{
  "error": {
    "code": "forbidden",
    "message": "You do not have access to this conversation"
  }
}

422 Validation Error

Returned when the request body fails validation.

json
{
  "error": {
    "code": "validation_error",
    "message": "Invalid request body",
    "details": {
      "agent_id": "Agent not found or not accessible"
    }
  }
}