# CoveSMS API · instructions for AI assistants and coding agents

> Give this whole file to your AI (ChatGPT, Claude, Gemini, Cursor, Copilot or your own agent). It contains everything needed to write a working CoveSMS integration without opening the website.

## What CoveSMS is
CoveSMS rents temporary virtual phone numbers (and email addresses) to receive one verification code. You buy a number for one app in one country, type it into the app, and read the SMS code through this API. If no SMS arrives in 20 minutes the price returns to the account balance automatically. Deposits are never paid back in money; an unused number is returned as balance.

## Rules for the AI writing the code
- Base URL: `https://www.covesms.com/api/v1`. REST over HTTPS, JSON in and out.
- Auth: header `Authorization: Bearer <API key>`. The key is created in Dashboard → API. Read it from an environment variable named `COVESMS_API_KEY`. Never hard-code it, never put it in front-end code, never print it in logs.
- Always send `max_price` when buying, so a price change can never spend more than expected.
- Always send an `Idempotency-Key` header (a fresh UUID per purchase) on `POST /numbers` and `POST /emails`. On timeout, retry with the same key.
- Poll `GET /numbers/{id}` no faster than every 3 seconds, or use the webhook instead of polling.
- If no code arrives, call `POST /numbers/{id}/cancel` after `cancelable_at` to get the balance back sooner. Otherwise it returns by itself at `expires_at`.
- Handle every error by its `error.code` (table below), not by the message text.
- Do not invent endpoints, fields or parameters that are not in this file.

## Machine-readable
- OpenAPI 3.1: https://www.covesms.com/api/openapi.json
- MCP server (Streamable HTTP, same API key as a Bearer header): https://www.covesms.com/mcp
- Live prices without a key: https://www.covesms.com/api/public/prices?country=us&service=whatsapp (add &currency=BRL for reais)

## Quick start
A full purchase takes three calls:
1. Read the price and the stock: GET /services?country=us (or GET /prices?service=whatsapp for one app in every country).
2. Buy: POST /numbers with service and country. Add server to choose where the number comes from.
3. Read the code: poll GET /numbers/{id} every 3 to 5 seconds, or set a webhook. No SMS in 20 minutes: the price goes back to your balance by itself.

```bash
curl -X POST https://www.covesms.com/api/v1/numbers \
  -H "Authorization: Bearer $COVESMS_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"service":"whatsapp","country":"us","max_price":1.00}'
```

## Endpoints

### Account
| Method | Path | What it does |
|---|---|---|
| GET | `/balance` | Your balance and currency. |
| GET | `/account` | Balance, your limits (requests per minute, numbers per day, open numbers), today's usage, what this key is allowed to buy and your loyalty progress (loyalty). |

### Catalog and prices
| Method | Path | What it does |
|---|---|---|
| GET | `/countries` | Countries with numbers in stock, with the number of apps each. |
| GET | `/countries?service=whatsapp` | Countries where one app is in stock, with price and stock per server. |
| GET | `/services?country=us` | Apps in stock for one country: code, name, price, stock, and the price and stock of each server in servers[]. |
| GET | `/prices?service=whatsapp&country=us&server=s2` | Flat price list, one line per app, country and server. Send service, country or both; server is optional. |
| GET | `/providers?service=whatsapp&country=us&server=s4` | Server 4 and Server 5 only: the supply lines inside the server, each with its own price and stock. Use the id as provider when buying. |

### Buying
| Method | Path | What it does |
|---|---|---|
| POST | `/numbers` | Buy one number, or several with quantity. Body: service, country, and the options below. Returns 201. |
| GET | `/numbers/{id}/rebuy` | Price to buy the same number again (Server 1 and Server 3, after the number is finished). |
| POST | `/numbers/{id}/rebuy` | Buy the same number again. Optional body: max_price. Returns a new number object. |

### Your numbers
| Method | Path | What it does |
|---|---|---|
| GET | `/numbers/{id}` | One number's status and every SMS it received. Poll every 3 to 5 seconds, or use the webhook. |
| GET | `/numbers?status=active&limit=50` | Numbers bought through the API, newest first. Filters: status (active, waiting, received, canceled, expired, all), service, country, number (area code or any digits of the phone number, e.g. number=11). Paginate with before=<created_at>. |
| POST | `/numbers/{id}/cancel` | Cancel a number with no SMS and get its price back to your balance. Allowed from cancelable_at (2 minutes after purchase). |
| POST | `/numbers/cancel` | Cancel up to 50 numbers in one call. Body: ids. Each id answers with the number or with its error. |
| POST | `/numbers/{id}/resend` | Ask for another SMS on an open number that already got one. Free. |
| POST | `/numbers/{id}/finish` | Release a number that got its code, before the reservation ends. |

