Skip to content

REST API

This content is for v1.x. Switch to the latest version for up-to-date documentation.

Base URL: your deployed worker, e.g. https://claudius-chat-worker.<you>.workers.dev. CORS restricts callers to the configured ALLOWED_ORIGIN list (plus http://localhost:*). Allowed methods: POST, OPTIONS; allowed header: Content-Type.

Send the conversation so far; receive the assistant’s reply.

{
"messages": [
{ "role": "user", "content": "Hello" },
{ "role": "assistant", "content": "Hi there!" },
{ "role": "user", "content": "What are your hours?" }
],
"conversationId": "optional-opaque-id"
}
FieldTypeNotes
messagesarray, requiredFull conversation history, oldest first. Max 100 messages; each content is truncated to 2,000 characters
messages[].role"user" | "assistant"Other roles are rejected
conversationIdstring, optionalOpaque id used only for analytics correlation
{
"reply": "We're available Monday through Friday, 9am to 5pm.",
"sources": [
{ "url": "https://example.com/contact", "title": "Contact", "type": "page" }
]
}

sources is optional and reserved for retrieval-backed backends — the bundled worker returns only reply today (see RAG).

All errors share one envelope:

{ "error": "Human-readable message", "code": "MACHINE_CODE", "limitType": "minute" }
StatuscodeWhenExtra
400VALIDATION_ERROREmpty/missing messages, more than 100 messages, invalid role
429RATE_LIMITEDPer-IP limit exceeded (default 10/min, 50/hr)Retry-After header (seconds); limitType: "minute" or "hour"
500CONFIG_ERRORWorker misconfiguration (e.g. bad API key)
503SERVICE_ERRORClaude temporarily unavailable/overloaded
500UNKNOWN_ERRORAnything else
{ "ok": true }

Use for uptime checks; it does not call Claude.

The widget’s built-in API client retries up to 2 times (3 attempts total): 429 waits for the server’s Retry-After; 503 backs off exponentially (1 s, then 3 s). Sends are debounced (300 ms default). If you build your own client, mirroring this behavior plays well with the worker’s limits.