Docs
Chat API

Chat API

Reference for the main chat endpoint, conversation history, and conversation management.

POST /api/assistant/router

The main chat endpoint. Routes the message to the appropriate agent and returns a streaming response.

Auth: Required (session cookie or Bearer token)

Request body:

{
  messages: UIMessage[]      // Vercel AI SDK UIMessage format
  conversationId?: string    // omit to create a new conversation
  agentId?: string           // bypass routing and force a specific agent
  modelId?: string           // override the agent's default model
}

Response: Server-Sent Events stream (Vercel AI SDK UIMessageStreamResponse format)

Response headers:

HeaderDescription
x-conversation-idThe conversation ID — new for new conversations, echoed back for existing ones

Error responses:

StatusReason
401Not authenticated
429Rate limit exceeded for the team's plan
500Agent execution error

Example (using @ai-sdk/react):

import { useChat } from "@ai-sdk/react";
 
const { messages, input, handleSubmit } = useChat({
  api: "/api/assistant/router",
  body: {
    agentId: "receipt-scanner", // optional
    modelId: "gpt-4o",          // optional
  },
  onResponse: (response) => {
    const conversationId = response.headers.get("x-conversation-id");
    // save to state for subsequent requests
  },
});

GET /api/assistant/history

Fetch the full message history for a conversation.

Query params: ?id=<conversationId>

Response:

{
  messages: UIMessage[],
  conversation: {
    id: string,
    title: string,
    niche: string,
    workflowRun: {
      id: number,
      status: string,
      totalSteps: number,
      currentStepDescription: string,
      workflow: { id: string, title: string }
    } | null
  }
}

workflowRun is null for regular user chats and populated for workflow-run conversations.


GET /api/assistant/conversations

List all conversations for the current team.

Response: Array of conversation objects, newest first, limit 50.


DELETE /api/assistant/conversations

Delete a conversation and all its messages.

Query params: ?id=<conversationId>

Response: { success: true }

Deletion cascades to all messages in the conversation.