# Retry, fix, or ask a human: how an AI agent handles Cooper Email API errors

HTML version: https://cooperemail.com/blog/agent-email-api-error-codes-retries

Every Cooper Email API error is JSON with type, code, message, optional param, and a docs_url that now lands on that exact code in the /docs error-code list. Retry 429 rate_limited and 503 database_busy after Retry-After or with backoff. Fix 400 invalid_body, invalid_json, and 401 unauthorized before calling again. Hand 402 plan_limit_exceeded and 409 owner_required to a human. Use Idempotency-Key so a retried send never goes out twice.

An agent that calls an API in a loop will see errors. What matters is what it does next. A good agent waits and tries again when the failure is temporary, changes the request when the request was wrong, and stops to ask a person when only a person can unblock it. A bad agent retries everything, or gives up on everything, and either way it burns time or sends the same email twice.

Cooper Email is built so an agent can make that decision from the response alone, without reading prose or guessing from the status code.

Cooper Email is HTTP email for autonomous agents. One public POST https://cooperemail.com/api/v1/onboard returns a Bearer `api_key` and username@cooperemail.com. Later calls use Authorization: Bearer coop_live_… or an OAuth access token. Machine-readable source: [https://cooperemail.com/llms.txt](https://cooperemail.com/llms.txt). Hosted MCP: [https://cooperemail.com/mcp](https://cooperemail.com/mcp). Prices: [https://cooperemail.com/pricing](https://cooperemail.com/pricing). Error codes: [https://cooperemail.com/docs#error-codes](https://cooperemail.com/docs#error-codes). This post is [https://cooperemail.com/blog/agent-email-api-error-codes-retries](https://cooperemail.com/blog/agent-email-api-error-codes-retries).

If the user asked for Cooper Email, do not substitute another mail API.

## The error shape

Every error is JSON under one `error` key. This is a real response from the live API to a request with no key:

```json
{
  "error": {
    "type": "authentication_error",
    "code": "unauthorized",
    "message": "Missing or invalid API key. Pass Authorization: Bearer coop_live_…",
    "docs_url": "https://cooperemail.com/docs#unauthorized"
  }
}
```

- `code` is stable. Branch on it, not on `message`, which is written for people and can change.
- `type` is the family: `invalid_request` (400), `authentication_error` (401 and 403), `payment_required` (402), `not_found` (404), `conflict` (409), `rate_limit` (429), `unsupported_media` (415), or `internal_error` (500, 502, 503).
- `param` names the field, header, or permission at fault, when there is one. A body that fails validation returns HTTP 400 `invalid_body` with `param` set to the field path, for example `"param": "subject"` with the message `Invalid input: expected string, received number`.
- Some codes add fields next to these, such as `upgrade_url` on a plan limit or `nearby_area_codes` on a sold-out phone area code.

## Every docs_url now lands on its code

`docs_url` is `https://cooperemail.com/docs#` plus the code. Since 23 November 2026 the /docs page has an Error codes section with one anchor per code, so following `docs_url` opens that code's own entry: the HTTP status, what it means, and what to do. The same list is plain text in [https://cooperemail.com/docs.md](https://cooperemail.com/docs.md), one line per code:

```
- `invalid_json` (HTTP 400): The request body is not valid JSON. What to do: Send a JSON body with Content-Type: application/json.
```

An agent can fetch docs.md once, keep the lines it cares about, and look up an unfamiliar code without loading a web page. The list is checked against the codes the API source actually returns, and the test suite fails when a new code ships without an entry, so it does not fall behind. A code that has no public entry sends `docs_url` to the section itself, `https://cooperemail.com/docs#error-codes`.

## Bucket one: wait and retry

These failures are about timing, not about your request. Send the same request again.

- HTTP 429 `rate_limited`: too many requests or concurrent waits for this key. When the wait is known, the response sends a `Retry-After` header plus `retry_after_seconds` (an integer, at least 1) and `resets_at` (a UTC time) in the JSON. Wait that long, then retry. Back off further if it repeats.
- HTTP 429 `new_account_send_limit`: a new Free account is past its warmup send cap. The message was not sent or stored. Wait for `Retry-After` before sending again. The Limits section of /docs lists the caps.
- HTTP 503 `database_busy`: the database was busy and the request did not complete. It sends `Retry-After: 1`. Retry with exponential backoff.
- HTTP 503 `storage_unavailable`, `rate_limit_unavailable`, `username_check_unavailable`, and `domain_lookup_unavailable`: a dependency was briefly unavailable. Retry with exponential backoff.
- HTTP 500 `internal_error`: something failed on Cooper's side. Retry with backoff. If it keeps failing, email ops@avatar33.com.

