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 voice-AI platform for speech-to-text, text-to-speech, realtime voice agents, and automated call compliance. Zero third-party dependencies (standard library only); Python 3.9+.
PyAI products
- Hear — Speech-to-text tuned for telephony (8 kHz), with streaming partials and a half-price async batch tier; OpenAI-compatible.
POST /v1/audio/transcriptions - Speak — Low-latency streaming text-to-speech (~32–98 ms to first byte) with 36 stock voices and free instant voice cloning.
POST /v1/audio/speech - Omni (flagship) — End-to-end realtime voice agents over a single WebSocket: listens, thinks, and speaks — grounded in your knowledge bases and tools, with natural turn-taking and barge-in.
wss://api.pyai.com/v1/omni - Trace (flagship) — Automated compliance & QA on every call: scores each call against rule packs (TCPA, HIPAA, PII, brand-voice), with findings that cite the rule, auto-redaction, and a tamper-evident audit hash.
GET /v1/trace/interactions - Cue — Turn detection + retrieved knowledge-base context for bring-your-own-LLM/voice pipelines, billed as one per-minute meter.
wss://api.pyai.com/v1/audio/transcriptions/stream - Telephony — Managed US phone numbers routed straight to your Omni agents, no separate carrier contract.
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.1.tar.gz.
File metadata
- Download URL: pyai_sdk-0.1.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b42b67d31f994606a20af7fee4aee776e8e70876c6567c5088c7d4b6a6a9ca80
|
|
| MD5 |
ad313bc0b1c852cf83ff1fea0130704a
|
|
| BLAKE2b-256 |
53a9d61c2779f59a34aa2e2176a24b71f948a7aa0ca2fe6a6c0f0fe730db0cdf
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.1.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.1.tar.gz -
Subject digest:
b42b67d31f994606a20af7fee4aee776e8e70876c6567c5088c7d4b6a6a9ca80 - Sigstore transparency entry: 1835591219
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@00281cf417dc8823ac38b6cc91ae5b1e5f7dbce9 -
Branch / Tag:
refs/tags/sdk-py-v0.1.1 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@00281cf417dc8823ac38b6cc91ae5b1e5f7dbce9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyai_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyai_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.3 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 |
76ebeb138fff8b9613c55e6d43e74bea5dfcf1118cac99a46d8621b91959e460
|
|
| MD5 |
6bf0d44f98ed0b9e2ef540bc1624dc8a
|
|
| BLAKE2b-256 |
7271a15d9299ca7b1c32014566ad90e0163cd3d822c39b9454e63923b5a15f92
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.1-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.1-py3-none-any.whl -
Subject digest:
76ebeb138fff8b9613c55e6d43e74bea5dfcf1118cac99a46d8621b91959e460 - Sigstore transparency entry: 1835591371
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@00281cf417dc8823ac38b6cc91ae5b1e5f7dbce9 -
Branch / Tag:
refs/tags/sdk-py-v0.1.1 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@00281cf417dc8823ac38b6cc91ae5b1e5f7dbce9 -
Trigger Event:
push
-
Statement type: