# REST API reference

> The Humanless REST API has five endpoints under `https://api.usehumanless.com/v1`. They create an identity (email inbox, SMS number, TOTP secret), wait for the next message, read the current TOTP code, read the identity and delete it. Requests and responses are JSON, and every error has a stable machine-readable code.

## Basics

- **Base URL:** `https://api.usehumanless.com/v1`
- **Auth:** `Authorization: Bearer hl_live_...` on every request. A missing, malformed or revoked key returns `401 unauthorized`.
- **Bodies:** JSON. Send `Content-Type: application/json`. An empty body is treated as `{}`. A body that isn't valid JSON returns `400 invalid_json`.
- **IDs:** `identity_id` is a UUID. A malformed or unknown ID, or one that belongs to another account, returns `404 not_found`.
- **Errors:** every non-2xx response has this shape:

```json
{
  "error": {
    "code": "channel_not_enabled",
    "message": "This identity was not created with the sms channel"
  }
}
```

Some errors also include `error.details`, for example quota numbers and a `billing_url`. When a `Retry-After` header is present, wait that many seconds before retrying.

## Endpoints

| Method | Path | What it does |
|---|---|---|
| `POST` | `/v1/identities` | Create an identity |
| `GET` | `/v1/identities/:id` | Read an identity |
| `GET` | `/v1/identities/:id/wait` | Long-poll for the next email or SMS |
| `GET` | `/v1/identities/:id/totp` | Current TOTP code |
| `DELETE` | `/v1/identities/:id` | Delete an identity (idempotent) |

## The Identity object

| Field | Type | Notes |
|---|---|---|
| `identity_id` | string (UUID) | Use it in every other call |
| `channels` | array of `"email"`, `"sms"`, `"totp"` | The channels this identity was created with |
| `email` | string or null | Disposable address, set when `email` is enabled |
| `phone` | string or null | E.164 US number (`+1...`), set when `sms` is enabled. Receive-only |
| `totp_secret` | string or null | Base32 secret (32 chars), set when `totp` is enabled. Enter it where the app says "can't scan the QR code?" |
| `status` | `"active"`, `"deleted"` or `"expired"` | |
| `expires_at` | ISO 8601 string | When the identity expires automatically |
| `created_at` | ISO 8601 string | |
| `ended_at` | ISO 8601 string or null | When it was deleted or expired |

## The Message object

| Field | Type | Notes |
|---|---|---|
| `type` | `"otp"`, `"magic_link"` or `"raw"` | `otp`: a code was found (and `url` may also be set). `magic_link`: only a link was found. `raw`: neither was found, so read `raw_snippet` |
| `code` | string or null | The extracted one-time code |
| `url` | string or null | The extracted verification or sign-in link |
| `channel` | `"email"` or `"sms"` | |
| `sender` | string | Email `From` or the SMS sender number |
| `subject` | string or null | Email subject. `null` for SMS |
| `received_at` | ISO 8601 string | |
| `raw_snippet` | string | The first 280 characters of the message as plain text |

## POST /v1/identities

Creates a new identity.

**Body**

| Field | Type | Default | Notes |
|---|---|---|---|
| `channels` | array of `"email"`, `"sms"`, `"totp"` (1 to 3) | `["email"]` | `sms` needs a paid plan or prepaid credits |
| `ttl_seconds` | positive integer | `3600` (1 hour) | Maximum `86400` (24 hours) |
| `domain` | string | Your account's default domain, otherwise the platform domain | Email domain to use. It must be a platform domain or one of your verified domains, and only works with the `email` channel |

```bash
curl -s -X POST https://api.usehumanless.com/v1/identities \
  -H "Authorization: Bearer $HUMANLESS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"channels":["email","sms","totp"],"ttl_seconds":900}'
```

