# ZIP Codes API — notes for AI agents (a person's key, or your own prepaid card)

Best practices for an agent calling https://api.zip-codes.com — on a person's behalf with their key, or on your
own with a prepaid card you buy (no signup, no account). The overview is
https://api.zip-codes.com/llms.txt; the complete reference is https://api.zip-codes.com/llms-full.txt.
Plans, packs, limits and formulas as JSON: https://api.zip-codes.com/pricing.json. Updated 2026-10-07.

## Before spending credits

1. **Try the demo key first.** `zc_test_DEMOAPIKEY000000000000` answers the demo ZIPs, postal codes and
   addresses listed in llms-full.txt, at 5 requests/minute per IP, with no account. Use it to confirm the
   response shape before using the person's own key.
2. **Know the cost of a call before making it.** Every response reports `meta.credits` (`used`, `remaining`,
   `breakdown`), so the cost of one call tells you the cost of a thousand. Formulas:
   - `/v2/zip`: 1 + one per billable enrichment flag + reverse_geocode (a coordinate input).
   - `/v2/quick-zip`: base × (1 + timezone + reverse_geocode); base 2 for ZIP+4, otherwise 1.
   - `/v2/address`: 1 + coordinates (if requested) + each delivered boundary flag + each delivered tract ACS tag.
     A no-match costs 1 (+1 for coordinates).
   - `/v2/radius`: distance-band base × (1 + timezone/ACS requests + auto_radius).
   - `/v2/distance`: 1 per pair. `/v2/suggest`: 1, 2, 3 or 5 by limit band (≤15, 50, 150, 500).
3. **Worked examples** (measured 2026-10-03):

   | Call | Credits |
   |---|---|
   | `/v2/zip?code=90210&include=census,cd,state_leg,school_district` | 5 |
   | `/v2/zip?code=90210&include=census,cd,state_leg,school_district,acs_demographic,acs_demographic_2022` | 7 |
   | `/v2/address` with `coordinates,census,cd,state_leg,school_district,acs_tract_demographic` | 7 |
   | `/v2/radius?code=90210&max=5&include=acs_demographic` | 2 |
   | `/v2/zip?code=34.0901,-118.4065` (coordinate → ZIP+4) | 2 |
   | `/v2/zip?code=K1A0A6&include=statcan,statcan_2016,statcan_2011,timezone` (Canada) | 5 |
   | `/v2/zip?code=K1A0A6&include=census,cd,census_2016,timezone` (legacy names on a Canadian code) | 4 |

4. **Tell the person the expected cost before a batch or a recurring job**, and how much of their daily
   allowance it uses (free accounts: 2,500 credits/day, 60 requests/minute).

## Choosing the cheapest way to pay

Prices as of 2026-11-01; https://api.zip-codes.com/pricing.json is the live source.

- **Credit packs** are one-time purchases that **never expire** and **stack on top of the free daily allowance**:
  Starter 25,000 credits $19 · Standard 65,000 $49 · Growth 150,000 $99 · Pro 300,000 $179 · Enterprise 2,000,000 $799.
  Two smaller packs are sold to agents only, through the API (see Buying credits): Mini 6,250 credits $5 · Lite 12,500 $10.
- **Subscriptions** are monthly: Developer 100,000 credits $49 · Professional 350,000 $149 · Business 1,500,000 $499.
  A subscription **replaces** the free daily credits, and unlocks batch and higher rate limits.
- **Spending order:** the free daily credits first (free accounts), then subscription credits, then purchased packs.
- **Worked example:** a ZIP lookup with timezone costs 2 credits. At 50,000 lookups a month that is 100,000 credits.
  The free allowance covers about 75,000 (2,500 a day), and one Starter pack ($19) covers the other 25,000, which is
  cheaper than the $49 Developer subscription. A subscription wins once the person needs batch, higher rate limits, or
  steady volume well above the free allowance.

## Buying credits

**This API accepts payment programmatically.** An agent with an MPP wallet (a shared payment token paid through Stripe —
card or Link) can buy credits and keep working with no signup, no account and no person on our side; the wallet
authorizes each payment (Link, for example, asks its human to approve every payment in the Link app). Paying is the
same round trip wherever it starts: the API answers **402** with a `WWW-Authenticate: Payment` challenge (MPP, `draft-httpauth-payment`), you pay it
with your wallet, and you resend the same request with the credential in a `Payment-Authorization` header. A successful
answer carries a `Payment-Receipt` header, and credits are added only after the payment completes.

The credential is `Payment ` followed by the base64url (no padding) of
`{"challenge":{"id":…,"realm":…,"method":…,"intent":…,"request":…,"expires":…},"payload":{"spt":"spt_…"}}`: the
challenge's parameters exactly as the `WWW-Authenticate` header gave them, and your wallet's shared payment token for
the challenge's amount. `Authorization: Payment …` (the MPP default) is read the same way; to pay with a key, send the
key in `X-Api-Key`. A prepaid card's key starts `pp_card_` (account keys `zc_live_`): mask both when you log.

