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

import asyncio
from ai_stats import AIStats

async def main():
    client = AIStats(api_key="sk_test_xxx")
    async with client:
        completion = await client.generate_text(
            {"model": "openai/gpt-5-nano", "messages": [{"role": "user", "content": "Say hi"}]}
        )
        print(completion.choices[0].message.content)

asyncio.run(main())

Streaming

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

Models and other helpers

async with AIStats(api_key="...") as client:
    models = await client.get_models()
    print([m.id for m in models.data])

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

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(
    api_key="sk_test_xxx",
    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: Provide the API key explicitly via the api_key parameter or by adding an Authorization header through headers. The SDK does not read environment variables.

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.0.1.tar.gz (17.8 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.0.1-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ai_stats_py_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 17.8 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.0.1.tar.gz
Algorithm Hash digest
SHA256 2200d3be5801c2c86491f09a90cd7e5d142871175cc7f40f1f9cac48b6833400
MD5 803b1be4577c0476c20844e58849b3b0
BLAKE2b-256 f9851da652adc3e1daec6e63f7887b00465c7505d0b54b1c5023e770c3515cf9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ai_stats_py_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af0695da4a8e070912334c368e9f9ccf19fc25bf6eefc267328d072bcbc64c1d
MD5 81af0f22d7338bdd53f0883d8a4c2113
BLAKE2b-256 06eebb8ab8833b21b0b494bd1fc1874e366dbeff4f52216e9db1e14a4fd08371

See more details on using hashes here.

Provenance

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