**Response** `201 Created`: an [Identity](#the-identity-object).

**SMS numbers.** Each paid account has dedicated US numbers: 1 on Builder, 5 on Pro, and extra or pay-as-you-go numbers paid from credits. They are never shared with other customers. An SMS identity holds one of your numbers until it is deleted or expires. After that, the number has a short cooldown (about 30 seconds) before the next SMS identity can use it. If every number is held by a live identity, you get `409 all_numbers_busy`.

**Errors:** `400 invalid_request`, `400 invalid_domain`, `402 payment_required`, `402 sms_quota_exceeded`, `409 all_numbers_busy`, `429 rate_limited`, `429 sms_limit_reached`, `503 numbers_provisioning`, `503 phone_pool_exhausted`, `503 email_domain_not_configured`.

## GET /v1/identities/:id/wait

Blocks until the next message for this identity arrives, then returns it. The wait is push-based, so it returns as soon as the message is received, with no polling interval.

**Query parameters**

| Param | Type | Default | Notes |
|---|---|---|---|
| `channel` | `any`, `email` or `sms` | `any` | Only return messages from this channel |
| `timeout` | number of seconds, 0 to 60 | `30` | Fractions are allowed |
| `since` | Unix time in milliseconds | none | See below |

```bash
curl -s "https://api.usehumanless.com/v1/identities/$ID/wait?channel=sms&timeout=60" \
  -H "Authorization: Bearer $HUMANLESS_API_KEY"
```

**Response** `200 OK`: a [Message](#the-message-object). If no message arrives before the timeout, you get `408 timeout`. Nothing is wrong, so call it again.

**Consumption semantics**

- Without `since`, each wait returns the oldest **unconsumed** message and marks it consumed. The next wait returns the next message. If your app sends two emails (for example a welcome email and then a code), the first wait may return the welcome email. Check `code` or `url` and wait again.
- With `since`, the wait returns the oldest message received **at or after** that time, whether or not it was already consumed. Take `Date.now()` just **before** you submit the form, so a message that arrives before the wait starts is still caught. Repeating the same `since` returns the same message. To get the next one, advance `since` past that message's `received_at`.

**Server-Sent Events.** Send `Accept: text/event-stream` to get a stream instead of JSON. The server sends one `message` event (data: the Message JSON) or one `timeout` event, then closes. It sends `: ping` comments every 15 seconds to keep the connection alive. A `404`, `409` or `410` is returned as a normal HTTP status before the stream starts. An error that happens during the stream is sent as an `error` event.

```bash
curl -N "https://api.usehumanless.com/v1/identities/$ID/wait?timeout=60" \
  -H "Authorization: Bearer $HUMANLESS_API_KEY" \
  -H "Accept: text/event-stream"
```

**Proxies.** The request can stay open for up to 60 seconds. If it passes through your own proxy, set its read timeout above that.

**Errors:** `400 invalid_request`, `404 not_found`, `408 timeout`, `409 channel_not_enabled` (for example `channel=sms` on an email-only identity), `410 identity_ended`.

## GET /v1/identities/:id/totp

Returns the current 6-digit code for the identity's TOTP secret.

```json
{ "code": "159026", "seconds_remaining": 17 }
```

If `seconds_remaining` is very low (3 or less), wait for the next 30-second window before you type the code.

**Errors:** `404 not_found`, `409 channel_not_enabled` (the identity has no `totp` channel), `410 identity_ended`.

## GET /v1/identities/:id

Returns the [Identity](#the-identity-object), including ones that are deleted or expired, with their `status` and `ended_at`.

**Errors:** `404 not_found`.

## DELETE /v1/identities/:id

Deletes the identity. Its email address stops receiving mail and its phone number goes back to your account. You can call it again safely: deleting an identity that is already deleted or expired returns the same result.

```json
{ "identity_id": "5b0d7c1e-8f2a-4c1b-9a63-2f1d0e7c4b11", "status": "deleted" }
```

**Errors:** `404 not_found`.

## Error codes

| Status | Code | Meaning and what to do |
|---|---|---|
| 400 | `invalid_request` | A parameter is invalid. The message names the field |
| 400 | `invalid_json` | The request body isn't valid JSON |
| 400 | `invalid_domain` | `domain` is not a platform domain or one of your verified domains. Omit it to use the default |
| 401 | `unauthorized` | Missing, malformed or revoked API key |
| 402 | `payment_required` | SMS needs Builder, Pro or prepaid credits. Use `email` or `totp`, or upgrade |
| 402 | `sms_quota_exceeded` | The included SMS are used up and your credits can't pay for more. `details` includes `credit_balance_cents` and `billing_url`. Existing SMS identities keep receiving |
| 404 | `not_found` | Unknown identity, or it belongs to another account |
| 404 | `route_not_found` | No such API route |
| 408 | `timeout` | No message arrived before `timeout`. Wait again |
| 409 | `channel_not_enabled` | The identity wasn't created with that channel |
| 409 | `all_numbers_busy` | Every dedicated number is held by a live identity. Delete the ones you've finished with, then retry |
| 410 | `identity_ended` | The identity was deleted or expired. Create a new one |
| 429 | `rate_limited` | Too many requests. Honor `Retry-After` |
| 429 | `sms_limit_reached` | You've hit the daily limit on SMS identities. Honor `Retry-After` or use email |
| 500 | `internal_error` | Unexpected server error |
| 503 | `numbers_provisioning` | Your dedicated numbers are still being set up after an upgrade. Honor `Retry-After` (30 s) |
| 503 | `phone_pool_exhausted` | No numbers are available right now. Retry later |
| 503 | `email_domain_not_configured` | No email domain is configured on the server. Retrying won't help, so contact support |

## Rate limits

Limits apply per API key per minute. Every response includes `X-RateLimit-Limit` and `X-RateLimit-Remaining`. A `429` also includes `X-RateLimit-Reset` and `Retry-After`.

| Plan | API requests per key per minute | Identities created per account per hour | SMS identities per account per day |
|---|---|---|---|
| Free and pay-as-you-go | 120 | 30 | 100 |
| Builder | 600 | 300 | 200 |
| Pro | 1,800 | 1,000 | 1,000 |

These are the current defaults and may change. Email `hello@usehumanless.com` if you need higher limits.

## Python example

There's no Python SDK. The API is plain HTTP:

```python
import os, time, requests

API = "https://api.usehumanless.com/v1"
H = {"Authorization": f"Bearer {os.environ['HUMANLESS_API_KEY']}"}

me = requests.post(f"{API}/identities", headers=H, json={"channels": ["email"]}).json()
since = int(time.time() * 1000)
# ... submit me["email"] in the app you're testing ...
r = requests.get(f"{API}/identities/{me['identity_id']}/wait",
                 headers=H, params={"channel": "email", "timeout": 60, "since": since})
if r.status_code == 408:
    raise TimeoutError("no code yet: wait again")
print(r.json()["code"])
requests.delete(f"{API}/identities/{me['identity_id']}", headers=H)
```

---
Canonical: https://usehumanless.com/docs/api · Index of all docs: https://usehumanless.com/llms.txt
