Know Exactly What Went Wrong
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.
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-…"
}Requests You Need to Fix
None of these is helped by sending the same request again.
A field is missing or wrong (422), or the body is too large (413). Fix it.
Credentials are missing or invalid. Sign in again; see Authentication.
Signed in, but out of scope. Ask for a broader scope, or use a key that has it.
It does not exist, or you cannot see it. Check the id and your access. Not retryable.
Conflicts, Validation, Limits and Outages
These can succeed on a later attempt, once the first call finishes, a person confirms, or the limit resets.
The same Idempotency-Key is still running. Wait, then retry with it.
A person must confirm this write first; see Confirmation contract.
Too many requests. Honour Retry-After; see Rate limits.
A failure on Archie's side. Retry with exponential backoff.
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.
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.
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.
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()Sign-In and Access
Codes on skill calls. Each code's first word is its family, and the family sets the status.
No credential was sent, over MCP. A REST skill call with no credential answers code auth_required instead; see Authentication.
The key or token is wrong or revoked.
The token ran out. The client should refresh it.
The key or token lacks the permission for this skill.
The person cannot see this client or record.
The Request Itself
Fix these and send the request again.
An input is missing, or has the wrong type or format. details.validation_errors names each field.
The body is too large.
No skill has that slug. Check the Skill catalogue.
A person must confirm the write first.
Limits, Repeats and Outages
These can clear on their own. Retry as the table above says.
This key went over its limit. Honour Retry-After.
Your organisation went over its limit.
An Idempotency-Key was sent with a different request.
A connected system did not answer. Retry later.
The work took too long. Retry with backoff.