Official Python SDK for the PyAI API (Hear, Speak, Cue, Omni).
Project description
pyai-sdk (Python SDK)
Official Python SDK for the PyAI API — Hear (speech-to-text), Speak (text-to-speech + cloning), Cue (turn detection + KB context), and Omni (realtime voice agents). Zero third-party dependencies (standard library only); Python 3.9+.
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.0.tar.gz.
File metadata
- Download URL: pyai_sdk-0.1.0.tar.gz
- Upload date:
- Size: 5.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 |
59a7e07bb9ac282170f99a487eeae0bdacb727660479c54dde16f98e335ff7be
|
|
| MD5 |
d3349bb9a6a0dac3e350b0e98a6b0e6b
|
|
| BLAKE2b-256 |
0db9969d2aae504ab25a580cdcf38a6d9c73be5c36c0c60f4b87059eadb3ee20
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.0.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.0.tar.gz -
Subject digest:
59a7e07bb9ac282170f99a487eeae0bdacb727660479c54dde16f98e335ff7be - Sigstore transparency entry: 1834475230
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@82821193b954d07eefa42d69ee72d02e02acd6d8 -
Branch / Tag:
refs/tags/sdk-py-v0.1.0 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@82821193b954d07eefa42d69ee72d02e02acd6d8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyai_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyai_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 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 |
c7c3cf9f1efb1553f3e95fc4d65a925192dc6e45659a748629f5422fa3973d0f
|
|
| MD5 |
b17f6eed8268f7b94b20b2712cb9e988
|
|
| BLAKE2b-256 |
702fbafc2f5825ea4c2ef85fcc37a9dec85c6dabafa51dd3c8753048f0b603ee
|
Provenance
The following attestation bundles were made for pyai_sdk-0.1.0-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.0-py3-none-any.whl -
Subject digest:
c7c3cf9f1efb1553f3e95fc4d65a925192dc6e45659a748629f5422fa3973d0f - Sigstore transparency entry: 1834475383
- Sigstore integration time:
-
Permalink:
atomsai/pyai-platform-backend@82821193b954d07eefa42d69ee72d02e02acd6d8 -
Branch / Tag:
refs/tags/sdk-py-v0.1.0 - Owner: https://github.com/atomsai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-pypi.yml@82821193b954d07eefa42d69ee72d02e02acd6d8 -
Trigger Event:
push
-
Statement type: