v1 error format - flat error strings and the HTTP status meanings.
v1 errors are a single string field:
{
"error": "invalid api key"
}No code, param, request_id, or type - branching on errors in v1 means string-matching, which is brittle. This is one of the main reasons to migrate.
| Status | Meaning |
|---|---|
400 | Malformed request - message describes the problem |
401 | Missing or invalid API key |
403 | Not permitted |
404 | Resource not found |
429 | Rate limited - retry after a delay (no Retry-After in v1) |
500 | Platform error - retry with backoff |
function errorCode(status, body) {
if (body?.error && typeof body.error === "object") {
return body.error.code; // v2
}
return `v1_http_${status}`; // v1 - map status only
}