Skip to main content

Official AI Stats Gateway SDK for Python.

Project description

AI Stats Python SDK

Official Python SDK for AI Stats Gateway.

Installation

pip install ai-stats-py-sdk

Requires Python 3.10+.

Quick start

from ai_stats import AIStats

client = AIStats()  # Uses AI_STATS_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()

for chunk in client.stream_text(
    {
        "model": "google/gemma-3-27b:free",
        "messages": [{"role": "user", "content": "Stream hi"}],
    }
):
    print(chunk, end="", flush=True)

Common methods

  • client.responses.create(...)
  • client.chat.completions.create(...)
  • client.models.list(...)
  • client.list_organisations(...) for paginated /organisations discovery
  • client.list_pricing_models(...) for /pricing/models catalogue pricing discovery
  • client.calculate_pricing(...) for /pricing/calculate usage estimation
  • client.list_providers(...), client.get_credits(...), client.get_activity(...), and client.get_analytics(...) for provider discovery and management-key usage surfaces
  • client.list_api_keys(...) for management-key /keys discovery
  • client.create_api_key(...), client.update_api_key(key_id, ...), and client.delete_api_key(key_id) for management-key API-key lifecycle changes
  • client.get_api_key(key_id) for management-key /keys/{id} lookup
  • client.list_workspaces(...), client.get_workspace(workspace_id), client.create_workspace(...), client.update_workspace(workspace_id, ...), and client.delete_workspace(workspace_id) for management-key workspace lifecycle management
  • client.get_current_api_key()
  • client.get_health()
  • client.models.get_deprecation_info(model_id)
  • client.models.validate(model_id)

Model discovery supports the public /gateway/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.

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 :free in 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

  • AI_STATS_API_KEY (required unless passed in code)
  • AI_STATS_BASE_URL (optional, defaults to https://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:chat
    • pnpm --filter @ai-stats/py-sdk run smoke:responses

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-2.0.4.tar.gz (37.5 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-2.0.4-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ai_stats_py_sdk-2.0.4.tar.gz
Algorithm Hash digest
SHA256 a25df2fb33784121a2c7fa4d7ca410ed772d6c344a8e1e687e19bfa418630533
MD5 c8d73e7d6657835410c0483eb55b6528
BLAKE2b-256 bda0b8512ebc6d35ab0550aae9a2e4a894ffc1af793c3e008efe489f7bc7ff60

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ai_stats_py_sdk-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3af7075cb4e4155b9e01fd5f5389ba8caf349b9da4dc4f4667bcc200c792e357
MD5 8409b54b6b963e95e8f64d3cf63e4d48
BLAKE2b-256 abb40202b6ee7f68e798f154e18d31b8b7cade2443ddf2a09d5a29de3a468e83

See more details on using hashes here.

Provenance

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