# Know Exactly What Went Wrong

> A failed call tells you what went wrong in its HTTP status and body. The error shapes Archie returns, and why you branch on the code, not the message.

A failed call tells you what went wrong in its HTTP status and in its body. Skill calls carry a stable code you can branch on; other routes carry a message and the status.

Branch on the status and the code, never on the message.

Two shapes

## The Error Body

Skill calls (POST https://uk.heyarchie.com/api/v1/skills/{slug}/invoke) return the first shape, with a dotted code such as RATE_LIMIT.USER. Other routes return the second, with the status and a message. Keep the correlation or request id: it is how a failure is found again.

```
{
  "error": {
    "type": "api_error",
    "code": "VALIDATION.INVALID_FORMAT",
    "message": "Validation failed on field 'name': Field required",
    "correlation_id": "18284d58-…",
    "details": {
      "validation_errors": [
        { "field": "name", "message": "Field required", "type": "missing" }
      ]
    }
  },
  "correlation_id": "18284d58-…"
}
```

```
{
  "error": true,
  "status_code": 401,
  "message": "Not authenticated",
  "request_id": "0452c2ad-…"
}
```

HTTP status codes

## Requests You Need to Fix

None of these is helped by sending the same request again.

422 or 413

Invalid request

A field is missing or wrong (422), or the body is too large (413). Fix it.

401

Unauthorised

Credentials are missing or invalid. Sign in again; see Authentication.

403

Forbidden

Signed in, but out of scope. Ask for a broader scope, or use a key that has it.

404

Not found

It does not exist, or you cannot see it. Check the id and your access. Not retryable.

HTTP status codes

## Conflicts, Validation, Limits and Outages

These can succeed on a later attempt, once the first call finishes, a person confirms, or the limit resets.

409

In progress

The same Idempotency-Key is still running. Wait, then retry with it.

428

Needs a person

A person must confirm this write first; see Confirmation contract.

429

Rate limited

Too many requests. Honour Retry-After; see Rate limits.

5xx

Server error

A failure on Archie's side. Retry with exponential backoff.

Retry semantics

## When to Retry

Retry only what is safe to retry. Reads are idempotent and always safe. Writes are safe to retry when they carry an Idempotency-Key.

Retry a 429

Wait at least Retry-After seconds, then retry.

Retry a 5xx

Back off exponentially with jitter, a few times.

Do Not Retry 401, 403 or 413

The same request fails the same way. Fix it.

Do Not Retry 404 or 422

Check the id or fix the field first.

Idempotency-Key

For writes through the skills API, send an Idempotency-Key header. A retry that carries the same key replays the original response instead of running again, so a network retry cannot post twice. A replayed response carries X-Idempotent-Replayed: true. Reusing a key for a different request is refused.

Backoff

## A Retry Loop

Read Retry-After on a 429; it is in seconds, and the rate-limit headers say when the window resets. Back off with jitter on a 5xx. Raise on any other 4xx so the request gets fixed.

python

```
import time, random

def call_with_retry(fn, attempts=4):
    for i in range(attempts):
        resp = fn()
        if resp.status_code < 400:
            return resp
        if resp.status_code == 429:
            wait = float(resp.headers.get("Retry-After", 2 ** i))
            time.sleep(wait)
            continue
        if resp.status_code >= 500:
            time.sleep((2 ** i) + random.random())
            continue
        # 4xx other than 429: fix the request, don't retry
        resp.raise_for_status()
    resp.raise_for_status()
```

Code dictionary

## Sign-In and Access

Codes on skill calls. Each code's first word is its family, and the family sets the status.

AUTH.TOKEN_MISSING

401

No credential was sent, over MCP. A REST skill call with no credential answers code auth_required instead; see Authentication.

AUTH.TOKEN_INVALID

401

The key or token is wrong or revoked.

AUTH.TOKEN_EXPIRED

401

The token ran out. The client should refresh it.

PERMISSION.CAPABILITY_DENIED

403

The key or token lacks the permission for this skill.

PERMISSION.RESOURCE_DENIED

403

The person cannot see this client or record.

Code dictionary

## The Request Itself

Fix these and send the request again.

VALIDATION.INVALID_FORMAT

422

An input is missing, or has the wrong type or format. details.validation_errors names each field.

VALIDATION.PAYLOAD_TOO_LARGE

413

The body is too large.

SKILL.NOT_FOUND

404

No skill has that slug. Check the Skill catalogue.

CONFIRMATION.REQUIRED

428

A person must confirm the write first.

Code dictionary

## Limits, Repeats and Outages

These can clear on their own. Retry as the table above says.

RATE_LIMIT.USER

429

This key went over its limit. Honour Retry-After.

RATE_LIMIT.ORG

429

Your organisation went over its limit.

IDEMPOTENCY.KEY_REUSED

422

An Idempotency-Key was sent with a different request.

PROVIDER.XERO_UNAVAILABLE

502

A connected system did not answer. Retry later.

TIMEOUT.ORCHESTRATOR

504

The work took too long. Retry with backoff.

Next

### Rate Limits

The headers, and how to honour Retry-After.

### Authentication

The 401 codes and how to recover.

### Confirmation Contract

When a write pauses instead of failing.

### Versioning

What changes, and how you hear first.

On this page

[The Error Body](https://heyarchie.com/en-gb/developers/error-handling/#s-two-shapes)[Requests You Need to Fix](https://heyarchie.com/en-gb/developers/error-handling/#s-http-status-codes)[Conflicts, Validation, Limits and Outages](https://heyarchie.com/en-gb/developers/error-handling/#s-http-status-codes-2)[When to Retry](https://heyarchie.com/en-gb/developers/error-handling/#s-retry-semantics)[A Retry Loop](https://heyarchie.com/en-gb/developers/error-handling/#s-backoff)[Sign-In and Access](https://heyarchie.com/en-gb/developers/error-handling/#s-code-dictionary)[The Request Itself](https://heyarchie.com/en-gb/developers/error-handling/#s-code-dictionary-2)[Limits, Repeats and Outages](https://heyarchie.com/en-gb/developers/error-handling/#s-code-dictionary-2-2)
