Skip to main content

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/omni surface (the default for product="omni"); product="flow" uses /v1/realtime. The older /v2/omni/chat URL 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

pyai_sdk-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyai_sdk-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for pyai_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 59a7e07bb9ac282170f99a487eeae0bdacb727660479c54dde16f98e335ff7be
MD5 d3349bb9a6a0dac3e350b0e98a6b0e6b
BLAKE2b-256 0db9969d2aae504ab25a580cdcf38a6d9c73be5c36c0c60f4b87059eadb3ee20

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyai_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7c3cf9f1efb1553f3e95fc4d65a925192dc6e45659a748629f5422fa3973d0f
MD5 b17f6eed8268f7b94b20b2712cb9e988
BLAKE2b-256 702fbafc2f5825ea4c2ef85fcc37a9dec85c6dabafa51dd3c8753048f0b603ee

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page