PAI Chat·Error codes
PAI Chat API errors
PAI Chat returns a JSON body with a message field on every error. API-key failures also include a symbolic code; validation failures include an errors array.
Response shape
Middleware and route errors return { message }; API-key authentication errors return { message, code }; schema validation failures return { message, errors }.
{
"message": "Forbidden: API key not valid for this chatbot"
}HTTP status + messages
Handling 429 rate limits
Two independent limits can return 429: the per-key daily limit (better-auth, RATE_LIMITED) and a general per-IP limit enforced on every route. Neither response currently guarantees a Retry-After header — back off with exponential delay and jitter.
JavaScript
// Exponential backoff with jitter
async function withRetry(fn, { max = 5 } = {}) {
for (let i = 0; i < max; i++) {
const res = await fn();
if (res.status !== 429 && res.status < 500) return res;
await new Promise(r => setTimeout(r, 2 ** i * 250 + Math.random() * 250));
}
throw new Error('retry budget exhausted');
}Debugging checklist
- Confirm
x-api-keyis set and the key is enabled in the dashboard. - For chatbot-scoped calls, confirm
x-chatbot-idis set and matches the key's scope. - For organization-level calls, confirm
x-organization-idmatches the key's organization. - A
403almost always means the key or session is valid but scoped to a different org/chatbot.
support_agent
Reporting a problem? Include the endpoint, HTTP method, timestamp, and the exact
message value — there is no request id to trace by yet.