Every API here is available over the APIs.io API and to AI agents over MCP.
openapi: 3.2.0
info:
title: PyAI AMD API
version: 2.14.0
description: 'Telephony-native Voice AI behind one bearer key:
- **Hear**, speech-to-text · `POST /v1/audio/transcriptions` (streaming + batch)
- **Speak**, text-to-speech · `POST /v1/audio/speech`, `GET /v1/voices`
- **Clone**, custom voices from a short clip · `/v1/voice/clones`
- **Cast**, auto-directed expressive voiceovers · `/v1/cast`
- **Dub**, asynchronous audio and video dubbing · `POST /v1/dub` (guide)
- **Cue configuration frames (reserved)**; Hear streams skip knowledge-base retrieval by default
- **Omni**, full-duplex agentic voice (speech-to-speech, grounded in your knowledge bases + tools) · `/v1/omni`
- **Knowledge Bases**, hosted grounding for Omni: create bases, add documents (file, URL, or text), crawl a public website, bind to agents or org defaults · `/v1/knowledgebases`
- **AMD API**, answering-machine detection: know *who or what* answered a call (human, voicemail, IVR, iPhone/Google screening, dead number) with the reason it decided · `wss …/v1/amd/stream` (Twilio Media Streams drop-in), `POST /v1/amd/config`, `GET /v1/amd/calls/{id}`
- **Agents Beta**, the live console feature to create, configure, test, and connect Omni voice agents without code. Beta features and limits may change. ## Identity, billing and authentication
- Before any generation or transcription, call GET /v1/me (MCP: whoami). Verify org_id, project_id, environment, scopes, limits and billing/credit context against the intended project. Do not infer identity or free usage from a key prefix or tool name. Stop on a mismatch or unknown budget; never switch to a live project automatically. - Test usage has enforced limits; live usage is billed. Current meters and rates: https://pyai.com/pricing. Agree a bounded input/request count before generating, and do not retry uncertain billable submissions blindly. Create a key in the console (it is shown once) and send it as a bearer token:
```
Authorization: Bearer pyai_live_... ```
Keys are environment-scoped: `pyai_live_...` (production) and `pyai_test_...` (sandbox). `POST /v1/sandbox/keys` creates an instant, short-lived test key without login or billing. Account signup also creates a sandbox key. Live keys consume prepaid credit; phone verification may unlock promotional credit under graduated-signup rules, but credit is not guaranteed at signup. Keys are self-validating signed tokens: they work on every PyAI surface the instant they are created, no activation or propagation delay. Treat them as opaque strings (up to 512 chars) and never parse their contents. Keep long-lived keys on trusted servers. For Omni browsers, mint an origin-locked short-lived token on your backend with POST /v1/omni/sessions; never expose a live or test API key in browser code. Offer the protocol marker and session token:
```
Sec-WebSocket-Protocol: pyai.v1, pyai-key. ```
(server-side clients may instead append `?api_key=...` to the URL). Your key is authenticated on the upgrade and never reaches the model. ## Quickstart, Hear (speech-to-text)
```
curl https://api.pyai.com/v1/audio/transcriptions \
-H "Authorization: Bearer $PYAI_API_KEY" \
-F file=@audio.wav -F model=pyai-hear
# -> { "text": "..." }
```
## Quickstart, Speak (text-to-speech)
```
curl https://api.pyai.com/v1/audio/speech \
-H "Authorization: Bearer $PYAI_API_KEY" \
-H "Content-Type: application/json" \
-d ''{"model":"pyai-speak","input":"Hello from PyAI.","voice":"voice_abc"}'' \
--output speech.wav
```
`voice` is a stock voice id from `GET /v1/voices` (the curated prebuilt catalog with personas and avatars) or a cloned voice id from `/v1/voice/clones`. Omit it to use the platform default voice (`stock_dorit_en_us`).'
contact:
name: PyAI
url: https://pyai.com
servers:
- url: https://api.pyai.com
description: Production
security:
- apiKey: []
- xApiKey: []
tags:
- name: AMD
description: 'Answering-machine detection: know who or what answered a call (human, voicemail, IVR, iPhone/Google screening, dead number), with the reason it decided. Twilio Media Streams drop-in over `wss …/v1/amd/stream`; one operating-point dial; billed per answered call.'
paths:
/v1/amd/stream:
get:
tags:
- AMD
summary: Answering-machine detection (WebSocket)
description: 'Realtime answering-machine detection over a WebSocket. **This surface speaks Twilio''s Media Streams protocol natively** (`start` / `media` / `stop` frames, G.711 μ-law 8 kHz base64, ~20 ms), so migrating from Twilio AMD is a one-line-TwiML change, point the call''s media at PyAI, keep your carrier and your code. ```xml
```
Use ``, NOT ``. `` forks the audio and TwiML continues to your next verb, so the call still goes where it was going; `` hands the media path to the socket and blocks TwiML until the stream ends, and because AMD is listen-only and never sends audio back the caller would hear dead air and a dialer would never reach the agent. (`` is correct for Omni, which is a two-way voice agent.) Drop `machineDetection` from the call and keep your carrier. On a Twilio-originated stream TWILIO owns the socket and relays only media/mark frames, so the pushed `amd` event does not reach you: a Twilio integration must read the decision from the `webhook` `` (or `GET /v1/amd/calls/{id}`). The socket push is for clients that drive the socket themselves. From Twilio, authenticate with the `api_key` `` shown above (Twilio strips query strings from the `` URL and cannot send headers; PyAI verifies the key from the stream''s `start` frame before processing any audio, and closes connections that never present a valid key). Server-side clients may instead authenticate at the handshake with the `Sec-WebSocket-Protocol: pyai.v1, pyai-key.` subprotocol pair or `?api_key=`. Requires the `amd:detect` scope. Mid-call, PyAI pushes an `amd` decision event on the socket (and to the per-call TwiML `webhook` parameter): `answered_by` (the routing class: `human`, `machine`, `sit_invalid`, `unknown`), `answered_by_twilio` (Twilio''s exact `AnsweredBy` enum for drop-in routing parity), `subtype` (when available), `party_detected`, `voicemail_ready`, `confidence`, `decision_ms`, and a human-readable `reason`. `party_detected` is true for human or machine classification and false for unknown or invalid-number outcomes. `voicemail_ready` is false on classification events: detecting voicemail does not establish that recording has started or authorize dropping a message. `decision_ms` measures processed inbound audio through the decision, not elapsed time from carrier answer. A `machine` decision can carry a `subtype` (`voicemail`, `ivr`, `screening`, `music`); the stored call record folds that subtype into `answered_by`. Read the stored record with `GET /v1/amd/calls/{id}` or receive it on the account-wide `amd.call.completed` webhook (`webhook_url` in `POST /v1/amd/config`). The per-call `aggressiveness` `` overrides the account default from `POST /v1/amd/config`. Decision events also include `engine_version` (decision-policy identity), `rule_id` (stable rule identifier), `speech_ms` (cumulative voiced audio excluding pauses, null if untracked), `silence_ms` (current contiguous silence), `speech_elapsed_ms` (audio since first voiced frame including pauses, null without onset), and `thresholds` (effective window, human dwell, early-yield hold and rule flags). These optional diagnostics also appear on new stored call details and the account-wide completion webhook; older records may omit them. Historical turn-yield reasons called elapsed time including trailing silence `speech`; use the new structured fields for comparisons. Confidence is a rule score, not a calibrated probability. Temporal human decisions require at least 200 ms of measured speech; isolated pulses cannot qualify just by waiting in silence. English introductions allow 2500 ms of silence for continuation, while complete recognized greetings can qualify after 500 ms of silence. Recognized call-progress tones are excluded from speech evidence. Without an explicit decision_window_ms override, the English 5000 ms base window can extend once by up to 2000 ms for recent speech or pending recognition; thresholds.effective_deadline_ms records the resulting deadline.'
operationId: amdStream
responses:
'101':
description: WebSocket upgrade, Twilio Media Streams protocol; PyAI emits `amd` decision events.
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
/v1/amd/config:
get:
tags:
- AMD
summary: Get AMD config
description: The org's AMD operating point (`aggressiveness`, 0-1) and webhook URL. Requires `amd:configure`.
operationId: getAmdConfig
responses:
'200':
description: AMD config
content:
application/json:
schema:
$ref: '#/components/schemas/AmdConfig'
'401':
$ref: '#/components/responses/Unauthorized'
post:
tags:
- AMD
summary: Set AMD config
description: 'Set the account-default operating point and webhook. `aggressiveness` is one dial on the ROC curve: near **0** is human-safe (never hang up on a person, for live-agent dialers; on the deadline it returns `unknown` rather than risk a false `machine`), near **1** fires `machine` fast (for AI voicemail-drop bots). A per-call TwiML `` overrides this. Requires `amd:configure`.'
operationId: setAmdConfig
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/AmdConfigInput'
responses:
'200':
description: Updated AMD config
content:
application/json:
schema:
$ref: '#/components/schemas/AmdConfig'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
/v1/amd/calls:
get:
tags:
- AMD
summary: List AMD decisions
description: Recent AMD decisions for this org, newest first. Requires `amd:read`. Filter by `session_label` (the opaque tag you passed on the connect URL / TwiML).
operationId: listAmdCalls
parameters:
- name: limit
in: query
required: false
schema:
type: integer
minimum: 1
maximum: 100
default: 20
- name: cursor
in: query
required: false
schema:
type: string
description: Pass the previous page's `next_cursor`.
- name: session_label
in: query
required: false
schema:
type: string
responses:
'200':
description: Paginated AMD decision list
content:
application/json:
schema:
$ref: '#/components/schemas/AmdCallList'
'401':
$ref: '#/components/responses/Unauthorized'
/v1/amd/calls/{call_id}:
get:
tags:
- AMD
summary: Get an AMD decision
description: 'The full decision for one call: `answered_by`, `answered_by_twilio`, `confidence`, `decision_ms`, and the word-level `reason`. Requires `amd:read`.'
operationId: getAmdCall
parameters:
- name: call_id
in: path
required: true
schema:
type: string
responses:
'200':
description: AMD decision detail
content:
application/json:
schema:
$ref: '#/components/schemas/AmdCall'
'401':
$ref: '#/components/responses/Unauthorized'
'404':
$ref: '#/components/responses/NotFound'
components:
responses:
Forbidden:
description: 'Key lacks the required scope or the origin is not allow-listed (`code: forbidden | origin_not_allowed`)'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
BadRequest:
description: Invalid request (bad field, unsupported value)
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
NotFound:
description: 'Resource not found (`code: not_found`)'
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
Unauthorized:
description: 'Missing or invalid API key (`code: unauthorized`)'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
schemas:
ErrorCode:
type: string
description: Stable, machine-readable error code. Branch on this rather than the human `message`.
enum:
- invalid_request_error
- invalid_session_label
- unauthorized
- forbidden
- origin_not_allowed
- credit_exhausted
- key_budget_exceeded
- child_budget_exceeded
- insufficient_quota
- rate_limit_exceeded
- concurrency_limit_exceeded
- daily_cap_exceeded
AmdDecisionDiagnostics:
type: object
description: Optional structured evidence on new AMD decisions; older records may omit it.
properties:
engine_version:
type: string
description: Decision-policy identity.
rule_id:
type: string
description: Stable decision rule identifier.
decision_timeout_ms:
type: integer
minimum: 1000
maximum: 15000
description: Requested elapsed decision budget. Present when explicitly configured on the stream.
decision_elapsed_ms:
type: integer
minimum: 0
description: Elapsed milliseconds from accepted authenticated start to result preparation; excludes webhook transport. Present when decision_timeout_ms was requested.
speech_ms:
type: integer
nullable: true
minimum: 0
description: Cumulative voiced audio excluding pauses; null if untracked.
silence_ms:
type: integer
minimum: 0
description: Current contiguous silence in ms.
speech_elapsed_ms:
type: integer
nullable: true
minimum: 0
description: Audio since speech onset including pauses; null without onset.
thresholds:
type: object
additionalProperties:
oneOf:
- type: number
- type: boolean
description: Effective decision thresholds and rule flags.
AmdCallListItem:
type: object
properties:
object:
type: string
example: amd.call
call_id:
type: string
session_label:
type: string
nullable: true
description: The opaque tag passed on the connect URL / TwiML, if any.
status:
type: string
enum:
- completed
- failed
answered_by:
type: string
enum:
- human
- machine
- voicemail
- live_voicemail
- screening
- ivr
- music
- human_gatekeeper
- sit_invalid
- fax
- silence
- unknown
description: PyAI's richer answered-by vocabulary. `machine` means an automated answer without an established subtype; it does not establish voicemail readiness or authorize hanging up. `screening` = an iPhone/Google call-screening assistant; `sit_invalid` = a dead/disconnected number.
answered_by_twilio:
type: string
nullable: true
description: Twilio's exact `AnsweredBy` enum (human | machine_start | machine_end_beep | machine_end_silence | machine_end_other | fax | unknown), so a Twilio drop-in keeps its routing logic unchanged.
confidence:
type: number
nullable: true
minimum: 0
maximum: 1
decision_ms:
type: number
nullable: true
description: Processed inbound audio through the decision, in ms; not elapsed time from carrier answer.
created_at:
type: integer
description: Unix ms when the decision was written.
AmdCall:
allOf:
- $ref: '#/components/schemas/AmdCallListItem'
- $ref: '#/components/schemas/AmdDecisionDiagnostics'
- type: object
properties:
reason:
type: string
nullable: true
description: 'Human-readable evidence, e.g. "machine phrase: ''please leave a message'' at 1.2s".'
aggressiveness:
type: number
nullable: true
description: Operating point used for this call.
custom_parameters:
$ref: '#/components/schemas/AmdCustomParameters'
started_at:
type: integer
nullable: true
description: Unix ms when the call was answered.
meta:
type: object
nullable: true
error:
type: string
nullable: true
description: Present when status is failed.
AmdConfigInput:
type: object
properties:
aggressiveness:
type: number
minimum: 0
maximum: 1
webhook_url:
type: string
nullable: true
format: uri
AmdConfig:
type: object
properties:
object:
type: string
example: amd.config
aggressiveness:
type: number
minimum: 0
maximum: 1
example: 0.25
description: Operating point on the ROC curve. Near 0 = human-safe (never hang up on a person); near 1 = fire `machine` fast. Per-call TwiML `<Parameter>` overrides this.
webhook_url:
type: string
nullable: true
format: uri
updated_at:
type: integer
description: Unix ms.
AmdCallList:
type: object
properties:
object:
type: string
example: list
data:
type: array
items:
$ref: '#/components/schemas/AmdCallListItem'
has_more:
type: boolean
next_cursor:
type: string
nullable: true
Problem:
type: object
description: RFC 7807 problem+json returned by the control plane (request-validation and resource errors such as 400/404/409). The stable code is the last path segment of `type`.
required:
- title
- status
properties:
type:
type: string
description: Problem type URI; ends with the stable code.
title:
type: string
status:
type: integer
detail:
type: string
request_id:
type: string
AmdCustomParameters:
type: object
maxProperties: 32
additionalProperties:
type: string
maxLength: 1024
description: Customer correlation parameters, excluding reserved controls and credentials. Names match [A-Za-z0-9][A-Za-z0-9_.-]{0,63}. Each value is bounded to 1024 UTF-8 bytes, and all names plus values to 8192 UTF-8 bytes; character limits alone do not express these byte limits. Nested fields never override AMD result fields.
example:
lead_id: lead-42
campaign_id: campaign-7
Error:
type: object
description: OpenAI-compatible error envelope returned by the gateway data plane (401/402/403/429). Control-plane request/resource errors use Problem (application/problem+json) instead.
required:
- error
properties:
error:
type: object
required:
- message
properties:
message:
type: string
description: Human-readable explanation.
type:
type: string
description: Error category, e.g. rate_limit_error.
code:
$ref: '#/components/schemas/ErrorCode'
param:
type: string
nullable: true
description: Offending parameter when applicable, else null.
securitySchemes:
interpretationUpload:
type: http
scheme: bearer
description: Short-lived write-only upload_capability returned by POST /v1/audio/interpretations/recordings. Never use it for reads.
sessionCookie:
type: apiKey
in: cookie
name: pyai_session
description: Console session cookie. PyAI-admin routes also require the configured platform-admin email allowlist.
apiKey:
type: http
scheme: bearer
description: 'Use `Authorization: Bearer pyai_live_...` (or `pyai_test_...`).'
xApiKey:
type: apiKey
in: header
name: x-api-key
description: Header alias for bearer auth on HTTP endpoints. WebSocket auth uses the subprotocol pair `pyai.v1, pyai-key.<API_KEY>`.
x-pyai-agent-notes:
guide: https://pyai.com/agents/speech-calling.md
omni_frames: https://api.pyai.com/omni-frames.json
discovery: Inspect live operation schemas; preserve IDs and required Idempotency-Key headers. SDK-first for realtime. Never infer a simulated PSTN call endpoint.