Phaseo Python SDK
Official Python SDK for Phaseo Gateway.
Deprecated package name:
ai-stats-py-sdkremains available for existing users, but new projects should installphaseoinstead. The product is now Phaseo and future package migration work will move examples and release automation to the new package name.
Installation
pip install phaseo
Requires Python 3.10+.
Quick start
from ai_stats import AIStats
client = AIStats() # Uses PHASEO_API_KEY from environment
response = client.responses.create(
{
"model": "google/gemma-3-27b:free",
"input": "Reply with: Python SDK works",
}
)
print(response.get("output_text"))
Streaming example
from ai_stats import AIStats
client = AIStats()
response = ""
for chunk in client.stream_chat(
{
"model": "google/gemma-3-27b:free",
"messages": [{"role": "user", "content": "Stream hi"}],
}
):
if chunk.get("text"):
response += chunk["text"]
print(chunk["text"], end="", flush=True)
if chunk.get("reasoning_tokens"):
print("\nReasoning tokens:", chunk["reasoning_tokens"])
Common methods
client.responses.create(...)client.chat.completions.create(...)client.messages.create(...)client.stream_chat(...),client.stream_responses(...), andclient.stream_message(...)for parsed streaming chunks withtext,usage, andreasoning_tokensclient.models.list(...)client.list_organisations(...)for paginated/organisationsdiscoveryclient.list_pricing_models(...)for/pricing/modelscatalogue pricing discoveryclient.calculate_pricing(...)for/pricing/calculateusage estimationclient.list_providers(...),client.get_credits(...),client.get_activity(...), andclient.get_analytics(...)for provider discovery and management-key usage surfacesclient.list_api_keys(...)for management-key/keysdiscoveryclient.create_api_key(...),client.update_api_key(key_id, ...), andclient.delete_api_key(key_id)for management-key API-key lifecycle changesclient.get_api_key(key_id)for management-key/keys/{id}lookupclient.list_workspaces(...),client.get_workspace(workspace_id),client.create_workspace(...),client.update_workspace(workspace_id, ...), andclient.delete_workspace(workspace_id)for management-key workspace lifecycle managementclient.get_current_api_key()client.get_health()client.models.get_deprecation_info(model_id)client.models.validate(model_id)client.batches.list_models()for batch-capable models and supported batch parameter metadata
Model discovery supports the public /models filters, including provider, provider_status, provider_routing_status, model_routing_status, capability_status, provider_availability_status, provider_availability_reason, status, organisation, endpoints, input_types, output_types, params, availability, limit, and offset.
Use provider_availability_reason with availability="all" when you want rollout-state entries such as preview_only, provider_not_ready, gated, access_limited, region_limited, project_limited, paused, or soft_blocked. Use capability_status with availability="all" when you want non-routable endpoint mappings such as coming_soon or internal_testing.
models = client.get_models({
"provider": ["anthropic"],
"provider_status": ["beta", "not_ready"],
"provider_availability_reason": ["preview_only", "provider_not_ready"],
"capability_status": ["coming_soon", "internal_testing"],
"availability": "all",
})
Async job websocket helpers
Batch and video operations can expose a websocket lifecycle stream at /v1/async/{kind}/{id}/ws.
Create responses include the job id, polling URL, optional websocket URL, and sanitized webhook delivery state.
import os
batch = client.batches.create({
"endpoint": "/v1/responses",
"input_file_id": "file_123",
"completion_window": "24h",
"webhook": {
"url": "https://example.com/ai-stats/webhooks",
"secret": os.environ["PHASEO_WEBHOOK_SECRET"],
"events": ["batch.progress", "batch.completed", "batch.failed"],
},
})
video = client.videos.create({
"model": "google/veo-3",
"prompt": "orbital reveal",
"webhook": {
"url": "https://example.com/ai-stats/webhooks",
"secret": os.environ["PHASEO_WEBHOOK_SECRET"],
"events": ["video.progress", "video.completed", "video.failed"],
},
})
batch_socket_url = client.batches.websocket_url("batch_123", interval_ms=1500)
video_socket_url = client.videos.websocket_url(
"video_123",
close_on_terminal=True,
)
generic_socket_url = client.get_async_job_websocket_url("video", "video_123")
Free and paid models
- Models with
:freein the model ID can be called with zero deposited credits. - Paid models require available wallet balance.
Model lifecycle warnings
from ai_stats import AIStats
client = AIStats(
enable_deprecation_warnings=True,
warnings_as_errors=False,
logger=lambda level, message, meta: print(level, message, meta),
)
Environment variables
PHASEO_API_KEY(required unless passed in code)PHASEO_BASE_URL(optional, defaults tohttps://api.phaseo.app/v1)
Devtools
from ai_stats import AIStats, create_ai_stats_devtools
client = AIStats(
devtools=create_ai_stats_devtools(
directory=".ai-stats-devtools",
capture_headers=False,
)
)
Regeneration and local checks
- Regenerate generated client:
pnpm openapi:gen:py - Run tests:
pnpm test:sdk-py - Smoke checks:
pnpm --filter @ai-stats/py-sdk run smoke:chatpnpm --filter @ai-stats/py-sdk run smoke:responses
Metadata
Release files for ai-stats-py-sdk 2.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_stats_py_sdk-2.0.5.tar.gz | 44.5 kB | Without provenance | Details for ai_stats_py_sdk-2.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_stats_py_sdk-2.0.5-py3-none-any.whl | Python 3 | none | any | Details for ai_stats_py_sdk-2.0.5-py3-none-any.whl |
Total release size: 91.3 kB
Release files / ai_stats_py_sdk-2.0.5.tar.gz
| Download URL | ai_stats_py_sdk-2.0.5.tar.gz |
|---|---|
| Size | 44.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2e29745d10af276b9d63595e2678a4565e06f7d9305b5095abec3e0eb16db19
|
|
BLAKE2b-256 checksum How to use checksums |
c63da966c05a8065b5e35cfa491c6342761fd2c76430e1f1d083250944a63f39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / ai_stats_py_sdk-2.0.5-py3-none-any.whl
| Download URL | ai_stats_py_sdk-2.0.5-py3-none-any.whl |
|---|---|
| Size | 46.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf103f0ce3c5f9f9378a4583f363a4c020b45a1120700366c40e65aeef8bca27
|
|
BLAKE2b-256 checksum How to use checksums |
790fb55f4622cfc1ceaabf59a0371ecf9f15a0854f6d020273768c32c5da8106
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for ai-stats-py-sdk 2.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.