Official Python SDK for PyAI — speech-to-text (Hear), text-to-speech (Speak), realtime voice agents (Omni), and call compliance (Trace).
Project description
pyai-sdk (Python SDK)
Official Python SDK for PyAI — the all-in-one voice AI platform: lightning-fast speech-to-text, ultra-realistic text-to-speech, end-to-end realtime voice agents, and automatic call compliance. Zero third-party dependencies (standard library only); Python 3.9+.
PyAI products
- Hear — Lightning-fast, telephony-native speech-to-text. Whisper-compatible transcription tuned for real phone-call audio, with live streaming partials so your app reacts mid-sentence, plus async batch transcription for big archives.
POST /v1/audio/transcriptions - Speak — Ultra-realistic text-to-speech that starts speaking in tens of milliseconds. Stream lifelike, expressive voices, choose from 36 studio-quality presets, or clone any voice instantly — for free.
POST /v1/audio/speech - Omni (flagship) — One API for a complete, end-to-end voice AI agent. A single WebSocket where your agent listens, thinks, and speaks — grounded in your knowledge bases and tools, with human-like turn-taking and instant barge-in — no STT, LLM, or TTS to stitch together yourself.
wss://api.pyai.com/v1/omni - Trace (flagship) — The compliance API that keeps your AI agents safe. Trace automatically checks every call for HIPAA, TCPA, and PII risks (plus your own brand-voice rules), flags the exact rule broken, redacts sensitive data, and seals each call with a tamper-evident audit trail — so a risky conversation never slips through.
GET /v1/trace/interactions - Cue — Realtime turn detection + knowledge-grounded context for your own stack. Bring your own LLM and voice; Cue nails the hard part — knowing the instant a speaker finishes and surfacing the right context.
wss://api.pyai.com/v1/audio/transcriptions/stream - Telephony — Instant managed phone numbers for your voice agents. Provision a US number and route live calls straight into an Omni agent — no carrier contracts, no telephony glue.
POST /v1/telephony/numbers
The contract is https://api.pyai.com/openapi.json. This SDK wraps it with
typed errors, automatic retries, and realtime URL helpers.
Install
pip install pyai-sdk
Quickstart
import os
from pyai import PyAI, new_idempotency_key
pyai = PyAI(api_key=os.environ["PYAI_API_KEY"])
# Text-to-speech
audio = pyai.audio.speech(input="Hello from PyAI.", voice="stock_sarah_style2")
open("hello.wav", "wb").write(audio)
# Voices
voices = pyai.voices.list(gender="female")
# Async transcription (safe retry with an idempotency key)
job = pyai.transcription_jobs.create(
audio_url="https://example.com/call.wav",
diarize=True,
idempotency_key=new_idempotency_key(),
)
done = pyai.transcription_jobs.get(job["job_id"])
Realtime (Omni)
Keys travel as a WebSocket subprotocol. Use the helpers with your preferred WS
library (e.g. websockets):
url = pyai.realtime_url(product="omni", agent_id="agent_123")
subprotocol = pyai.realtime_subprotocol()
import asyncio, websockets
async def main():
async with websockets.connect(url, subprotocols=[subprotocol]) as ws:
async for frame in ws:
print(frame)
asyncio.run(main())
Omni uses the native
wss://api.pyai.com/v1/omnisurface (the default forproduct="omni");product="flow"uses/v1/realtime. The older/v2/omni/chatURL is deprecated but still works.
Errors
Failures raise PyAIError with a stable code (branch on it, not the message):
from pyai import PyAIError
try:
pyai.audio.speech(input="hi")
except PyAIError as err:
if err.code == "credit_exhausted":
... # out of prepaid credit — add credit or use a sandbox key
Common codes: unauthorized, forbidden, credit_exhausted,
rate_limit_exceeded, concurrency_limit_exceeded, idempotency_conflict.
429/5xx are retried automatically (honoring Retry-After); tune with
PyAI(api_key, max_retries=...).
Develop
python -m unittest discover -s tests -v # no network; transport injected
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyai_sdk-0.1.2.tar.gz.
File metadata
- Download URL: pyai_sdk-0.1.2.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
459f37e1661f9071a6b9041c95d264637dcd86c3f22b94ec07e0dcc70bd16ebc
|
|
| MD5 |
13823d393d8179dafde43fee6c0beee2
|
|
| BLAKE2b-256 |
fccd82495083317e580d1b9eab9719ac1f13d2a499b79281b814c4d1cf9c5ecd
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.2.tar.gz:
Publisher:
publish-sdk-pypi.yml on atomsai/pyai-platform-backend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyai_sdk-0.1.2.tar.gz -
Subject digest:
459f37e1661f9071a6b9041c95d264637dcd86c3f22b94ec07e0dcc70bd16ebc - Sigstore transparency entry: 1837167329
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@ab85ab75d56b8c6430978af12cb7d5db3446517d -
Branch / Tag:
refs/tags/sdk-py-v0.1.2 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@ab85ab75d56b8c6430978af12cb7d5db3446517d -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyai_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyai_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7c4432f237aa65020dc22dc26a0fb27edc0f6ac90ed6eaa289f9d72628488f
|
|
| MD5 |
40215233607f782610c53a04a928207a
|
|
| BLAKE2b-256 |
57258bb9cf62598cf9f201f65dbb479ef7cd615b8638a91594e4facd379fcdde
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.2-py3-none-any.whl:
Publisher:
publish-sdk-pypi.yml on atomsai/pyai-platform-backend
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyai_sdk-0.1.2-py3-none-any.whl -
Subject digest:
cc7c4432f237aa65020dc22dc26a0fb27edc0f6ac90ed6eaa289f9d72628488f - Sigstore transparency entry: 1837167440
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@ab85ab75d56b8c6430978af12cb7d5db3446517d -
Branch / Tag:
refs/tags/sdk-py-v0.1.2 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@ab85ab75d56b8c6430978af12cb7d5db3446517d -
Trigger Event:
push
-
Statement type: