# Errors that tell you what to do next.

> Every Dizo error has a stable code to branch on, a plain-English fix, and retry hints. Agents and scripts can recover without a human reading logs.

Each Dizo error returns a stable `error.code` for your code, an `error.fix` sentence for people and models, and `retryable` plus `retry_after` so nobody has to guess.

## Highlights
- **Stable codes.** Branch on `error.code`, such as `monthly_cap_reached`. Codes are stable, not prose that changes.
- **A fix in plain English.** `error.fix` says what to change, in a sentence a person or a model can act on.
- **Retry hints.** `error.retryable` and `error.retry_after` say whether and when to try again.
- **Misses are not failures.** A lookup that finds nothing returns `404 not_found` and costs nothing.
- **Budget errors are explicit.** Hit the monthly cap and you get `402 monthly_cap_reached`, not a vague failure.
- **Traceable.** Every response has an `x-dizo-request-id` to quote in logs and feedback.

## Steps
1. **Check the status** — Success, a free miss, or an error object.
2. **Branch on the code** — Map `error.code` values to actions in your client.
3. **Retry only if allowed** — When `retryable` is true, wait `retry_after` seconds and resend with the same idempotency key.
4. **Otherwise follow the fix** — Surface `error.fix` to the agent or the human and change the request.

## APIs used
| API | Endpoint | Credits | Charged | Reference |
|---|---|---|---|---|
| Key info | `GET /v1/me` | Free | Never | [docs](https://dizo.ai/docs/me.md) |
| Balance & usage | `GET /v1/billing` | Free | Never | [docs](https://dizo.ai/docs/billing.md) |
| Email finder | `POST /v1/email/find` | 1 credit | Only if found | [docs](https://dizo.ai/docs/email-find.md) |
| Spend limits | `PUT /v1/billing/limits` | Free | Never | [docs](https://dizo.ai/docs/billing-limits.md) |


## Why error design matters more when a model is the client

Most API errors were designed for a developer reading a log after something broke. A status code, a short message, maybe a link. That works when a person is in the loop. It works badly when the client is an agent running unattended, or a workflow step that has to decide on its own whether to retry, skip the record or stop the whole run.

An agent faced with a vague error tends to do one of two unhelpful things. It retries the same call until something gives, burning time and sometimes money, or it gives up and reports a failure that a person then has to debug. Neither is what you want from software that is supposed to save you work.

Dizo errors are built for that reader. Each one carries a stable code your program can branch on, a fix written in plain English that a model or a person can act on, and explicit retry guidance. The aim is simple: whoever receives the error should know what to do next without opening the docs.

## The anatomy of a Dizo error

Errors come back as an `error` object with four fields that matter. `error.code` is a short, stable identifier such as `monthly_cap_reached`. It is the field to branch on, because it does not change when the wording of a message is improved. `error.fix` is a sentence explaining what to change: raise a limit, correct a parameter, wait, or ask the account owner.

`error.retryable` is a boolean that answers the most common question directly: will sending this again help? `error.retry_after` gives the number of seconds to wait first when a retry is worthwhile. Together they replace the guesswork of inferring retry behaviour from HTTP status codes.

Alongside the body, every response has an `x-dizo-request-id` header. Log it. It ties an error to a specific request when you are debugging, and it is what you send to `POST /v1/feedback` if a successful result later turns out to be wrong.

## Two outcomes you will see often

The first is not really an error. When the email finder or another only-if-found lookup cannot return a result it stands behind, it responds with `404 not_found` and charges nothing. For the email finder, any address that does not validate ends this way. Your code should treat it as a normal outcome: record that no email was found, move on to the next record, and perhaps try again later with a better identifier such as a profile URL. Retrying the same body straight away will not change the answer.

The second is a budget stop. When the account reaches its monthly spend cap, calls return `402 monthly_cap_reached`. Retrying will not help until a person raises the cap or the month rolls over. The right response from an agent is to stop the job and tell its human, ideally with the numbers from `GET /v1/billing` so the decision is easy. The [monthly spend cap](/features/monthly-spend-cap) page explains how that ceiling works with auto-refill.

## A branching pattern that holds up

You do not need a large error-handling framework. A short decision tree covers nearly everything, and it is the same one the Dizo agent rules describe: on errors, branch on `error.code` and follow `error.fix`; retry only if `error.retryable` is true, after `error.retry_after` seconds.

- Success: read the data, log `x-dizo-credits-used`, continue.
- `404 not_found` on a lookup: record a free miss and continue.
- `402 monthly_cap_reached`: stop the job and alert a human.
- Any error with `retryable: true`: wait `retry_after` seconds, then resend the identical request with the same `Idempotency-Key`.
- Any error with `retryable: false`: do not resend unchanged. Pass `error.fix` to whoever can act on it, then change the request or stop.
- An unfamiliar code: treat it as not retryable, log the request id and the fix, and surface it.

## Why a fix field helps agents

Language models are good at following short, concrete instructions and poor at reverse-engineering what a terse message meant. A fix written as a plain sentence fits how they work. If a call fails because a request would exceed the key's per-request ceiling, a fix that says so lets the agent split the job into smaller requests on its own. If a call fails because the key is not allowed to use an endpoint, the agent learns not to try it again and can tell its human what access it lacks.

That is why the fix is worth passing straight back into the model's context when a tool call fails. Over the [MCP server](/mcp), tool errors reach the model as part of the tool result, so it can read the fix and adjust in the same turn. If you build your own loop on the REST API, include `error.code` and `error.fix` in the tool output you return to the model, not just a generic failure flag.

Keep humans in the loop for anything involving money. A fix that points to raising a cap or topping up is a prompt for a person, never for the agent. The Dizo agent rules are explicit that billing write calls need human approval.

## Preventing errors before they happen

The cheapest error is the one you never trigger. Call `GET /v1/me` at start-up, or `dizo_whoami` over MCP. It returns the key's scopes, its endpoint allow-list, `max_credits_per_request`, the remaining daily and monthly budget and the rate limits. An agent that reads this first can plan inside its limits instead of discovering them one failed call at a time.

For larger jobs, quote first. Add `"dry_run": true` to the request and you get the exact credit cost without spending anything, which tells you whether the job fits the remaining budget. Then send the real call with `max_credits` set as a hard ceiling. The Dizo rules suggest a dry run before any job that may exceed about 100 credits.

Finally, check the balance before long loops with `GET /v1/billing`. If monthly spend is close to the cap, stop and ask, rather than running until a `402` arrives halfway through the work.

## A worked example: an enrichment run that recovers on its own

Imagine a hypothetical agent asked to find emails for 600 conference attendees, sent as individual calls. It starts with `dizo_whoami` and sees 1,000 credits left this month. Email finder costs 1 credit only when found, so even a 100% hit rate fits. It goes ahead.

Along the way, 180 lookups return `404 not_found`. The agent logs them as misses and moves on; they cost nothing. A handful of calls fail with an error marked retryable with a short `retry_after`. The agent waits, resends each with its original idempotency key, and they succeed without any double charge. The run finishes with 420 emails found and 420 credits used, which is $10.50 at the pay-as-you-go rate of $0.025.

At no point did a person have to read a log. The only time the agent would have stopped and asked is if it had hit the monthly cap, because that error is not retryable and needs a human decision.

## Logging and monitoring

Treat error codes as metrics. Count them by code and by key. A rising rate of `not_found` on one workflow often means it is sending weak identifiers, such as company names instead of domains. Retryable errors that cluster at the same time of day may mean a job should be spread out. Any `402` is a sign that caps and expected usage are out of step.

It also helps to keep the fix text in your logs, not only the code. When a teammate opens an alert at the end of a long day, a sentence that says what to change is quicker to act on than a code they have to look up. For agent runs, write a short summary at the end of each job: calls made, credits used, misses, retries and any errors that stopped work. That summary is what the human reviewing the run actually reads.

Store the request id with every failure and every charge. If a verified email later bounces, report it through `POST /v1/feedback` with that id; confirmed reports within 30 days of purchase are refunded to your balance. See the [feedback reference](/docs/feedback) for the issue types.

## FAQ

### What fields does a Dizo error include?
A stable `error.code`, a plain-English `error.fix`, a boolean `error.retryable` and, when a retry makes sense, `error.retry_after` in seconds. Every response also has an `x-dizo-request-id` header.

### Should I branch on the message or the code?
The code. `error.code` is the field designed to be stable, while `error.fix` is written for reading. Use the code for logic and pass the fix to whoever has to act.

### Is a 404 from the email finder an error?
It means nothing was found that Dizo would stand behind. It costs nothing. Record a miss and move on rather than retrying the same request.

### What happens when I hit my monthly cap?
Calls return `402 monthly_cap_reached`. It is not retryable; a person needs to raise the cap or wait for the next month.

### When is it safe to retry?
When `error.retryable` is true. Wait `error.retry_after` seconds and resend the same request with the same `Idempotency-Key`, so it is never charged twice.

### Do agents see the fix text over MCP?
Tool errors are returned to the client as the tool result, so the model can read the code and the fix and adjust its next call.
