Staging for most APIs is simple: a second database, a second key, a lower bill. Texting adds a problem, because a mistake in staging can reach a real phone, cost real money and put a real person on an opt-out list. A copied production table in a staging database is enough to text customers from a test run.
This guide covers how to separate the two when you text through an API: which of the three setups to pick, what to do with keys, webhooks and numbers, and one opt-out behavior that decides how separate "separate" really is. We make Ready, so the specifics use only what our API documents. The ideas apply to any provider.
Three ways to separate staging from production
You have three levers, and they can be combined. They differ in how much a mistake can reach.
| Setup | What it isolates | What it can't do |
|---|---|---|
| Test key in staging | Nothing is sent or charged. Results come back with a test-msg- id | Prove delivery, registration or quiet hours behavior |
| A staging sub-account with its own live key | Its own numbers and its own registration | Guarantee that opt-outs stay inside it (see below) |
| A separate account for staging | Keys, numbers, card, opt-out list and billing | It's another card and number to pay for and manage |
Most teams run the first for everyday work and the third or second for a pre-release check against real phones. Start by deciding which environment needs to send for real. Local development and CI almost never should.
Use a test key everywhere that doesn't need a handset
A test key simulates POST /v1/messages and POST /v1/messages/bulk. Nothing is sent or charged, and each result has a test-msg- id and its segments. It needs no card and no number. Create one in Settings, Developers, Environment: Test. Writes it can't simulate answer 403 test_key_not_allowed, so a test that wanders into something that bills fails loudly. See the test keys docs.
Put the test key in every environment that isn't production by default: laptops, CI, preview deploys and the shared staging server. A live key then has to be added on purpose, which is a much better failure mode than having to remember to remove one. The sandbox and test numbers guide covers what a simulated send proves and what it doesn't.
When staging needs real sends
Some things only a real send can show: how a code looks on a handset, a STOP round trip, segment counts with your real template, and how quiet hours treat a number in another time zone. For those, give staging a live key, and make the account around it small.
Every text is charged from the first one, at $0.0075 per segment plus a $0.0045 carrier fee per segment. To send for real you need a card on file and a number of your own, which is $2 a month. An account can send up to 500 texts a calendar month until its registration is approved, and that's plenty for a pre-release check on staff phones. A new sub-account sends from its own number on Ready's shared registration until its own registration is approved, unless its Organization chose one of its own campaigns for it when it was created. Most approvals take 2 to 7 days, so a staging sub-account doesn't need its own registration to be useful. Our 10DLC explainer says when you do need one.
Sub-account or separate account
A platform that texts for its own customers already uses sub-accounts, one per customer, each with its own numbers. You create them with POST /v1/sub-accounts and list them with GET /v1/sub-accounts. The sub-accounts docs have the details, and our multi-tenant architecture guide explains the tenant model.
A staging sub-account is a cheap, tidy way to keep test traffic apart from customer traffic: its own number, so no tester ever sees a customer's number and no customer sees a test text. But think about opt-outs before you settle on it. A STOP always blocks that number in the sub-account that received it, and it can reach further than that: don't assume it stays inside the sub-account. So a staff member who replies STOP to a staging text may find their number refused in production too.
You can check instead of guessing: call GET /v1/opt-outs/:phone against the production key after a staging STOP test. If you want a guarantee, use a separate account for staging. It costs another card and number, and it gives you a fully separate opt-out list. Read more in the opt-outs docs.
Keys, secrets and a boot check
Separate keys per environment is the baseline, and it's easy to say and hard to keep. A few habits help:
- Each environment reads its key from its own secret store path, never from a shared config file. Our key security and rotation guide and the secrets manager guide cover storage.
- Name the variable the same everywhere, such as
READY_API_KEY, so code never branches on the environment. Only the value changes. - At boot, refuse to start if
APP_ENVisn't production and the key's SHA-256 fingerprint matches the production fingerprint you keep in config. You never store the key itself that way. - Give CI its own key. A key shared between CI and production can't be rotated without breaking both.
- Rotate on a schedule, and when someone leaves, with an overlap window, as in the rotation guide.
Webhooks per environment
A webhook is configured per account, so each environment needs its own receiver URL and its own signing secret. A staging receiver that accepts production's secret is a way for a production event to reach staging data, and the reverse. The webhook is saved with PUT /v1/webhooks, and you can rotate its secret with regenerate_secret. The webhooks docs have the events, and our guide to testing webhooks locally covers the tunnel side.
If you text for many customers, set include_sub_accounts so each event says which sub-account it came from, and map that to a tenant once, when you create the sub-account. Do the same mapping in staging, with staging tenants only.
Test numbers and test data
The commonest staging accident is a production table restored into staging. The text goes to a real person, and it's your own test run that sent it. Three guards stop it:
- No production phone numbers in staging data. Seed with placeholders in the reserved 555-01xx range, such as
+12125550199, which can't reach anyone. - An allowlist in your own code. In any non-production environment, check each recipient against a short list of staff numbers who agreed to be texted and refuse everything else before you call the API.
- A log of what would have been sent. In staging, log destination and template for each send attempt so a test run can be audited.
An allowlist number is still a person. They agreed, and STOP works for them.
A pre-release checklist
| Step | Environment | Key |
|---|---|---|
| Unit and integration tests | CI | Test key |
| Journey tests in a browser | Staging | Test key |
| Real send to staff phones, STOP round trip, quiet hours case | Staging sub-account or separate account | Staging live key |
| Smoke send after deploy | Production | Production key, one number you own |
| Compare the two environments' webhook settings | Both | Each environment's own key |
Keep the claims separate in your release notes: "test key passed" means your code is shaped right, and "real send arrived" means the live path works.
The short version
Default every non-production environment to a test key, give real sends a small staging sub-account or a separate account, and check what a STOP does across them before you trust the separation. Use different keys, webhook URLs and secrets in each environment, seed staging with placeholder numbers, and add an allowlist in your own code. The API quickstart shows how to create keys, and the pricing page lists the current figures.
Accounts opened before November 12, 2026 keep their signup prices, shown under Billing.