app/api/phone-numbers, inbound-configurations,
sms, and session. All routes require a phone-verified bearer token.
Phone numbers
Search inventory
-
GET /api/phone-numbers/search→["twilio"](provider slugs). -
GET /api/phone-numbers/search/{provider}/countries→ list of countries and supported number types (local,mobile,tollFree, etc.). -
GET /api/phone-numbers/search/{provider}?country=US&type=localreturns available numbers and their pricing. Each entry includes:Field Description name,phoneNumberTwilio metadata for display purposes. capabilities.voice/sms/mmsBoolean flags. addressRequirements"none","local", or"foreign"depending on regulations.price{ currency, amount, jwt }. Thejwtencodes the SKU and is required when purchasing.
Purchase & store addresses
PUT /api/phone-numbers/addresswith{ street, city, region, postalCode, isoCountry, ... }creates a Twilio address SID you can reuse when buying regulated numbers.PUT /api/phone-numbersexpects{ jwt: string }(copied from the search response) plus optionaldescriptionandaddressSid. The route:- Verifies that a default payment method exists (Stripe).
- Reserves the number via Twilio.
- Starts a Stripe subscription so the number stays active.
- Returns the new Telentir phone ID.
Manage purchased numbers
GET /api/phone-numbers→ list all numbers (type, friendly name, references, inbound configuration attachment).GET /api/phone-numbers/{id}→ single record.PATCH /api/phone-numbers/{id}body{ name?: string, description?: string }.DELETE /api/phone-numbers/{id}cancels the Twilio number and its Stripe subscription. Failure to cancel the subscription returns HTTP 502.
Inbound configurations
app/api/inbound-configurations lets you map phone numbers to AI or human
agents with optional knowledge bases.
GET /api/inbound-configurations
Returns all configs for the user, expanding the humanAgents array from the
stored metadata.
PUT /api/inbound-configurations
Body (all required unless noted):
| Field | Description |
|---|---|
name | Display label. |
agent | Object reference { id, type, ... } pointing to an encrypted agent. |
source | Campaign source descriptor (same shape Telentir stores on campaigns). |
humanAgents | Optional array of human agent references; duplicates are stripped. |
description? | Text shown in the UI. |
knowledge_base_id? | Link to a knowledge base uploaded via /api/knowledge-bases. |
GET /api/inbound-configurations/{id}
Returns a single config plus de-duplicated humanAgents.
PUT /api/inbound-configurations/{id}
Updates name/agent/source/human agents. All new agent IDs are validated against
the encrypted object store to ensure they exist.
PATCH /api/inbound-configurations/{id}
Partial updates for name, description, source, and humanAgents.
DELETE /api/inbound-configurations/{id}
Removes the config entirely.
Attach/detach numbers
POST /api/inbound-configurations/{id} body { action: "attach"|"detach", phone_number_id }.
"attach"requires the number’stypeto be"inbound"or"both"."detach"only succeeds if the number is currently attached to the selected configuration.
SMS
POST /api/sms/messages
Body: { phoneNumberId: string, to: string, body: string }.
The route validates ownership of the phoneNumberId, forwards the SMS through
Twilio, and stores Telentir’s webhook URL in statusCallbackUrl so delivery
updates feed back into the dashboard. The response mirrors Twilio’s message SID
and status.
Call sessions
POST /api/session/call
This endpoint executes lib/sessions.call with the data embedded in an
application-specific JWT. Body:
| Field | Description |
|---|---|
jwt | Signed payload created by one of your registered servers. It must decrypt to { agent, contact, humanAgents?, pathway? } (see below). |
server | Server ID (from /api/servers) used to verify and decrypt the JWT. |
agent: encrypted agent record (AI voice, voice settings, etc.).contact: encrypted contact object for the callee.- Optional
humanAgents: extra humans who will be conferenced in. - Either
{ type: "pathway", pathway: ConversationalPathway }or{ type: "prompt", prompt: string }. - Optional
knowledgeBasemetadata if you attach KB functions insidegetPrompt.
getPrompt + getContactPrompt), assembles
available integration functions, and streams the call through the audio server.
The HTTP response is empty (204) – monitor /api/events or your own webhooks
for progress.
Temporary testing sessions
Routes under/api/session/temporary let you spin up quick test calls without
touching encrypted objects. They rely on Twilio and the preconfigured call types
stored in lib/call-types.ts.
| Endpoint | Description |
|---|---|
GET /api/session/temporary | Returns the list of available call type definitions (types). |
PUT /api/session/temporary | Body { phone: string, type: string }. Sends a verification code via SMS and returns a signed key. |
POST /api/session/temporary | Body { key, code, email }. Validates the code, reserves a temporary Telentir phone number, and kicks off a one-off outbound call using the requested call type. The response is the session ID. |
session/temporary/route.ts).
