Documentation
API Error Codes and How to Fix Them
Every CurrencyCore API error code, the HTTP statuses that carry it, what causes it, and which failures are safe to retry. Includes 401, 402, 429, and 5xx.
All CurrencyCore API errors use the same JSON envelope:
{
"error": {
"code": "unknown_currency",
"message": "Currency code 'XYZ' is not recognized.",
"details": {}
}
}
details is optional and is omitted when there is nothing extra to return. The
code is stable for programmatic handling; the message may change.
Error code reference
A code can carry more than one status; check both.
| Code | Typical status | Meaning | Fix |
|---|---|---|---|
invalid_input | 400 | A required parameter is missing, malformed, or out of range. | Compare the request with the endpoint reference. |
invalid_input | 413 | The request body or q parameter is too large. | Shorten the question or body. |
invalid_input | 404 or 409 | A resource was not found, or a state conflict blocked the action. | Check the identifier and current state. |
unsupported_query | 422 | The /ai question is outside currency, FX, or PPP scope. | Ask an in-scope question. The model was consulted, so this can consume a credit. |
unknown_currency | 400 | A currency code is not recognized, or a base currency is unsupported. | Use an ISO 4217 code from /currencies. |
unknown_currency | 404 | No history exists for the requested currency. | Try a supported currency or a wider date range. |
unknown_ppp | 404 | No PPP factor exists for the country and year. | Check the alpha-3 code and year on /countries. |
rate_not_found | 404 | No rate snapshot exists for the date. | Use a more recent date, or omit date for the latest. |
unauthorized | 401 | The key is missing, malformed, revoked, or its owner is suspended. | Send a valid Authorization: Bearer <key> or x-api-key. |
unauthorized | 403 | A dashboard route rejected the caller’s membership or role. | Use an account with access to that organization. |
billing_past_due | 402 | Billing is past due and live API access is paused. | An owner or admin must clear payment. Test keys keep working at Free limits. |
forbidden | 403 | The key is valid but a plan gate, history window, toggle, or role blocks the request. | Read the message and adjust the plan, date, or setting. |
rate_limited | 429 | The per-minute limit, monthly quota, hard cap, or AI credit balance was exceeded. | Wait, upgrade, raise the cap, or buy AI credits. |
internal_error | 500, 502, 503 | An unexpected server, provider, or upstream failure occurred. | Retry with backoff; contact support if it persists. |
402 versus 403
A past-due organization receives 402 with the code billing_past_due. A
plan gate or disabled feature receives 403 with the code forbidden. Branch
on the status, then read the message.
Retry guidance
| Status | Retry? | Guidance |
|---|---|---|
429 from the per-minute limiter | Yes, after a delay | Honor the Retry-After header in seconds. |
429 from the monthly quota, hard cap, or AI credits | Only after a change | Waiting a few seconds will not help. Wait for the next period, upgrade, raise the cap, or buy credits. |
500, 502, 503 | Yes | Use exponential backoff with jitter, for example 1s, 2s, 4s. Cap attempts. |
400, 401, 402, 403, 404, 413, 422 | No | Fix the request, key, plan, or billing state first. |
Data endpoints are GET; retries are safe.
Authentication and plan errors
Common causes:
- A missing
Bearerprefix inAuthorization. - A key revoked within the last 5 minutes and still in the key cache.
- A live key calling a data endpoint on the Free plan, or a historical date outside the plan window.
- The AI endpoint or MCP access disabled for the organization.
See Authentication for the full 401 checklist and Rate Limits and Plan Quotas for plan gates.
Validation errors
invalid_input, unknown_currency, unknown_ppp, and rate_not_found are
request-shape or data-availability problems. They will not resolve on their own.
amountmust be a number and greater than zero where required.- Currency codes are three letters from the supported list.
- PPP requests pair a currency with a country, such as
USD:USA. - Dates use
YYYY-MM-DDand cannot be in the future. qon/aimust be present and within the input budget.
TypeScript
Error codes are exported as a typed constant from @currencycore/shared:
import { ERROR_CODES, type ApiError } from "@currencycore/shared";
const body = (await res.json()) as ApiError;
if (body.error?.code === ERROR_CODES.RATE_LIMITED) {
// Read Retry-After when present, then back off.
}
ERROR_CODES contains INVALID_INPUT, UNSUPPORTED_QUERY, UNKNOWN_CURRENCY,
UNKNOWN_PPP, RATE_NOT_FOUND, UNAUTHORIZED, FORBIDDEN, BILLING_PAST_DUE,
RATE_LIMITED, and INTERNAL.