Skip to main content

Official AI Stats Gateway SDK for Python.

Project description

AI Stats Python SDK

Asynchronous-first Python client for the AI Stats Gateway API. Built from the canonical OpenAPI spec and wrapped with helper methods that mirror the new generate/stream interface.

Installation

pip install ai-stats-py-sdk

Requires Python 3.9+.

Quick start

from ai_stats import AIStats

# Uses AI_STATS_API_KEY from environment by default.
client = AIStats()
response = client.generate_response(
    {"model": "openai/gpt-5.4", "input": "Write a one-sentence bedtime story about a unicorn."}
)
print(response.get("output_text"))

Streaming

client = AIStats(api_key="sk_test_xxx")
for chunk in client.stream_text(
    {"model": "openai/gpt-5.4", "messages": [{"role": "user", "content": "Stream hi"}]}
):
    print(chunk, end="", flush=True)

Models and other helpers

client = AIStats()
models = client.get_models()
print(models)

client.generate_image({"model": "image-alpha", "prompt": "A purple nebula"})
client.generate_embedding({"model": "google/gemini-embedding-001", "input": "hello"})
client.generate_moderation({"model": "openai/omni-moderation", "input": "safe?"})
client.generate_video({"model": "video-alpha", "prompt": "Ocean waves"})
client.generate_speech({"model": "tts-alpha", "input": "Hello!"})
client.generate_transcription({"model": "whisper-alpha", "file": "<base64 data>"})

Model ID future-proofing

Model fields are typed as KnownModelId | str, so new gateway model IDs are still accepted before a package update.

Deprecation lifecycle warnings

The SDK checks /v1/data/models and warns once per process for deprecated/retired models.

from ai_stats import AIStats

client = AIStats(
    enable_deprecation_warnings=True,  # default
    warnings_as_errors=False,          # set True to raise instead of warn
    logger=lambda level, message, meta: print(level, message, meta),
)

info = client.models.get_deprecation_info("openai/old-model")
validation = client.models.validate("openai/old-model")

Features

  • Async and sync interfaces (AIStats + AIStatsSync)
  • Typed models for requests/responses and errors
  • Streaming helper that yields decoded SSE frames
  • Customisable timeouts, headers, and base URL
  • Built-in devtools telemetry capture (no separate core package required)

Devtools

The Python SDK bundles telemetry capture directly. Enable it by passing create_ai_stats_devtools() to the client:

from ai_stats import AIStats, create_ai_stats_devtools

client = AIStats(
    devtools=create_ai_stats_devtools(
        directory=".ai-stats-devtools",
        capture_headers=False,
    ),
)

Captured data is written to .ai-stats-devtools/generations.jsonl and can be viewed with:

npx @ai-stats/devtools-viewer

Note: The client reads AI_STATS_API_KEY by default. You can still pass api_key explicitly.

Refer to the docstrings for each method to see accepted parameters and return values—everything is annotated for IntelliSense.

Versions are driven by Changesets and published via CI (see .github/workflows/ci.yml). You should not need to tag or upload artifacts manually.

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

ai_stats_py_sdk-1.1.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

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

ai_stats_py_sdk-1.1.0-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_stats_py_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: ai_stats_py_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ai_stats_py_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 07e6a001d630f18dc205aaeaf304175326fa9c7c381110bbdb1accd5a14fc2a3
MD5 29ed9746ca0fbb2eb59ace343c1c558f
BLAKE2b-256 0917f35f25128fbb593a78fa4143bc78f877c40e4e59cb81a1107a3b7158efbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_stats_py_sdk-1.1.0.tar.gz:

Publisher: ci.yml on AI-Stats/AI-Stats

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

File details

Details for the file ai_stats_py_sdk-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_stats_py_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86dfc9cabecaf94170d8e714e6f5b9f4d5beee93bd42fd8086a9ac7117641b99
MD5 b252359d4c1994126ad298aeb5c11ed0
BLAKE2b-256 a3c9ea80a9a4dc8fa84c19860d77fbe28a91ee4b1ef6fabce157d425ef98086b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_stats_py_sdk-1.1.0-py3-none-any.whl:

Publisher: ci.yml on AI-Stats/AI-Stats

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