### Email verification
| Method | Path | What it does |
|---|---|---|
| GET | `/emails?service=instagram` | Email addresses for verification (Server 1 and Server 5): app, server, domain, price and stock. |
| POST | `/emails` | Buy an email address. Body: service, server, domain, optional max_price. The answer is a number object with type "email"; read the code with GET /numbers/{id}. |

### eSIM (enabled accounts)
| Method | Path | What it does |
|---|---|---|
| GET | `/esim` | eSIM plans (Vivo Controle, Brazil) with your price, the area codes in stock and preorders for other area codes. Only works on accounts with eSIM enabled by support; others get not_allowed. |
| POST | `/esim/orders` | Buy 1 eSIM with an area code in stock. Body: plan, area_code, optional max_price. Send an Idempotency-Key. The answer has status delivered with esim.lpa (the QR code text), smdp_address and activation_code, or pending: check GET /esim/orders/{id}. |
| POST | `/esim/preorders` | Preorder eSIMs with any area code in Brazil (one area code per eSIM, up to 10). Body: plan, area_codes, max_total. Delivered within 1 hour; if not, the price goes back to your balance by itself. |
| GET | `/esim/orders` | Your eSIM orders, newest first (limit up to 100). |
| GET | `/esim/orders/{id}` | One eSIM order. status: pending, ordered, delivered, failed (price returned) or refunded. |

## Buying options (body of POST /numbers)
Only service and country are required. Without server, the number comes from the cheapest server in stock.
| Field | Type | What it does |
|---|---|---|
| `service` | string | App code from /services, for example whatsapp, telegram, google. |
| `country` | string | 2-letter country code, lowercase: us, br, gb. |
| `max_price` | number | Highest price you accept, in your account currency (USD, or BRL for accounts in Brazil). If the live price is above it, nothing is bought (price_above_max). |
| `server` | string | s1, s2, s3, s4 or s5. The number comes only from that server, at that server's price. |
| `area_code` | string | Server 3 (Brazil numbers): 2-digit area code (DDD), for example 11. Adds 30% to the price. |
| `carrier` | string | Server 3 (Brazil numbers): claro, oi, tim or vivo. |
| `provider` | number | Server 4 and Server 5: id of one supply line from /providers. The number comes only from it, at its price. |
| `quantity` | number | 1 to 20 numbers in one call. The answer changes to { requested, bought, data[], errors[] }. |

## Buying many numbers of one app
If you buy the same app all day, this is the shortest path:
1. GET /prices?service=whatsapp shows every country and server with stock for that app. Pick the server with the price you want.
2. POST /numbers with quantity (up to 20 per call) and server. Each number that could not be bought comes back in errors[] and is not charged.
3. Send an Idempotency-Key header on every purchase. If your request times out and you send it again with the same key, you get the first answer back and nothing is bought twice.
4. Set the webhook to receive each code the moment it arrives, instead of polling hundreds of numbers.
5. Cancel what you no longer need with POST /numbers/cancel (up to 50 ids). The price goes back to your balance.
6. GET /account shows how many numbers you can keep open at the same time and your daily limit. Need more? Ask support: limits and prices can be set per account.

## The number object
Every purchase and every number endpoint answers with the same object:
| Field | Meaning |
|---|---|
| `id` | Use it in the other endpoints. |
| `phone` | The number, with country code. null for an email. |
| `type` | sms or email. For an email, the address is in email and the domain in domain. |
| `service, country` | What you bought. |
| `server` | The server the number came from (s1 to s5). |
| `area_code, carrier` | Set when you chose them (Server 3). |
| `status` | See Statuses below. |
| `price, currency` | What was charged from your balance, in your account currency: USD, or BRL for accounts in Brazil. Balance, prices and amounts always come in that same currency. |
| `created_at, cancelable_at, expires_at` | When it was bought, from when it can be canceled, and when it expires. |
| `sms[]` | Every message received: code, text, received_at. |

