What you will build
An AI agent that calls a data API will hit errors. Keys get revoked, caps run out, a burst of parallel calls trips the rate limit, a lookup finds nobody. A human developer reads the message and decides. An agent running a loop at night needs that decision written down in advance, or it will either give up on the first hiccup or retry the same failing call until something else breaks.
By the end of this guide you will have a small, explicit error policy for an agent that uses Dizo over REST or MCP. It covers four things: learning the key's limits before the first call, making every write safe to repeat, mapping each error code to one action, and handing money decisions back to a person. The policy fits in a few dozen lines of code or a short block of system prompt, and it is the same whether the agent is an AI SDR, a CRM enrichment job or a research assistant.
Prerequisites
You need a Dizo key and somewhere to run the agent. You get a live key when you sign up. You do not need a live key to build this. Keys that start with dz_test_ return synthetic data and never spend credits, which makes them the right place to exercise error paths before any money is involved.
It also helps to create a dedicated key for the agent rather than sharing your own. A key created with POST /v1/keys can carry its own scopes, daily and monthly credit caps, a max_credits_per_request ceiling and an endpoint allow-list. Several of the errors below only exist because those limits exist, and they are what stop a confused agent from spending more than you meant. The API keys reference lists every option.
Step 1: Read your limits before the first call
Start every session with GET /v1/me, or the dizo_whoami tool over MCP. It is free and safe for any key. The response lists the key's scopes, its allowed_endpoints, a budget block with max_credits_per_request, day_remaining_credits and month_remaining_credits, and a rate_limit block, for example 20 requests per second and 10 concurrent.
This one call prevents a whole class of errors. An agent that knows its allow-list will not try an endpoint it cannot reach and collect a scope_denied. An agent that knows it has 1,640 credits left today will not queue a job that needs 5,000. An agent that knows its concurrency limit will not open fifty parallel requests. Put the response in the agent's working context and tell it to plan inside those numbers.
For longer runs, add GET /v1/billing (the dizo_balance tool) before each big loop. It returns the account balance, this month's spend against the cap and per-key usage. Dizo's agent rules are direct about this: if monthly spend is near the cap, stop and ask your human.
Step 2: Make every POST safe to repeat
Networks drop responses. If your agent sends a lookup, the connection times out and it sends the same lookup again, you want one charge, not two. Send an Idempotency-Key header on every POST. Retries with the same key within 24 hours are never charged twice, and the original result comes back.
Generate the key from the intent, not from the clock. A hash of the endpoint plus the normalized request body works well: the same lookup always produces the same key, and a different lookup always produces a different one. Reusing a key with a different body returns 409 idempotency_conflict, which almost always means a bug in how keys are generated. Treat it as a programming error, log it and do not retry.
Step 3: Branch on the code, not the message
Every error response carries an error object with a stable code, a plain-English fix, a retryable flag and, when relevant, retry_after in seconds. Branch on error.code. Messages can be reworded; codes are the contract. Pass error.fix to the model as well, because it is written to be followed and it gives the agent a sentence it can repeat to a human.
These are the codes most agents need to handle. The full table, with HTTP statuses, is on the error codes page.
invalid_request(400): fix the field named inerror.param. Not retryable as sent.invalid_api_key(401): stop and ask a human for a working key.scope_deniedorip_not_allowed(403): the key cannot do this. Stop, do not try other keys.not_found(404): no match on a lookup. Not charged. Record the miss and move on.idempotency_conflict(409): same key, different body. A bug, not a transient error.rate_limited(429): retryable. Waitretry_afterseconds.internal_error(500): retryable with exponential backoff, at most five tries.insufficient_credits,monthly_cap_reached,budget_exceeded,request_budget_exceeded(402): money decisions. See step 5.
Step 4: Retry only what is retryable
The rule is short: retry only if error.retryable is true, and only after error.retry_after seconds. For rate_limited, that wait is supplied. For internal_error, use exponential backoff with a little random jitter, and give up after five attempts. Everything else is not retryable as sent, and repeating it just burns time and rate-limit budget.
Rate limits are usually a sign the agent is doing too much one item at a time. If a job has more than about 50 lookups, send it as a single POST /v1/batch request instead. A batch takes up to 10,000 items, runs asynchronously and charges each item at the same rate as the underlying endpoint, so it costs the same and avoids hammering the per-second limit. The batch enrichment guide walks through it.
Because every POST carries an idempotency key from step 2, retries are free of double charges. That is what makes it safe to let the agent retry on its own at all.
Step 5: Treat every 402 as a question for a human
Four codes share HTTP 402, and none of them should be retried automatically. insufficient_credits means the balance is empty. monthly_cap_reached means the account hit its hard monthly ceiling, refills included, and a human must raise it or wait for the new month. budget_exceeded means this key's daily or monthly cap is used up. request_budget_exceeded means this single call would cost more than its max_credits allows.
The last one is the only 402 an agent can often fix by itself: lower limit, narrow the query, or split the job. The other three are decisions about money. Dizo's agent rules say never to call billing write endpoints such as top-up, auto-refill, limits or keys without explicit human approval, and those endpoints need the billing:write scope, which keys do not have by default. The account owner can also lock billing entirely.
So the agent's job on a 402 is to stop the loop, report what it finished, how many credits it used and what is left, and ask. A good message names the code and quotes error.fix. A bad one keeps retrying, or worse, tries to find a key that still has budget.
Misses, quotes and bad data
A 404 not_found from a lookup is not an error in the usual sense. The email finder, phone finder, email to profile and phone to profile endpoints charge only when they find something, so a miss is free. Do not retry a miss with the same input. Do try a different identifier, such as a profile URL instead of a name, since that is a new request with new odds.
Errors you can see coming are cheaper than errors you react to. Add "dry_run": true to any billable call for an exact quote that spends nothing, and do it before any job that may exceed about 100 credits. Always send max_credits as well, so the worst case is a 402 rather than a surprise. The dry-run guide covers the pattern.
Finally, some failures arrive later: an email bounces, a number is disconnected. Report them with POST /v1/feedback using the x-dizo-request-id from the original response. Confirmed reports within 30 days are refunded to your balance, usually within an hour.
Variations: REST, MCP and batch
Over REST you own the loop, so the policy lives in code: a switch on error.code, a retry helper that honors retry_after, and a hard stop on 402. Over MCP at https://mcp.dizo.ai/mcp, the model sees tool errors in its context, so the policy lives in the system prompt. Keep it short and literal: call dizo_whoami first, retry only when told, stop and ask on budget errors, never touch billing. MCP connections also default to data:read and a 500-credit per-call limit unless you change them in the console.
Batch jobs add one more layer. The submit call can fail like any POST, but individual items inside the batch follow their own endpoint's rules, and misses inside a batch are still free. Check the job with GET /v1/batch/{id}, which is free, or listen for the batch.completed webhook instead of polling in a tight loop.
Common mistakes and costs
Error handling itself costs nothing. GET /v1/me, GET /v1/billing, batch status, feedback and dry runs are all free, and failed lookups are not charged. The cost of getting it wrong is indirect: duplicate charges without idempotency keys, wasted calls against a rate limit, and an agent that quietly stops working at 2 a.m. Credits run from $0.025 down to $0.010 depending on purchase size; see pricing for the tiers.
- Matching on error message text instead of
error.code. - Retrying 402s in a loop, which never succeeds and hides the real problem.
- Generating a new idempotency key for every retry, which defeats the point.
- Treating
not_foundas a crash and halting a whole job. - Running hundreds of single lookups in parallel instead of one batch.
- Giving the agent a key with
billing:writeso it can fix its own budget errors.
Frequently asked questions
Which field should my agent branch on?
Branch on error.code. It is stable across releases, while messages may change. Use error.fix as the human-readable explanation, and error.retryable and error.retry_after to decide whether and when to try again.
Am I charged when a request fails?
Lookups that find nothing return 404 not_found and are free. Errors raised before work is done, such as auth, scope or budget errors, return no data. Retries that reuse the same Idempotency-Key within 24 hours are never charged twice.
What should an agent do on a 402?
Stop the loop and ask a human, except for request_budget_exceeded, which it can often fix by lowering limit or splitting the job. The other 402 codes mean the balance, a key cap or the account's monthly cap is exhausted, and changing those requires human approval.
How many times should I retry a 500?
Use exponential backoff with jitter and stop after five attempts. If it still fails, log the x-dizo-request-id and report the failure rather than continuing to retry.
How do I avoid rate limits in the first place?
Read the rate_limit block from GET /v1/me and stay under it, and send more than about 50 lookups as one POST /v1/batch job. Batches take up to 10,000 items at the same per-item price.
Can I test error handling without spending credits?
Yes. Keys starting with dz_test_ return synthetic data and never spend credits, so you can run your agent loop against them. Dry runs on live keys are also free.
Last reviewed 2026-11-24.