Errors
The Coaade Cloud API's error format, HTTP status codes and error codes.
Errors return a non-2xx status and a JSON body with a machine-readable error code and a human-readable message:
{
"error": "INVALID_CREDENTIALS",
"message": "Invalid email or password"
}Some errors add fields. For example, KEY_LIMIT_REACHED includes limit and used.
Branch on error, not on message; messages may change.
The model API uses a different error shape. See Model API errors.
Status codes
| Status | Meaning |
|---|---|
400 | The request was understood but can't be done, such as a wrong verification code |
401 | Missing, invalid or expired credentials |
402 | Payment is needed, for example checkout before a plan change |
403 | You're signed in but not allowed, such as a plan limit |
404 | The resource doesn't exist |
409 | It conflicts with existing data, such as an email that's already registered |
422 | The body failed validation |
429 | Rate limit exceeded |
502 | The payment provider failed; try again |
503 | A dependency, such as billing, isn't available |
Error codes
| Code | Status | When |
|---|---|---|
UNAUTHORIZED | 401 | No Authorization: Bearer header |
TOKEN_EXPIRED | 401 | The access or refresh token is invalid or expired |
TOKEN_REVOKED | 401 | The refresh token was revoked, for example after a password reset |
INVALID_CREDENTIALS | 401 | Wrong email or password |
EMAIL_NOT_VERIFIED | 403 | The email isn't verified. A new code is sent automatically on sign-in. |
EMAIL_EXISTS | 409 | An account already uses this email |
ALREADY_VERIFIED | 400 | The email is already verified |
INVALID_CODE | 400 | A verification or reset code is wrong or expired |
WEAK_PASSWORD | 422 | The password fails the password rules |
VALIDATION_ERROR | 422 | A field is missing or invalid |
USER_NOT_FOUND | 404 | The account doesn't exist |
PLAN_NOT_FOUND | 404 | The plan ID doesn't exist |
PLAN_NOT_PURCHASABLE | 422 | The plan is free or custom (Enterprise) |
CHECKOUT_REQUIRED | 402 | The plan change needs checkout first |
NO_SUBSCRIPTION | 404 | There's no paid plan to cancel or reactivate |
BILLING_UNAVAILABLE | 503 | Billing isn't configured |
BILLING_ERROR | 502 | The payment provider failed |
KEY_LIMIT_REACHED | 403 | The plan's API key limit is reached |
KEY_NOT_FOUND | 404 | The API key doesn't exist or is already revoked |
UPGRADE_REQUIRED | 403 | Team seats need a Team or Enterprise plan |
SEAT_LIMIT_REACHED | 403 | No seats left |
ALREADY_INVITED | 409 | This email already has a seat or invitation |
OWNER_SEAT | 422 | The owner already has a seat |
SEAT_NOT_FOUND | 404 | The seat doesn't exist |
NOT_A_MEMBER | 404 | You aren't on a team |
Model API errors
The model API (POST /v1/chat/completions and GET /v1/models) uses a different shape. The body is an error object with a human-readable message, the error's type and a machine-readable code:
{
"error": {
"message": "The model \"my-model\" does not exist. Available models: coaade-code-2, coaade-mind-1.",
"type": "not_found_error",
"code": "model_not_found"
}
}type is one of authentication_error, permission_error, not_found_error, invalid_request_error, rate_limit_error or server_error. An error about one field of the request also has param, naming it. Branch on code. The Call models page lists every code with its status.
Tool calling
A request with tools that fails one of these checks gets 400 invalid_tools, with param naming the field:
{
"error": {
"message": "messages[2].tool_call_id is \"call_x\", which is not one of the tool calls in messages[1].",
"type": "invalid_request_error",
"param": "messages[2].tool_call_id",
"code": "invalid_tools"
}
}| Check | param |
|---|---|
tools is an array of at most 128 tools, at most 200,000 characters as JSON | tools |
Each tool is { "type": "function", "function": { ... } } | tools[i], tools[i].type, tools[i].function |
| A name is 1 to 64 letters, digits, underscores or dashes, different for each tool | tools[i].function.name |
description is a string | tools[i].function.description |
parameters is a JSON Schema object with "type": "object", or has no type | tools[i].function.parameters |
tool_choice is "auto", "none", "required" or a function in tools; "required" needs tools | tool_choice |
parallel_tool_calls is true or false | parallel_tool_calls |
An assistant message's tool_calls is an array of calls, each with an id of its own, type "function", a valid name and arguments that are a JSON object, as a string | messages[i].tool_calls[j] and its fields |
A tool message has a tool_call_id | messages[i].tool_call_id |
A tool message follows the assistant message whose call it answers, with only other tool messages between | messages[i] |
Its tool_call_id is one of that message's calls, answered once | messages[i].tool_call_id |
| Every call has its tool message before the next user or assistant message | messages[i].tool_calls |
functions, function_call and function messages, the older form of tools, get 400 unsupported_parameter: send tools and tool messages instead.
Handling expired tokens
When a call returns 401 with TOKEN_EXPIRED, refresh and retry once. If the refresh also fails, sign the user in again.
async function call(path: string, init: RequestInit = {}) {
let res = await fetch(`https://api.coaade.com${path}`, withAuth(init, tokens.access));
if (res.status === 401) {
tokens = await refresh(tokens.refresh); // POST /v1/auth/refresh
res = await fetch(`https://api.coaade.com${path}`, withAuth(init, tokens.access));
}
return res;
}