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.1.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.1-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_stats_py_sdk-1.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f1010b4230999f6bebea4f41ac35f32a2dfd383170ec8babb4836694593502bb
MD5 8c5702672dcea8f99791612f46ad4809
BLAKE2b-256 b8ff0c1b0805e9f524bc55c248559bd107f18c83726397570d36d688b2f04aea

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_stats_py_sdk-1.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_stats_py_sdk-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68787862326727b75616141d0c038b72f9e08160ec3698600737ec82cd177e3c
MD5 0c5fca24b98c12cc0e6125b8f2d3c7ff
BLAKE2b-256 ae360bf0fe805208cf236e8de2cad879563b1d50c3c2a32c45dc71979e6c515e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ai_stats_py_sdk-1.1.1-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