# Authentication and API keys

> Authenticate HandleHaul API calls with an X-Api-Key header. Keys are 256-bit random secrets shown once, stored only as a keyed hash, with revoke, rotate, IP allowlists and per-key limits.

Send your key in the `X-Api-Key` header on every request. Live keys start with `kd_live_`; sandbox keys start with `kd_test_`.

```bash
curl "https://api.handlehaul.com/v1/account" -H "X-Api-Key: kd_live_YOUR_KEY"
```

```php
$ch = curl_init("https://api.handlehaul.com/v1/account");
curl_setopt_array($ch, [
    CURLOPT_HTTPHEADER => ["X-Api-Key: " . getenv("HANDLEHAUL_API_KEY")],
    CURLOPT_RETURNTRANSFER => true,
]);
$body = json_decode(curl_exec($ch), true);
print_r($body["data"]);
```

```go
req, _ := http.NewRequest("GET", "https://api.handlehaul.com/v1/account", nil)
req.Header.Set("X-Api-Key", os.Getenv("HANDLEHAUL_API_KEY"))
res, err := http.DefaultClient.Do(req)
if err != nil {
    log.Fatal(err)
}
defer res.Body.Close()
var body map[string]any
json.NewDecoder(res.Body).Decode(&body)
fmt.Println(body["data"])
```

## How keys are protected

- Each key carries more than 256 bits of randomness.
- We store only a keyed hash (HMAC-SHA256 with a server-side secret). The full key is shown **once**, when you create it. The dashboard shows only the first characters.
- **Rotate** issues a new key with the same name and settings. The old one stops at once, or after a grace period of up to 7 days so you can deploy the new one.
- **Revoke** stops a key within seconds.
- **IP allowlist:** limit a key to your servers' addresses or CIDR ranges (IPv4 or IPv6). Calls from anywhere else answer `403 ip_not_allowed`.
- **Per-key limits:** give a key a lower requests-per-second limit or a monthly credit cap, for example for a staging server.
- Keep keys on your server. Never ship them in a browser, a mobile app or a public repository. A live key sent from a web page still works, but the answer carries `meta.warning` and an `X-HandleHaul-Warning` header. Building with an AI tool? See [Build with AI tools](/docs/build-with-ai).

## Account access

The docs, OpenAPI spec and pricing are public. Using the API needs a business account, which moves through these levels:

| Level | How you get there | What you can do |
|---|---|---|
| Email confirmed, in review | You signed up; an automatic check needs a person to look | Unlimited sandbox (`kd_test_`) keys |
| Limited | Automatic checks passed (verified business email, website, no blocklist hit) | Sandbox, 1 live key, 2 requests a second, the $29 and $99 packs, 100 live test calls |
| Approved | A person reviewed your account (usually within one business day) | Up to 10 live keys, every pack, 10 to 30 requests a second depending on the largest pack you bought ([rate limits](/docs/rate-limits)) |

Accounts that break the [acceptable use policy](/docs/acceptable-use) are suspended: every key answers `403 account_suspended` at once.

**Live test calls** are spent only after your paid credits, at 1 request a second and up to 5 pages of any list. Going faster gives `429 promo_rate_limited` with `Retry-After` (not charged; wait and retry). Page 5+1 of a list gives `402 promo_limit`. When the test calls run out you get `402 insufficient_credits` with a link to buy a pack.

## Dashboard sign-in

The dashboard uses one-time sign-in links sent by email (valid 15 minutes, single use). You can turn on **two-factor authentication** (any authenticator app) under **Settings → Two-factor** in the dashboard; you then get recovery codes to store safely.

## Account endpoint

`GET /v1/account` is free and returns your credit balance, rate limits and this key's monthly spend. Use it as a health check for your integration.

```json
{
  "data": {
    "plan": "payg",
    "pricing_version": 2,
    "status": "approved",
    "credits": { "total": 61480, "paid": 61480, "plan_allowance": 0, "prepaid": 61480, "free_test_calls": 0 },
    "limits": { "requests_per_second": 10, "concurrent_requests": 25 },
    "key": { "prefix": "kd_live_Ab12Cd", "name": "production", "mode": "live", "monthly_credit_limit": null, "credits_used_this_month": 1240 }
  },
  "meta": { "request_id": "req_…", "credits_charged": 0 }
}
```

- `credits.prepaid` is what your packs have left; `free_test_calls` are the live test calls from sign-up. `total` is both together.
- `limits` is the speed of the whole account: it comes with the largest pack you have bought.
- HandleHaul sells credit packs only, so `plan` is always `"payg"` and `plan_allowance` is always `0`.