## Statuses
| Status | Meaning |
|---|---|
| `waiting` | Open for 20 minutes, waiting for an SMS. |
| `received` | At least one SMS arrived. The code is in sms[].code, the full text in sms[].text. |
| `finished` | You released the number after getting the code. |
| `canceled` | You canceled it before any SMS. Price back to your balance. |
| `expired` | No SMS within 20 minutes. Balance back automatically. |

## Webhooks
Set an HTTPS URL in Dashboard → API. When a number bought through the API receives an SMS, we POST an sms.received event, retrying up to 3 times. Reply with any 2xx.
Every request carries X-Signature: t=<unix>,v1=<hex>, the HMAC-SHA256 of "<t>.<raw body>" with your signing secret. Reject timestamps older than 5 minutes.

## Errors
Errors return an HTTP status and { "error": { "code", "message" } }.
| HTTP | code | Meaning |
|---|---|---|
| 401 | `invalid_api_key` | Missing, wrong or revoked key |
| 402 | `insufficient_balance` | Balance too low; needed shows the price |
| 409 | `price_above_max` | Live price is above your max_price; price shows the live price |
| 400 | `no_numbers` | Out of stock; you weren't charged |
| 409 | `queue_available` | Server 4 or 5 has no number right now; you weren't charged. Try again or pick another server |
| 409 | `provider_sold_out` | The supply line you chose ran out; read /providers again |
| 409 | `price_changed` | The cheapest numbers ran out and the next ones cost more; you weren't charged. price shows the new price; send the request again |
| 403 | `not_allowed` | This key is limited to certain apps or servers; GET /account lists them |
| 403 | `server_unavailable` | Server 3 is not enabled for this account |
| 429 | `too_many_active` | Too many open numbers; finish or cancel one first |
| 429 | `daily_limit` | Daily number limit of this key reached; limit and used show the numbers |
| 400 | `too_early` | Cancel before cancelable_at; wait_seconds says how long |
| 400 | `already_closed` | Number already canceled, expired or finished |
| 409 | `rebuy_unavailable` | This number can't be bought again |
| 409 | `request_in_progress` | The same Idempotency-Key is still running; retry in a few seconds |
| 403 | `api_paused` | API access for this account is paused; contact support |
| 403 | `account_suspended` | Contact support |
| 429 | `rate_limited` | More than 120 requests in a minute |
| 503 | `provider_unavailable` | Temporary carrier issue; not charged. Retry shortly |

## Limits and rules
- Loyalty program, only for the API: your level goes up with your weekly top-ups or with the codes you receive through the API, and gives 5% to 30% off every number. Prices returned by the API already include your discount. See your level in the dashboard (API loyalty) or in GET /account, under loyalty: level, discount_pct, valid_until, this week's topped_up and codes_received, and next_level with top_up_missing, codes_missing and progress_pct.
- 120 requests per minute per key. Poll a number no faster than every 3 seconds.
- One number per verification, SMS only, reserved 20 minutes.
- Prices move with supply: read them from /services or /prices, or send max_price.
- Up to 20 numbers per call with quantity. GET /account shows your limits.
- Use the API only for your own accounts, or as a reseller for customers who follow our Acceptable Use Policy. Bulk sign-ups, spam and getting around identity checks close the account.

## Reference implementation (Python)
```python
import os, time, uuid, requests

BASE = "https://www.covesms.com/api/v1"
H = {"Authorization": f"Bearer {os.environ['COVESMS_API_KEY']}"}

def get_code(service: str, country: str, max_price: float, timeout_s: int = 1200) -> tuple[str, str]:
    """Buys one number and waits for the SMS. Returns (phone, code)."""
    r = requests.post(f"{BASE}/numbers", headers={**H, "Idempotency-Key": str(uuid.uuid4())},
                      json={"service": service, "country": country, "max_price": max_price}, timeout=30)
    if r.status_code >= 400:
        raise RuntimeError(r.json()["error"]["code"])
    n = r.json()
    print("Use this number in the app:", n["phone"])
    end = time.time() + timeout_s
    while time.time() < end:
        time.sleep(4)
        n = requests.get(f"{BASE}/numbers/{n['id']}", headers=H, timeout=30).json()
        if n["status"] == "received":
            return n["phone"], n["sms"][-1]["code"]
        if n["status"] in ("canceled", "expired"):
            break
    raise TimeoutError("No SMS arrived; the price went back to the balance.")

```

## More
Full docs: https://www.covesms.com/api/docs · Support: support@covesms.com
