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
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07e6a001d630f18dc205aaeaf304175326fa9c7c381110bbdb1accd5a14fc2a3
|
|
| MD5 |
29ed9746ca0fbb2eb59ace343c1c558f
|
|
| BLAKE2b-256 |
0917f35f25128fbb593a78fa4143bc78f877c40e4e59cb81a1107a3b7158efbe
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_stats_py_sdk-1.1.0.tar.gz -
Subject digest:
07e6a001d630f18dc205aaeaf304175326fa9c7c381110bbdb1accd5a14fc2a3 - Sigstore transparency entry: 1162776058
- Sigstore integration time:
-
Permalink:
AI-Stats/AI-Stats@a6d45241c909266e16c5b36821072e9a754c9f70 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AI-Stats
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a6d45241c909266e16c5b36821072e9a754c9f70 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ai_stats_py_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_stats_py_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86dfc9cabecaf94170d8e714e6f5b9f4d5beee93bd42fd8086a9ac7117641b99
|
|
| MD5 |
b252359d4c1994126ad298aeb5c11ed0
|
|
| BLAKE2b-256 |
a3c9ea80a9a4dc8fa84c19860d77fbe28a91ee4b1ef6fabce157d425ef98086b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_stats_py_sdk-1.1.0-py3-none-any.whl -
Subject digest:
86dfc9cabecaf94170d8e714e6f5b9f4d5beee93bd42fd8086a9ac7117641b99 - Sigstore transparency entry: 1162776113
- Sigstore integration time:
-
Permalink:
AI-Stats/AI-Stats@a6d45241c909266e16c5b36821072e9a754c9f70 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/AI-Stats
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@a6d45241c909266e16c5b36821072e9a754c9f70 -
Trigger Event:
push
-
Statement type: