carrier — the telephony company it belongs to — is twilio, the
default, telnyx (see Telnyx numbers), or asterisk for a
PBX of your own (see Asterisk numbers), and is fixed once
bound: a PUT naming a different carrier is a
422. provider is accepted for it as a deprecated alias, and reads still
carry provider beside carrier; prefer carrier, since “provider” means an
STT, LLM or TTS backend everywhere else in the API.
Bind a Phone Number
Static routing (to an agent)
Dynamic routing (server URL)
Route calls to a webhook that decides which agent to use:Telnyx numbers
A Telnyx number answers inbound calls through Telnyx Call Control. Bind it with"carrier": "telnyx". TurnCall looks the number up on your Telnyx account, so
external_number_sid (its Telnyx phone number id) is optional — and a number
the account does not hold is refused with a 422 naming it:
TurnCall <your host>, whose webhooks go to
https://<your host>/webhooks/telnyx/voice — created on the first bind (on
your account’s outbound voice profile, if it has exactly one; otherwise pick
one for it in Mission Control before dialling out), corrected on every bind or
update, and deleted when the last number leaves it. The number is moved onto
it; webhooks_configured in the response says whether that worked (it needs
PUBLIC_BASE_URL). Unbinding takes the number off again, unless it has since
been moved to another connection, which is left alone. The agent, its tools,
recording, ambience and voicemail detection behave exactly as on a Twilio
number.
The Telnyx account is the platform’s TELNYX_API_KEY and TELNYX_PUBLIC_KEY,
or the project’s own:
error.raised event carries
missing_keys: ["telnyx"].
Cold and warm transfers and sending DTMF work on a Telnyx number as on Twilio (see
Call transfer), and so do outbound
calls (POST /v1/calls/outbound, campaigns). Telnyx dials on the number’s Call
Control application, so a number on none is refused with a 409. SMS on Telnyx
numbers is not supported, so sms_enabled is refused on one.
Bring your own Twilio account
A number can run on its own Twilio account instead of the platform’sTWILIO_ACCOUNT_SID / TWILIO_AUTH_TOKEN. Send the pair — both or neither —
and external_number_sid becomes optional: TurnCall looks the number up on that
account, which is also what proves the account owns it.
- Credentials that Twilio rejects, or that do not own the number, are a
422— nothing is bound. - The token is stored encrypted under
CREDENTIAL_ENCRYPTION_KEYand never returned. Reads carrytwilio_account_sidandtwilio_credentials(numberorplatform). - Every Twilio operation for that number uses its account: webhook
configuration, outbound calls, hang-up, transfer, DTMF, recording download,
and the signature check on its inbound webhooks (matched by the webhook’s
AccountSid). PUT /v1/phone-numbers/{id}with a new pair replaces it — rotating a token. Omitting the pair keeps the stored one.
With no platform Twilio account configured, an inbound webhook TurnCall cannot
verify passes only while no number carries its own account (a development
setup). Once any does, an unverifiable webhook is refused.
server_url returns a server_url_secret — TurnCall signs each call-init request with it so your endpoint can verify the source.
Search and buy a number
A number you do not have yet can be found and bought through the API, then bound like any other. Both calls take an admin key: buying spends money on the carrier account. A developer or viewer key gets a403. Both work on
Twilio and on Telnyx (carrier=telnyx); an Asterisk PBX’s
numbers belong to its dialplan, so carrier=asterisk is a 422.
Search the account’s available numbers. Every filter is optional: country
(ISO code, default US), number_type (local, the default, toll_free or
mobile), area_code, contains (2 to 16 digits) and limit (1 to 50,
default 20). Only voice-capable numbers are listed.
null: Twilio’s search gives no price, Telnyx’s
gives no friendly_name or postal_code.
Buy one:
201 response is what binding needs. Send its carrier, e164_number
and external_number_sid to POST /v1/phone-numbers with the routing you
want:
- Which Twilio account. Without a pair, the platform’s
TWILIO_ACCOUNT_SID/TWILIO_AUTH_TOKENaccount searches and buys. To use your own Twilio account, sendtwilio_account_sid+twilio_auth_tokenin the buy’s body, and theX-Twilio-Account-Sid+X-Twilio-Auth-Tokenheaders on the search (headers keep the token out of the URL). The buy then returnstwilio_account_sidand"twilio_credentials": "number". Bind with the same pair; the token is never returned. With neither a pair nor a platform account the call is a503(no_twilio_account). - Refusals. A number Twilio will not sell (already taken, or its country
needs an address or regulatory bundle on the account first) is a
422with Twilio’s message anddetails.twilio_code. A number already bound in TurnCall is a409. Anumber_typeTwilio does not sell in that country is a422. Credentials you sent that Twilio rejects are a422; anything else Twilio fails on is a502(twilio_error). - Audited. Each purchase writes an audit log entry,
phone_number/purchased, whoseresource_idis the E.164 number (a bought number has no binding yet). See Audit log. - Billing. The number stays on the carrier account, and is billed, until it
is released. Unbinding (
DELETE /v1/phone-numbers/{id}) does not release it. - If TurnCall cannot record it. The carrier has sold the number by the
time TurnCall records the purchase, so a failure then (the database, the
audit log) does not undo it. The call is a
500(internal_error) whosedetails.boughtnames the number (e164_number,external_number_sid,telnyx_order_id), and the operator’s logs carry it at error level (phone_number_bought_untracked). Bind it, or release it in the carrier’s console.
Buying on Telnyx
The same two calls withcarrier=telnyx search and buy on the project’s
Telnyx account: its telnyx credential, else the platform’s TELNYX_API_KEY,
the account binding uses. With neither, the call is a 503
(no_telnyx_account, details.missing_keys: ["telnyx"]). The X-Twilio-*
headers and the twilio_* body fields are refused (422) on Telnyx.
upfront_cost, monthly_cost, currency, as Telnyx sends them).
A Telnyx purchase is a number order, which Telnyx completes
asynchronously. The call waits up to about five seconds for it:
"status": "active": the order went through and the number is on the account.external_number_sidis its Telnyx phone number id. Bind it now."status": "pending": the order is placed, and paid for, but Telnyx has not finished it (it is slow, or the number’s country needs documents in the Telnyx portal first).external_number_sidisnull. Bind with justcarrierande164_numberonce Telnyx completes it: bind looks a Telnyx number up on the account by its E.164 and refuses it (422, “not a phone number on this project’s Telnyx account”) until it is there.
telnyx_order_id is the number order, to look up in the Telnyx portal; it is
not the number’s id. Bound, the number goes onto this deployment’s Call
Control application like any other Telnyx number. A number Telnyx will not
sell is a 422 with details.telnyx_codes; an order Telnyx accepts and then
fails, or that ends cancelled or deleted, is a 422 with
details.telnyx_order_id, and buys nothing. An API key Telnyx rejects is a
422; anything else Telnyx fails on is a 502 (telnyx_error). If Telnyx
does not answer the order at all (a timeout), the call is a 502
(telnyx_error) saying the order may have been placed: check the account’s
number orders in the Telnyx portal before buying the number again. A pending
purchase is audited like any other: the money is spent.
Release a number
Releasing gives a number on the carrier account back to the carrier, so it stops being billed. It takes an admin key (a developer or viewer key gets a403) and works on Twilio and Telnyx, on the same account a
purchase uses.
Three guards make a release deliberate:
- Unbound numbers only. A number TurnCall still binds is refused with a
409;details.phone_number_idnames the binding when it is your project’s. Unbind it first withDELETE /v1/phone-numbers/{phone_number_id}, which leaves the number on the account. - An explicit confirmation.
confirmmust repeate164_numberexactly. Without it, or with anything else (true,"yes", another number), the request is a422and nothing is released. - Your purchases only, on the shared platform account. The platform’s
carrier accounts hold every project’s numbers: Twilio’s
TWILIO_*account (used when you send notwilio_account_sid+twilio_auth_token) and Telnyx’sTELNYX_API_KEY(used when the project has notelnyxcredential). A release there is allowed only for a number your project bought withPOST /v1/phone-numbers/purchase. Any other number, including one another project bought or one put on the account outside TurnCall, is a403(forbidden,details.account: "platform"), and the carrier is not asked anything. A release on your own account (your Twilio pair, or your project’stelnyxcredential) has no such limit.
- Which account. On Twilio, the
twilio_account_sid+twilio_auth_tokenpair in the body, else the platform’sTWILIO_*account (503no_twilio_accountwith neither). On Telnyx ("carrier": "telnyx"), the project’stelnyxcredential, else the platform’sTELNYX_API_KEY(503no_telnyx_accountwith neither).carrier=asteriskis a422. On the platform’s account, only a number your project bought there is released (see above). - Found by its number. TurnCall looks the number up on the account by its
E.164 and releases what it finds (Twilio’s PN SID, Telnyx’s phone number id,
returned as
external_number_sid). A number the account does not hold is a422, and so is a Telnyx number whose order has not finished. - Refusals. Credentials you sent that the carrier rejects, and anything
Telnyx refuses, are a
422; anything else the carrier fails on is a502(twilio_error,telnyx_error), and nothing is recorded. If Telnyx does not answer the release itself, the502says the number may have been released: check the account before releasing it again. - Deleting the project. Numbers your project bought on the platform’s
account are not released when the project is deleted. Once a deleted
project is purged, TurnCall no longer knows they were its, so nobody can
release them through the API: release them before deleting the project. The
purge logs a warning (
purged_project_left_numbers) naming each one it leaves on the account, still billed, for the operator to release in the carrier’s console. - Audited. Each release writes an audit log entry,
phone_number/released, whoseresource_idis the E.164 number and whose “before” is the number released. See Audit log.
Update a Binding
Re-route a number in place — the phone id and itsserver_url_secret stay stable, so a call-init endpoint keeps verifying with the same secret across edits:
server_url appears on a number that never had one; it is never rotated implicitly.
Configure Twilio
TurnCall sets these on bind whenPUBLIC_BASE_URL is configured (the response
says so in webhooks_configured; twilio_webhooks_configured is the same
value under its older, Twilio-only name). To set them by hand:
- Voice URL:
https://your-host/webhooks/twilio/voice/inbound(POST) - Status URL:
https://your-host/webhooks/twilio/status(POST)
Asterisk numbers
A number on your own Asterisk (a call centre or company PBX) reaches an agent over ARI, with no cloud carrier in between. It needs Asterisk 20.18, 22.8, 23.2 or later (the WebSocket channel driver with JSON control messages). 1. Give TurnCall your Asterisk as the project’sasterisk credential.
TurnCall connects to its ARI events WebSocket and keeps it open:
app (the Stasis app, default turncall),
media_connection (the websocket_client.conf entry, default turncall),
transfer_context (default turncall-transfer).
2. Configure the PBX. ari.conf holds that user; websocket_client.conf
tells Asterisk where to send call audio; the dialplan hands calls to the app,
and the transfer context dials what an agent transfers to:
Stasis argument is the number TurnCall looks up (without one, the
channel’s extension; bare digits get a +). A call TurnCall cannot take —
an unknown number, say, or one over the project’s live-call limit (which also
sends call.rejected) — goes back to the dialplan unanswered, at the line
after Stasis. The caller’s channel carries TURNCALL_CALL_ID from then on.
3. Bind the number with carrier: "asterisk". It has no SID, Twilio
account or SMS, and twilio_webhooks_configured is null:
end_call, send_dtmf, live call control, recording and analysis. What
differs:
- Transfers are cold only. The caller continues in the transfer context
with the target as extension. A warm transfer, a
transfer_messageor afallback_messageis refused, and the agent is told why. - No outbound calls or SMS from an Asterisk number.
- The caller’s leg needs continuous audio, as a SIP trunk sends; turn off silence suppression on endpoints that use it.
- One TurnCall replica holds the ARI connection. Asterisk gives an app’s
calls to one connection only; with several replicas, set
ASTERISK_EDGE_ENABLED=falseon all but one.
ASTERISK_ARI_URL, ASTERISK_ARI_USERNAME,
ASTERISK_ARI_PASSWORD); a project with its own credential uses its own.
SIP trunks
TurnCall has no native SIP endpoint, so a SIP trunk is never pointed at TurnCall directly. It reaches an agent in one of two ways:- Through Asterisk. The trunk lands on your Asterisk, which hands each call to TurnCall over ARI. No cloud carrier sits between your PBX and TurnCall.
- Through Twilio or Telnyx. Your phone system sends the call over a Twilio or Telnyx elastic SIP trunk to a number bound here, and the carrier delivers it to TurnCall like any other call.
SMS Support
Enable SMS on a phone number to handle both voice calls and text messages:sms_enabled: true is set on bind, TurnCall auto-configures the Twilio SMS webhook. See SMS / Chat for details.