Tutorial

Build a production-shaped voice agent.

Follow an end-to-end path from agent contract to outbound calls, inbound telephony, observability, and launch acceptance criteria.

Target architecture

Start with one tenant, one approved agent, one inbound phone route, and one outbound workflow. Keep runtime credentials, admin credentials, and webhook consumers owned by separate deployment surfaces.

Runtime app

Customer-facing calls

Uses tenant bearer auth to create outbound calls and read sessions, call logs, and evaluations.

Control plane

Internal automation

Uses admin auth to configure tenants, agent versions, phone routes, and rollout gates.

Event consumer

Business systems

Receives webhook events, deduplicates delivery, and writes outcomes into CRM, ticketing, or analytics systems.

1. Define the agent contract

DecisionExampleWhy it matters
Supported intentsAppointment confirmation, order status, missed-call recoveryLimits what the agent can promise and what tools it may call.
Escalation rulesPayment, identity failure, complaint, repeated low confidenceProtects customers and keeps regulated or sensitive work human-reviewed.
Success signalsResolved, transferred, callback created, no answer, failed authenticationGives operators and analytics teams a stable outcome model.
Launch gates20 synthetic calls, 95% signature verification, no duplicate outbound callsTurns voice launch from a demo into a controlled production workflow.

2. Configure runtime behavior

Use admin automation to attach the model, voice, prompt key, and telephony defaults to the tenant or agent version that will receive traffic.

curl -sS -X PUT "https://voice.stateset.app/api/v1/admin/tenants/${TENANT_ID}/runtime-config" \
  -H "x-admin-key: ${STATESET_ADMIN_API_KEY}" \
  -H "content-type: application/json" \
  -d '{
    "model": "gpt-realtime",
    "voice": "alloy",
    "system_prompt_key": "front_desk_v1",
    "webhook_url": "https://api.example.com/webhooks/stateset-voice"
  }'

3. Start the first outbound call

Use POST /api/v1/make-call to create the first customer-facing outbound workflow.

curl -sS -X POST "https://voice.stateset.app/api/v1/make-call" \
  -H "Authorization: Bearer ${STATESET_VOICE_API_KEY}" \
  -H "content-type: application/json" \
  -d '{
    "to": "+15555555678",
    "from": "+15555551234",
    "agent_key": "front_desk",
    "greeting": "Hi, this is Acme calling to confirm your appointment."
  }'
Persist the response: store the returned call identifier with your business record so later call logs, voice sessions, and webhook events can reconcile to the original workflow.

4. Receive inbound traffic

Configure Twilio to POST signed inbound calls to StateSet Voice. Route numbers to tenants and agents before production traffic moves over.

Twilio fieldValue
Voice webhookhttps://voice.stateset.app/api/v1/incoming-call
HTTP methodPOST
SecurityValidate X-Twilio-Signature and keep fallback routing configured.
MonitoringWatch readiness, call status callbacks, media stream setup, and session creation.

5. Observe outcomes

curl -sS "https://voice.stateset.app/api/v1/call-logs?limit=25" \
  -H "Authorization: Bearer ${STATESET_VOICE_API_KEY}"

curl -sS "https://voice.stateset.app/api/v1/voice-sessions?limit=25" \
  -H "Authorization: Bearer ${STATESET_VOICE_API_KEY}"

Review call status, duration, transcript turns, tool calls, escalations, summaries, tags, and evaluation score before broadening the rollout.

Production acceptance criteria

Security

Tenant keys, admin keys, Twilio auth token, and webhook secrets are stored separately and rotated by environment.

Behavior

Each supported intent has a synthetic call, expected transcript outcome, and approved escalation path.

Reliability

Clients retry only safe failures, webhook consumers deduplicate by event ID or call/session ID, and duplicate outbound calls are blocked.

Operations

Dashboards track call creation, answer rate, transfer rate, failed webhooks, error rate, and provider health.