What you’ll build
A phone number that answers incoming calls with your agent’s greeting and instructions. You can set it up in the console or from your backend. Choose the option that suits your business:
Both options add a dedicated number to your workspace. You then use the same
agent assignment and activation steps. Numbers purchased through Mirai are
recurring rentals; review their charges and renewal terms before confirming.
This recipe currently supports Indian +91 voice numbers. WhatsApp calling has a
separate cookbook.
You need:
- An enabled workspace with enough wallet balance for at least one minute at its applicable calling rate.
- A published agent in that workspace. A draft or archived agent cannot answer incoming calls.
- A dedicated, voice-enabled number purchased through Mirai or connected from your own supported telco. For BYO Plivo only, have your account’s Auth ID and Auth Token available.
- For API setup: your workspace API key, its assigned API host, cURL and
jq, or Python 3.10+ withhttpx, or Node.js 18+.
Purchasing or importing a number is the first step. Assign a published agent
and activate incoming calls to make it answer. Test a real incoming call before
you advertise the number.
How it works
You assign the agent once. Each incoming call uses that assignment; you do not sendPOST /v2/calls to receive a call. That endpoint starts an outgoing call.
Set up in the console
- Open the console and select your workspace. Trial workspaces use the sandbox console.
- Open Phone numbers and follow either option below. If your workspace already has a dedicated number, continue to assign and activate.
Option A: Buy a number through Mirai
- Click Add a number and choose Mirai wallet under Billing account.
- Complete Verify your business if prompted. Submit the requested details and documents, then use Refresh status to check the review result.
- After approval, search the available numbers and select one for your business.
- Review the rental amount, renewal terms, and separate call-usage charges. Confirm the rental from your workspace wallet.
- Once the purchase completes and the number appears in your workspace, continue to agent assignment below.
Option B: Connect your own telco number
- Click Connect Plivo, enter your Plivo Auth ID and Auth Token, and save.
- Select Import a number, then Import beside the voice number you own.
- Once the number appears in your workspace, continue to agent assignment below.
Assign your agent and activate
These steps are the same for numbers purchased through Mirai and BYO numbers:- Create your agent in Agent Studio. Set its greeting, instructions, language, voice, and maximum call duration, then publish it.
- Return to Phone numbers. Under Incoming calls go to, select your published agent and click Save.
- Click Activate incoming calls. Review the routing change, confirm that you want incoming calls to reach Mirai, and activate.
- Call the number from another phone and complete the test below.
Set up through the API
The API uses the same number options. If you purchased a number through Mirai in the console, list it in step 1 and skip the BYO integration and import in step 3. You do not need Plivo credentials for a Mirai-managed number. The agent assignment, activation, and result APIs are the same for both options.1. Choose your API host
Use the host shown with your workspace’s API credentials:
Set
VOICE_BASE_URL and VOICE_API_KEY in your backend environment. For BYO
Plivo, also set PLIVO_AUTH_ID, PLIVO_AUTH_TOKEN, and PLIVO_NUMBER to the
owned number in E.164 format, including +91. Keep secrets on your backend.
Changing the host does not activate a sandbox workspace for production.
Run the shell examples in Bash with set -euo pipefail so a failed request
stops the sequence:
data, has_more, and next_cursor. Follow next_cursor
with ?cursor=… if needed. If your number is already listed, retain its id,
set NUMBER_ID, and skip step 3. To inspect number onboarding availability,
use GET /v2/telephony/options.
2. Create a published agent
Save this asagent.json, then adapt its greeting and instructions for your
business. It has no required caller inputs, so a new caller can reach it
without a customer record.
- cURL
- Python
- Node.js
201 with the agent object. Confirm draft: false and
archived: false. You can also use an existing published agent from
GET /v2/agents in the same workspace.
Caller inputs: incoming calls supply caller_number and called_number.
Any other required input must have a usable default in your agent’s
input_schema; otherwise admission fails. Ask unknown callers for their name
or order number during the conversation. Do not treat caller ID as proof of
identity. See agents and tools for API lookups.
3. Connect your own telco number (BYO only)
Skip this step if you purchased your number through Mirai or it is already in your workspace. The following example connects Plivo, the currently supported BYO provider. If the Plivo integration already exists, get its ID fromGET /v2/telephony/connections instead of
creating it again.
201. The integration should have
state: "verified"; the imported number initially has state: "imported".
Import verifies ownership and leaves existing Plivo routing unchanged. Save
the returned IDs; if a response is lost, list existing resources before retrying.
4. Assign your agent and activate incoming calls
Read the current number before updating it. Every write uses its latestversion; do not hard-code version numbers.
200. Before testing, check:
agent_id matches your published agent.
If another voice application is attached, the safe example above refuses to
replace it. Review the existing routing in Plivo. Only after you decide to move
those incoming calls to Mirai, fetch the number’s latest version and repeat
activation with replace_existing_application: true. After any activation
timeout or failure, GET the number again and inspect state and setup_error
before retrying.
5. Receive events and read results
Optionally set a public HTTPSwebhook_url on the number with PATCH:
GET /v2/calls. Match
direction: "inbound", phone_number_id, and agent_id; retain the call id.
For an incoming call, from is the caller and to is your business number.
Authenticate each request with your workspace API key. Results can take time
to arrive after hangup; check availability on the call before fetching audio
or transcript. See the calls reference.
Test it
- Call the configured number from another phone. You should hear your agent’s greeting without starting a call through the API.
- Say a short phrase, ask the agent to repeat it, and confirm you can both hear each other. Then complete a realistic support question.
- Hang up. Find the incoming call in history and check its number, agent, duration, transcript, available recording, and settled cost.
- If you configured events, verify receipt and signature handling in your backend. Replay a saved event to confirm it does not create duplicate work.
- Repeat the call before publishing the number to customers.
Troubleshooting
Change or pause incoming calls
To switch agents, PATCH the number with its latestversion and the new
agent_id. New calls use the new assignment; accepted calls retain their agent
snapshot. Publishing or editing an agent affects later calls. Archiving it or
leaving its latest configuration as a draft stops it answering new calls.
To stop new incoming calls for one number, PATCH agent_id: "" with the
current version. To disable an entire Plivo integration, PATCH
/v2/telephony/connections/{id} with its current version and
state: "disabled". Disabling also blocks new outgoing calls through it.
POST /v2/telephony/connections/{id}/verify verifies credentials and re-enables
the integration.
Unassigning or disabling does not release the number, cancel its rental, or
restore its previous Plivo application. Manage rentals separately and coordinate
restoring previous voice routing if you move away from Mirai.
Billing and privacy
Mirai call usage follows your workspace’s pricing. For BYO Plivo, Plivo bills your provider account separately. Managed number rental and renewal charges are separate from call usage; review the displayed terms. Tell callers they are speaking with an AI voice agent and provide appropriate recording notices. Keep API keys, Plivo tokens, webhook secrets, transcripts, and recording links private. Apply access controls and retention rules for your business, including GDPR, HIPAA, or TCPA requirements where applicable. This recipe does not establish regulatory compliance.Production checklist
- The workspace is enabled and funded, and the number belongs to it.
- The correct published agent is assigned, with defaults for required inputs.
- The number is ready, its integration is verified, and real incoming calls have passed the audio and result checks.
- Webhook verification, caller notices, result access, and retention are set up.
- Your expected concurrent-call volume and number renewal arrangements are confirmed.