# An agent loop that prospects and knows its limits.

> Design an agent loop that checks its key, sizes the market for free, searches past suppressed contacts, finds verified emails and stays inside hard spend caps.

An AI SDR is a loop: learn the budget, size the segment, find people you have not contacted, get verified contact data, hand off and learn from bounces. Dizo covers the data steps.

## Highlights
- **Starts with GET /v1/me.** The agent learns its scopes, allow-list, per-request ceiling and remaining budget first.
- **Free sizing.** `POST /v1/count` tells the agent how big a segment is before it buys anything.
- **Never re-prospects customers.** Suppressed domains and emails are dropped from every search before billing.
- **Plain-English search.** `POST /v1/search` turns an ICP sentence into filters and shows them in `interpreted`.
- **Hard spend fences.** `max_credits` per call, per-key daily and monthly caps, and an account cap.
- **Learns from bounces.** Bounces go to `POST /v1/feedback`; confirmed reports refund the credits.

## Steps
1. **Issue a scoped key** — `data:read`, caps and an allow-list of the endpoints the loop needs.
2. **Load suppression** — Customers, open deals and opt-outs go into `POST /v1/suppression`.
3. **Check budget at start-up** — Call `GET /v1/me`, and `GET /v1/billing` before long loops.
4. **Size the segment** — Free `POST /v1/count`, one per slice if needed, to forecast cost.
5. **Search and get contacts** — `POST /v1/search` with `include: ["email"]`, `max_credits` and an `Idempotency-Key`.
6. **Hand off and personalise** — Pass people to your sequencing tool with the context the agent gathered.
7. **Close the loop** — Report bounces, suppress replies that opt out, and log credits per meeting.

