Chat Endpoint

Send messages to your agent and receive AI responses programmatically.

The Chat endpoint lets you send messages to your agent and receive AI responses. Use it to build custom chat interfaces or integrate agent functionality into your applications.

Endpoint

POST /api/v1/chat

Authentication

Requires Bearer token authentication.

Authorization: Bearer YOUR_API_KEY

Request Body

{
  "chatbotId": "uuid",
  "messages": [
    { "role": "user", "content": "What are your pricing plans?" }
  ],
  "conversationId": "optional-id",
  "stream": false
}

Parameters

FieldTypeRequiredDescription
chatbotIdstring (UUID)YesYour agent's ID
messagesarrayYesArray of message objects (1-100 items)
conversationIdstring (max 16 chars)NoReference ID returned by a prior call's x-conversation-id header. Invalid or missing values cause the server to assign a fresh ID.
streambooleanNoEnable streaming response (default: false)

Message Object

FieldTypeValuesDescription
rolestring"user", "assistant"Who sent the message
contentstring1-32000 charsMessage text

Limits

  • Maximum 100 messages per request
  • Maximum 32,000 characters per message

Response

Non-Streaming (default)

Success (200):

{
  "text": "Our pricing starts at $29.99/month for the Hobby plan..."
}

Headers include:

X-Conversation-ID: abc123

Streaming

Set "stream": true for streaming responses.

Success (200):

Content-Type: text/plain; charset=utf-8

Response streams plain text as it's generated. Use this for real-time UI updates.

Example Requests

Basic Request

curl -X POST 'https://your-domain.com/api/v1/chat' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "chatbotId": "123e4567-e89b-12d3-a456-426614174000",
    "messages": [
      {"role": "user", "content": "What are your pricing plans?"}
    ]
  }'

Multi-Turn Conversation

curl -X POST 'https://your-domain.com/api/v1/chat' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "chatbotId": "123e4567-e89b-12d3-a456-426614174000",
    "conversationId": "conv_abc123",
    "messages": [
      {"role": "user", "content": "What are your pricing plans?"},
      {"role": "assistant", "content": "We offer three plans..."},
      {"role": "user", "content": "Tell me more about the Pro plan"}
    ]
  }'

Streaming Response

curl -X POST 'https://your-domain.com/api/v1/chat' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "chatbotId": "123e4567-e89b-12d3-a456-426614174000",
    "messages": [{"role": "user", "content": "Hello"}],
    "stream": true
  }'

Error Responses

StatusMessageCause
400Invalid JSON bodyMalformed JSON
400Invalid request bodyMissing/invalid fields
401Missing or invalid Authorization headerHeader not provided or wrong format
401Invalid API keyKey not recognized
403API access requires a Hobby plan or above with active billingPlan/billing does not allow API access
403Chatbot does not belong to this accountAgent belongs to a different account
404Chatbot not foundInvalid agent ID
429Rate limit exceededToo many requests

Error Response Format

{
  "message": "Invalid request body",
  "details": {
    "chatbotId": ["Required"]
  }
}

Code Examples

Node.js

async function sendMessage(chatbotId, message) {
  const response = await fetch('https://your-domain.com/api/v1/chat', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.AGENTKIT_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      chatbotId,
      messages: [{ role: 'user', content: message }],
    }),
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

  const data = await response.json();
  return data.text;
}

Python

import requests

def send_message(chatbot_id: str, message: str) -> str:
    response = requests.post(
        'https://your-domain.com/api/v1/chat',
        headers={
            'Authorization': f'Bearer {API_KEY}',
            'Content-Type': 'application/json',
        },
        json={
            'chatbotId': chatbot_id,
            'messages': [{'role': 'user', 'content': message}],
        },
    )
    response.raise_for_status()
    return response.json()['text']

Node.js with Streaming

async function streamMessage(chatbotId, message) {
  const response = await fetch('https://your-domain.com/api/v1/chat', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.AGENTKIT_API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      chatbotId,
      messages: [{ role: 'user', content: message }],
      stream: true,
    }),
  });

  const reader = response.body.getReader();
  const decoder = new TextDecoder();

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    const text = decoder.decode(value);
    process.stdout.write(text); // Print as it streams
  }
}

Conversation Management

Starting a Conversation

Omit conversationId to start a new conversation. The response header X-Conversation-ID returns the new ID.

Continuing a Conversation

Include the conversationId and all previous messages to maintain context.

Message History

You must include previous messages in each request. The API is stateless - we don't store conversation history on the server between requests.

Next Steps