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.

CodeTypical statusMeaningFix
invalid_input400A required parameter is missing, malformed, or out of range.Compare the request with the endpoint reference.
invalid_input413The request body or q parameter is too large.Shorten the question or body.
invalid_input404 or 409A resource was not found, or a state conflict blocked the action.Check the identifier and current state.
unsupported_query422The /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_currency400A currency code is not recognized, or a base currency is unsupported.Use an ISO 4217 code from /currencies.
unknown_currency404No history exists for the requested currency.Try a supported currency or a wider date range.
unknown_ppp404No PPP factor exists for the country and year.Check the alpha-3 code and year on /countries.
rate_not_found404No rate snapshot exists for the date.Use a more recent date, or omit date for the latest.
unauthorized401The key is missing, malformed, revoked, or its owner is suspended.Send a valid Authorization: Bearer <key> or x-api-key.
unauthorized403A dashboard route rejected the caller’s membership or role.Use an account with access to that organization.
billing_past_due402Billing is past due and live API access is paused.An owner or admin must clear payment. Test keys keep working at Free limits.
forbidden403The 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_limited429The per-minute limit, monthly quota, hard cap, or AI credit balance was exceeded.Wait, upgrade, raise the cap, or buy AI credits.
internal_error500, 502, 503An 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

StatusRetry?Guidance
429 from the per-minute limiterYes, after a delayHonor the Retry-After header in seconds.
429 from the monthly quota, hard cap, or AI creditsOnly after a changeWaiting a few seconds will not help. Wait for the next period, upgrade, raise the cap, or buy credits.
500, 502, 503YesUse exponential backoff with jitter, for example 1s, 2s, 4s. Cap attempts.
400, 401, 402, 403, 404, 413, 422NoFix the request, key, plan, or billing state first.

Data endpoints are GET; retries are safe.

Authentication and plan errors

Common causes:

  • A missing Bearer prefix in Authorization.
  • 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.

  • amount must 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-DD and cannot be in the future.
  • q on /ai must 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.