Skip to content

Chat

POST /api/chat

Send a message and receive the complete response (non-streaming). For streaming, use the WebSocket endpoint.

Request

bash
curl -X POST http://localhost:3000/api/chat \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-key" \
  -d '{
    "text": "What files are in this directory?",
    "user_id": "user123",
    "channel_id": "main",
    "channel_session_key": "550e8400-e29b-41d4-a716-446655440000"
  }'

Request Body

FieldTypeRequiredDescription
textstringYesThe user's message
user_idstringNoUser identifier
channel_idstringNoChannel name (default: "main")
channel_session_keystringNoSession identifier

Response

json
{
  "text": "The directory contains:\n- Cargo.toml\n- README.md\n- src/\n- crates/",
  "session_id": "abc123-def456",
  "usage": {
    "input_tokens": 1200,
    "output_tokens": 85,
    "cache_read_tokens": 0,
    "cache_write_tokens": 0,
    "cost_usd": 0.0032
  }
}

Response Fields

FieldTypeDescription
textstringThe agent's response text
session_idstringThe session this message belongs to
usageobjectToken usage and cost
usage.input_tokensintegerTokens sent to Claude
usage.output_tokensintegerTokens generated by Claude
usage.cache_read_tokensintegerTokens read from cache
usage.cache_write_tokensintegerTokens written to cache
usage.cost_usdfloatEstimated cost in USD

Session Behavior

  • If channel_session_key is provided, the message continues that session
  • If omitted, a new session is created
  • Sessions on the main channel are explicit — the same key always maps to the same session

Released under the MIT License.