## APIs used
| API | Endpoint | Credits | Charged | Reference |
|---|---|---|---|---|
| Key info | `GET /v1/me` | Free | Never | [docs](https://dizo.ai/docs/me.md) |
| Count (TAM) | `POST /v1/count` | Free | Never | [docs](https://dizo.ai/docs/count.md) |
| Natural-language search | `POST /v1/search` | 1 credit / 25 results | Per result returned | [docs](https://dizo.ai/docs/search.md) |
| Suppression list | `POST /v1/suppression` | Free | Never | [docs](https://dizo.ai/docs/suppression.md) |
| Email finder | `POST /v1/email/find` | 1 credit | Only if found | [docs](https://dizo.ai/docs/email-find.md) |
| API keys | `POST /v1/keys` | Free | Never | [docs](https://dizo.ai/docs/keys.md) |
| Balance & usage | `GET /v1/billing` | Free | Never | [docs](https://dizo.ai/docs/billing.md) |
| Data feedback | `POST /v1/feedback` | Free (refunds credits) | Never | [docs](https://dizo.ai/docs/feedback.md) |


## What an AI SDR actually does

Strip away the branding and an AI SDR is a loop. It decides who to contact, finds them, gets a way to reach them, writes something relevant, hands it to a sending tool, and learns from what happens. The writing gets most of the attention, but the data steps decide whether the loop works at all. An agent that emails the wrong people, re-prospects existing customers or bounces half its sends does damage faster than a human could.

This guide is about the data half of that loop. It shows how to build an agent that starts by learning its own budget, sizes a segment for free, searches for people while skipping anyone you must not contact, gets verified emails, and stays inside hard limits it cannot change. The examples use Dizo's REST API, but every step has an equivalent MCP tool if your agent framework prefers tools over HTTP.

## Prerequisites

You need an agent framework or runtime, a sequencing or sending tool for the actual email, and a Dizo account. Sign up with a work email to get 250 free credits. Build the whole loop against a `dz_test_` key first; it returns synthetic data and never spends credits, so you can test logic, error handling and budget behaviour end to end.

You also need a written ICP the agent can follow and a clear policy for who must never be contacted. The agent will apply both literally, so make them specific.

## Step 1: give the agent its own key and limits

Create a key just for the agent with `POST /v1/keys`. Give it `data:read` only, a `daily_cap_credits` and `monthly_cap_credits` sized to the plan, a `max_credits_per_request` ceiling, and an `allowed_endpoints` list containing only what the loop needs: for example `/v1/me`, `/v1/count`, `/v1/search`, `/v1/email/find`, `/v1/suppression` and `/v1/feedback`. Leave phone lookups and billing endpoints off unless you have a reason.

Add an account-wide `monthly_cap_usd` with alerts at 50, 80 and 100 percent as a backstop. Without `billing:write`, the agent cannot top up, change refills or raise its own caps. That separation is deliberate: a human owns the account and the money, and the agent works inside the box the human drew. The [budget agent data spend guide](/guides/budget-agent-data-spend) covers sizing those caps.

## Step 2: load suppression before the first search

Before the agent runs a single search, push everyone it must not contact into the [suppression list](/docs/suppression): current customer domains with reason `customer`, open-opportunity domains with reason `opportunity`, and every opt-out email with reason `opt_out`. Suppressed records are removed from every search, list and lookup before billing, so the agent never sees them and you never pay for them.

Keep suppression in sync. When a deal opens in your CRM, add the domain. When someone replies asking not to be contacted, have the agent call `dizo_suppress` straight away. Suppression is free and holds up to 1,000,000 entries per account, so there is no reason to ration it.

## Step 3: the start-up check

Every run should begin with `GET /v1/me`. It returns the key's scopes, allowed endpoints, `max_credits_per_request`, `day_remaining_credits`, `month_remaining_credits` and rate limits. The agent should plan within those numbers rather than discovering them through errors. If the day's remaining budget is lower than the run needs, the agent should do less, not try harder.

Before long loops, also call `GET /v1/billing` to see the account's month-to-date spend against its cap. Dizo's published agent rules say to stop and ask a human if monthly spend is near the cap. Build that into the loop as an explicit branch, not a hope.

## Step 4: size the segment for free

Next, the agent sends its ICP to `POST /v1/count`. The response gives the total number of matching people. It is free, so the agent can try several phrasings of the ICP and pick the one that gives a sensible segment size. To see how the segment splits, the agent runs one count per slice, for example one per seniority level or one per state. Each of those counts is free too.

Count also lets the agent forecast. If 4,000 people match, a run that searches 200 of them and fetches emails will cost 8 credits for the search and at most 200 for emails, because an email is charged only when one is found. The real figure lands below that ceiling, and the agent can check that against its remaining budget before it starts. Any job likely to exceed about 100 credits should be dry-run first.

## Step 5: search and get verified contacts

For open-ended prospecting, `POST /v1/search` is the right default for agents because it takes plain English: `{"query":"Heads of RevOps at US fintech companies with 200 to 1,000 employees","include":["email"],"limit":50,"max_credits":60}`. The response includes an `interpreted` object showing the filters Dizo derived. Have the agent log it, so a human can check that the translation matches the intent. Paginate with `next_cursor`.

Search costs 1 credit per 25 results, and emails added with `include` cost 1 credit each, only when found. Every POST should carry an `Idempotency-Key` header; retries within 24 hours are never charged twice, which matters for agents that retry on timeouts. The agent should read `x-dizo-credits-used` and `x-dizo-credits-remaining` on each response to keep a live ledger.

If you sell into fixed accounts rather than a segment, swap search for the [decision-maker finder](/docs/best-match): a list of domains and a ranked title list, returning the top match per account. The rest of the loop is unchanged.

## Step 6: hand off, close the loop and handle errors

The agent passes each person, with their verified email and whatever context it gathered, to your sequencing tool. Dizo's part ends at the data; writing and sending are yours. Keep the Dizo `person_id` and the `x-dizo-request-id` with each contact record, because the loop needs them later.

When an email bounces, the agent reports it to `POST /v1/feedback` with the request id, the issue `bounced` and the bounce message. Confirmed reports within 30 days are refunded, usually within an hour, and the correction applies for everyone. When a reply is an opt-out, the agent suppresses the address immediately. When a reply is positive, the agent can add that person to a job-change watchlist so you hear if they move.

Dizo errors carry a stable `error.code`, a plain-English `error.fix`, and an `error.retryable` flag. The agent should branch on the code, follow the fix, and retry only when retryable is true, after `error.retry_after` seconds. A `402 monthly_cap_reached` means stop and tell a human; it is not a retryable error and the agent cannot fix it. A `404 not_found` on the email finder is a free miss, not a failure. The [error handling guide](/guides/handle-api-errors-in-agents) goes through each case.

## Variations: supervised, scheduled and fully autonomous

Most teams should start supervised. The agent runs inside a chat client connected over MCP, proposes a segment and a list, shows the quote, and waits for a human to say go. The tools are the same ones the autonomous loop uses, `dizo_count`, `dizo_search` and `dizo_find_email`, so nothing has to be rebuilt later.

The next stage is scheduled: the loop runs daily from code with a fixed ICP, a fixed per-run `max_credits`, and a human reviewing the handoff queue before anything is sent. A monitor can replace repeated searches here, sending only people who newly match a saved query at 1 credit per 25 new results.

Fully autonomous loops make sense only once bounce rates and credits per meeting are stable. Even then, keep the caps tight and the alerts on. Autonomy is about who presses the button, not about removing the limits.

## Cost model and what to measure

Take a hypothetical agent that prospects 1,000 new people a month. Searching 1,000 people costs 40 credits. If 820 emails are found, that is 820 credits. Total: 860 credits, which is $21.50 at the Pay as you go rate or $18.06 at the Builder rate. If 15 of those emails bounce and are confirmed, 15 credits come back.

Measure the loop by outcomes, not activity: credits per meeting booked, bounce rate on agent-sourced contacts, share of searches whose `interpreted` filters matched the intent, and how often the agent stopped for budget. Those four numbers tell you whether to widen the segment, tighten the ICP or raise the caps. The [AI SDR agents use case](/use-cases/ai-sdr-agents) has more on the end-to-end picture.

## FAQ

### Which Dizo endpoint should an AI SDR use for prospecting?
`POST /v1/search` with a plain-English query is the default for agents, because there is no filter vocabulary to learn and the `interpreted` field shows how the query was translated. Use the decision-maker finder when you work from a fixed account list.

### How do I stop an agent from overspending?
Give it a dedicated key with daily and monthly credit caps, a per-request ceiling and an endpoint allow-list, and set an account monthly cap. Have it send `max_credits` on every call and dry-run anything likely to exceed about 100 credits.

### How do I keep the agent away from existing customers?
Add customer and open-opportunity domains to the suppression list. Suppressed records are dropped from every search and lookup before billing, so the agent never sees them.

### Can the agent buy more credits when it runs out?
Not unless its key has the `billing:write` scope, and Dizo's agent rules require explicit human approval for any billing change. Keys are read-only for billing by default.

### What happens if the agent retries a request?
If it sends the same `Idempotency-Key` within 24 hours, it is not charged twice. Retry only when the error says `retryable` is true.

### Can I build and test the agent before I have live access?
Yes. `dz_test_` keys return synthetic data and never spend credits, so you can test the full loop, including caps and errors, before joining with a live key.