Two ways to pay, by whose money it is:

- **On a person's key** (their account's payment method): **ask the person before paying.** Out of credits, a request
  answers 402 CREDIT_INSUFFICIENT with an offer and the challenge; `POST /v2/purchase` buys a pack onto that account.
- **On your own — no signup, no account:** `POST /v2/purchase` **sent without any key** mints a **prepaid card**: an API
  key with no account, holding the pack's credits, returned in `results[0].api_key`. Use it on every endpoint, and
  `POST /v2/purchase` **with that card's key** to reload it. You pay with your own wallet, which authorizes the payment. Keep
  the key: resending the same payment returns it only while the card is unused and for 24 hours after settlement. From
  zero, go straight to `POST /v2/purchase` — the data endpoints answer **401** for a missing key, not a purchase offer.
- **`POST /v2/purchase`** body is any of `pack` (name, case-insensitive), `price_usd` and `credits`, each naming one
  agent pack in `pricing.json`; sent together they must name the same pack. **201** paid and credited; **202** still
  clearing (status `processing`, no credits yet) — keep `purchase_id`, read `GET /v2/purchases/{id}`, **never buy
  again**; **200** the same credential again, never charged twice. Errors include PAYMENT_FAILED, PAYMENT_PENDING,
  PACK_NOT_AVAILABLE, PURCHASES_DISABLED and AUTH_TEST_KEY_RESTRICTED (test and demo keys cannot buy).
- **`GET /v2/purchases/{id}`** reads one purchase by its order number (PP- through the API, ZC- on the website; dashes
  and case forgiven); `status` is `processing`, `succeeded`, `failed`, `refunded` or `disputed`, and an unknown id — or
  one on another account or card — is **404**.
- **`GET /v2/balance`** shows the free, subscription and purchased pools (a prepaid card: purchased only; a request
  draws on free or subscription first, then purchased). Both reads take the key in a header (`X-Api-Key` or
  `Authorization: Bearer`), never `?key=`, 10 a minute per key. The demo key's 403 is expected; test, demo and admin
  keys cannot read a purchase or a balance.
- Agent packs start at $5 (`pricing.json`, where `available_to` lists `agents`); packs never expire. Paying accepts the
  Terms of Service: https://www.zip-codes.com/api/tos.

## Batches

5. Batch routes need a paid plan or purchased credits. Each item is charged, **duplicates included**: dedupe inputs first.
6. Maximum 100 items per batch (250 for `/v2/address/batch`). Spatial radius is not available in batch.

## What is free, and should not be retried

7. Unknown flags, enrichments that are unavailable for the input (for example ACS for a Canadian code) and ACS
   years Census did not publish are **not charged**. They come back as notices in `meta.notices` or as
   `published: false`. Retrying returns the same answer; it is not an error to fix.

## Errors and limits

8. Every error carries a `code`, a `message` and a `url` with the next step; `retryable` says whether to try
   again where it is known. Retry only retryable errors, with backoff.
9. Rate limits are per minute (Free 60; Developer and Professional 300; Business 600; Enterprise 1800).
   On 429, wait for the window rather than retrying in a loop.
10. Lookup not-found is HTTP 200 with a per-item `success: false`; a single-address no-match is a top-level
    `success: false`. Neither is a transport failure.

## Getting it right first time

11. The radius parameter is `max` (miles), not `radius`.
12. Send the key in the `X-Api-Key` header or as `Authorization: Bearer <key>`. Do not put it in the URL
    (`?key=` works, but URLs end up in logs and histories).
13. For the current ACS year, use the unsuffixed flag (`acs_economic`) rather than hardcoding a year.
14. `/v2/address`: with a ZIP, city and state are optional; without a ZIP, give the city and state.
15. Canadian geography is `statcan` on `/v2/zip` (Statistics Canada; federal electoral districts are inside each
    period, at no extra charge). `statcan` is the newest census, `statcan_YYYY` another one (`statcan_2016`,
    `statcan_2011`; the years the server holds are in the OpenAPI `include` enum). `census` / `cd` on a Canadian
    code still work but are answered as `statcan` with an `ENRICHMENT_FLAG_RENAMED` notice, so `census,cd` is one
    `statcan` credit; ask for `statcan` directly. `statcan` on a US ZIP is free and returns `ENRICHMENT_UNAVAILABLE`.
16. The OpenAPI spec (https://api.zip-codes.com/swagger/v2/swagger.json) lists every `include` flag the API accepts,
    year flags included, and types every response field; a field it marks nullable is always present (null when
    empty), any other field is omitted when empty.

## Contact

Bugs, feature requests, apps built on the API (apps and tools we feature get 100,000 credits) and research credits:
jharris@zip-codes.com. Including the `request_id` from the response helps.
