Reference
Errors
Every error from the CortexPay API has the same JSON shape and a stable, machine-readable code. Switch on the code, show the message.
Code samples in
Error shape#
400 Bad Request
{
"error": {
"code": "validation_failed",
"message": "rules.maxPerPayment: Expected integer base units",
"details": [{ "path": "rules.maxPerPayment", "message": "Expected integer base units" }]
}
}code is stable and safe to branch on. message is written for people and may change. details is optional and depends on the code: field issues for validation_failed, retryAfter for rate_limited.
Status codes#
| Status | Code | Meaning |
|---|---|---|
| 400 | bad_request | A malformed request: missing header, bad cursor, wrong parameter. |
| 400 | validation_failed | The body did not match the schema. details lists up to 8 { path, message } issues. |
| 401 | unauthorized | No valid session or API key: missing, malformed, revoked or expired, or its workspace has expired. |
| 403 | forbidden | Authenticated, but the role or the key's scopes do not allow this. The message names what is missing. |
| 404 | not_found | The resource does not exist in this workspace. Other workspaces' resources also return 404. |
| 409 | various | Conflicts with the current state; see below. |
| 413 | payload_too_large | Sandbox x402 resources accept bodies up to 16 KB. |
| 422 | various | Well-formed but not allowed right now; see below. |
| 429 | rate_limited | Rate limit hit. The Retry-After header and details.retryAfter give the seconds to wait. |
| 500 | internal_error | Unexpected failure. Safe to retry with the same Idempotency-Key. |
| 503 | various | A dependency this call needs is unavailable or not configured on this deployment, for example the AI assistant. |
Common codes#
| Code | Status | Meaning |
|---|---|---|
idempotency_key_reused | 409 | The Idempotency-Key was already used with a different body. |
request_in_progress | 409 | A request with this Idempotency-Key is still running. Retry shortly. |
quote_expired | 409 | The 5-minute quote expired. Request a new quote. |
quote_closed | 409 | The quote was already used or closed. |
version_conflict | 409 | The policy changed since you read it. Reload and publish against the latest version. |
already_paused / not_paused | 409 | The agent is already in the state you asked for. |
agent_revoked / already_revoked | 409 | Revocation is permanent. |
approval_decided / approval_expired | 409 | The approval is no longer pending. |
key_revoked | 409 | The API key was already revoked. |
last_owner / last_workspace | 409 | A workspace always keeps one owner, and you always keep one workspace. |
policy_invalid | 422 | The rules are inconsistent; details.fields lists each problem. |
policy_archived | 422 | Agents on an archived policy cannot pay. |
sandbox_only | 422 | A sandbox workspace tried to call a non-sandbox service or URL. |
sandbox_service | 422 | A live workspace tried to call a sandbox service. |
service_unavailable | 422 | The service is not operational. |
unsupported_payment_requirements | 422 | The service offered no payment option CortexPay can sign. |
payments_frozen | 422 | New payment authorizations are frozen for this workspace. |
live_funding_unavailable | 422 | Live agents are funded on-chain, not through CortexPay. |
funding_cap / insufficient_balance | 422 | Sandbox funding limits, or not enough balance to withdraw. |
insufficient_credits | 422 | Not enough infrastructure credits for the action. |
unsafe_url | 422 | The URL is not public HTTPS (private, loopback or link-local addresses are refused). |
webhook_limit / key_limit | 422 | The workspace reached its number of webhook endpoints or API keys. |
rate_limited | 429 | Too many requests in this minute. Wait Retry-After seconds. |
internal_error | 500 | Something failed on CortexPay's side; the request was not completed. |
Refusals are not errors#
A payment the policy refuses, a service that fails after payment, or a payment waiting for approval is a normal result of POST /api/services/request or /api/payments/authorize: HTTP 200 (or 202 while waiting) with status, evaluation.reasonCode and error in the body.
Retrying safely
Retry 429, 5xx and network failures with the same Idempotency-Key. Do not retry other 4xx responses unchanged: fix the request and send it with a new key. A key that already failed can replay the same error, and a key reused with a different body returns idempotency_key_reused.