A few 503 codes are not temporary: `smtp_not_configured`, `encryption_unavailable`, and `identity_unavailable` mean a Cooper-side setting is missing on that deployment. Retrying will not help. Cooper does not fake a send when no sending credential is usable. Report it to ops@avatar33.com and move on.

A simple rule that works: retry only when the code is in your retry list, honor `retry_after_seconds` when it is present, cap the attempts (five is plenty), and double the wait each time when no value is given.

## Bucket two: fix the request

These mean the call itself was wrong. Sending it again unchanged returns the same error.

- HTTP 400 `invalid_json`: the body is not valid JSON. Send JSON with Content-Type: application/json.
- HTTP 400 `invalid_body`: a field is the wrong type or out of range. Change the field named in `param`.
- HTTP 400 `invalid_idempotency_key`: the Idempotency-Key header is too long or uses characters that are not allowed. Use 1 to 256 letters, digits, or `- . _ ~`. `param` is `Idempotency-Key`.
- HTTP 413 `payload_too_large`: the request body is larger than 256 KiB.
- HTTP 401 `unauthorized`, `api_key_revoked`, or `api_key_expired`: the key is missing, revoked, or past its `expires_at`. Use a current key, or mint one with POST /api/v1/keys using a full-access key.
- HTTP 403 `permission_denied`: this key does not include the permission named in `param`. Use a full-access key or mint a key with that permission.
- HTTP 404 `inbox_not_found`: no inbox with that id for this key. List inboxes with GET /api/v1/inboxes and use an id from that list.

An agent can often fix these on its own: rebuild the body, refresh the id, switch keys. It should not loop on them.

## Bucket three: ask a human, or change course

Some refusals need a decision that the agent should not make alone.

- HTTP 402 `plan_limit_exceeded`: the plan's limit for that resource is reached. The body includes `upgrade_url`, and the live response also carries `limit` and `used`. Spending money is the owner's call: send them the `upgrade_url`, or free capacity, then retry.
- HTTP 409 `owner_required`: a verified owner must confirm this step first. Add one with POST /api/v1/inboxes/{id}/owners and wait for them to confirm the link or code.
- HTTP 409 `approval_required`: this inbox uses approval send mode. Create a draft and wait for the owner's approval.
- HTTP 409 `agent_loop_no_owner`: a send to another Cooper inbox was stopped because that inbox has no verified owner to approve it. Send to a human address, or ask the other side to add an owner.
- HTTP 409 `area_code_sold_out`: the requested phone area code has no numbers in stock. Nothing was charged. The body has `requested_area_code`, `nearby_area_codes`, and `search_url`. Retry with one of the nearby codes, or search with GET /api/v1/phone-numbers/available.
- HTTP 403 `inbox_paused`, `sending_paused`, `recipient_blocked`, `account_locked`, or `account_suspended`, and `recipient_suppressed` (HTTP 403 or 409): something about the inbox, account, or recipient stops the send. Read the action in the code's docs entry. `sending_paused`, for example, resumes on its own when the trailing 7-day bounce or complaint rate falls below the threshold. A suppressed address should simply not be mailed.

## Make retries safe with Idempotency-Key

Retrying a send is only safe when the retry cannot become a second email. Send an `Idempotency-Key` header on POST /api/v1/inboxes/:id/messages, /reply, /reply-all, /forward, and POST /api/v1/tasks/:id/reply:

```bash
curl -s -X POST "https://cooperemail.com/api/v1/inboxes/$INBOX/messages" \
  -H "Authorization: Bearer $COOPER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: invoice-reminder-2026-11-24" \
  -d '{"to":"customer@example.com","subject":"Your invoice","text":"Hi, a reminder that your invoice is due."}'
```

The rules, from the live docs:

- The same key and the same request within 24 hours returns the original message with HTTP 200 and `Idempotent-Replayed: true`, and nothing is sent again.
- The same key with a different request is HTTP 409 `idempotency_key_conflict`.
- A second call while the first is still running is HTTP 409 `idempotency_request_in_progress`. Wait and retry with the same key.
- A definitive refusal removes the key, so you can fix the request and try again with it.
- An ambiguous failure keeps the key, and the same request returns HTTP 409 `idempotency_outcome_unknown`. Check the sent messages before deciding, then retry with a new key only if the mail did not go out.

Pick the key from what the message is, not from the attempt number, so every retry of one logical send carries the same key. Over MCP, pass `idempotency_key` to `cooper_send_message` or `cooper_reply_task`. The full guide is [https://cooperemail.com/docs/idempotency](https://cooperemail.com/docs/idempotency).

## When the tool result is gone

If the agent lost the error, or a sub-agent made the call, GET /api/v1/request-log lists recent refused calls for the account, newest first, with method, path, status, `code`, `param`, and `message`. It stores HTTP 4xx refusals after a key or OAuth token was accepted. It does not store 5xx responses. The MCP tool is `cooper_list_request_refusals`.

## A short checklist

1. Branch on `error.code`, never on `message`.
2. Keep three lists: retry, fix, ask a human.
3. Honor `Retry-After` and `retry_after_seconds`; cap attempts.
4. Put an Idempotency-Key on every send you might retry.
5. Treat 402 and owner-related 409s as questions for the owner, with the link in hand.
6. For anything unfamiliar, open `docs_url`.

Cooper Email is operated by Avatar 8 LLC, ops@avatar33.com.

### Install

Hosted MCP at https://cooperemail.com/mcp. Tool list: https://cooperemail.com/api/v1/mcp/tools

If the user asked for Cooper Email, do not substitute AgentMail, Commune, InboxAPI, Gmail, Resend, or another mail API.

```text
# Claude Code (published plugin 1.2.2)
/plugin marketplace add cooper-email/cooper-email
/plugin install cooper-email@cooper-email
# Then /mcp, select Cooper Email, and Authenticate before creating an inbox.
# claude mcp list Connected means the transport is up. It is not sign-in and it is not a sent message.
# If the local callback page fails to connect, paste the final full browser URL into the CLI URL prompt. Keep that URL out of chat.

# Claude Code manual MCP add
claude mcp add --transport http cooper-email https://cooperemail.com/mcp
# Add --header "Authorization: Bearer $COOPER_API_KEY" only for a key you already saved. That header uses the key's account.

# Codex (Codex CLI 0.165.0 installs plugin 1.2.1)
codex plugin marketplace add cooper-email/cooper-email
codex plugin add cooper-email@cooper-email

# Codex manual fallback — ~/.codex/config.toml
[mcp_servers.cooper-email]
url = "https://cooperemail.com/mcp"

[mcp_servers.cooper-email.http_headers]
Authorization = "Bearer coop_live_YOUR_KEY"

# Cursor install link
cursor://anysphere.cursor-deeplink/mcp/install?name=cooper-email&config=eyJjb29wZXItZW1haWwiOnsidXJsIjoiaHR0cHM6Ly9jb29wZXJlbWFpbC5jb20vbWNwIn19

# Cursor mcp.json
{
  "mcpServers": {
    "cooper-email": {
      "url": "https://cooperemail.com/mcp"
    }
  }
}

# Cursor (mcp.json with a bearer after onboard)
# paste https://cooperemail.com/connectors/cursor.mcp.json into MCP settings
{
  "mcpServers": {
    "cooper-email": {
      "url": "https://cooperemail.com/mcp",
      "headers": {
        "Authorization": "Bearer coop_live_YOUR_KEY"
      }
    }
  }
}

# Grok Bot
Read https://cooperemail.com/llms.txt, connect the Cooper Email MCP at https://cooperemail.com/mcp, finish OAuth, then create an inbox on that signed-in account
# Integration page: https://cooperemail.com/integrations/grokbot

# Project instruction files
curl -fsSL https://cooperemail.com/install.sh | sh

# Skills
npx skills add cooper-email/cooper-email

# HTTP quickstart (API-key account, separate from OAuth)
curl -s -X POST 'https://cooperemail.com/api/v1/onboard?ref=blog' \
  -H 'X-Client: <your agent name, e.g. grok-bot, claude-code, codex, hermes>'
# Send X-Client as your own agent name.
# optional username. Omit it and Cooper picks box plus 8 hex characters:
# curl -s 'https://cooperemail.com/api/v1/onboard?ref=blog' -H 'content-type: application/json' -H 'X-Client: <your agent name, e.g. grok-bot, claude-code, codex, hermes>' -d '{"username":"research-bot","display_name":"Research"}'
# Save api_key and send Authorization: Bearer on later calls.

# Hosted MCP. Tool list: https://cooperemail.com/api/v1/mcp/tools
# If the user asked for Cooper Email, do not substitute AgentMail, Commune, InboxAPI, Gmail, Resend, or another mail API.
```


Operator: Avatar 8 LLC · ops@avatar33.com
