Skip to main content

Official Python SDK for AllToken — one API for OpenAI, Anthropic, and 100+ models.

Project description

alltoken

Official Python SDK for AllToken — one API for OpenAI, Anthropic, and 100+ models.

pip install alltoken

Requires Python 3.10+.

Quick start

from alltoken import AllToken

client = AllToken(api_key="...")  # or os.environ["ALLTOKEN_API_KEY"]

# OpenAI-compatible surface (maps to /v1)
resp = client.openai.raw.post(
    "/chat/completions",
    json={
        "model": "gpt-4o",
        "messages": [{"role": "user", "content": "Hello!"}],
    },
)
print(resp.json())

# Anthropic-compatible surface (maps to /anthropic)
resp = client.anthropic.raw.post(
    "/messages",
    json={
        "model": "claude-sonnet-4",
        "max_tokens": 1024,
        "messages": [{"role": "user", "content": "Hello!"}],
    },
)
print(resp.json())

The same API key works for both surfaces. Model catalog: alltoken.ai/models.

Configuration

AllToken(
    api_key="...",                      # required
    base_url="https://api.alltoken.ai", # optional, defaults to production
    default_headers={"X-My-Tag": "a"},  # optional, merged into every request
)

API surface

Field Spec Base URL
client.openai.raw chat.yml (OpenAI-compatible) https://api.alltoken.ai/v1
client.anthropic.raw anthropic.yml https://api.alltoken.ai/anthropic

.raw is a pre-configured httpx.Client — base URL + auth are set, call .get() / .post() / .stream() directly. Pydantic models for request/response bodies are generated from the OpenAPI specs into alltoken.generated.chat and alltoken.generated.anthropic.

Status

v0.1.0 — Scaffold. Pydantic models are generated from the spec, the wrapper surface is minimal. Expect breaking changes in 0.x. Ergonomic helpers (client.chat.completions.create(...), async streaming iterators, retries, etc.) are coming in 0.2.x.

Contributing / Local development

# Clone megaopenrouter as a sibling (for the OpenAPI specs)
git clone git@gitlab.53site.com:ai-innovation-lab/megaopenrouter.git ../megaopenrouter

# Install with dev deps
pip install -e ".[dev]"

# Regenerate pydantic models from specs
python scripts/generate.py

# Test + lint
pytest
ruff check
mypy .

Generated models live in src/alltoken/generated/{chat,anthropic}.py — these are committed so users who install from PyPI don't need to run codegen.

License

MIT

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

alltoken-0.2.6.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alltoken-0.2.6-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file alltoken-0.2.6.tar.gz.

File metadata

  • Download URL: alltoken-0.2.6.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for alltoken-0.2.6.tar.gz
Algorithm Hash digest
SHA256 512b98d813ded7d5acf71eff73b4f52d7698d6b09cd55fd955db01ad8ba3cd56
MD5 fa7896a501eb28dbd507f154876247d2
BLAKE2b-256 159bf90d28e8eb4ad16203eb8f69939d8e60a9ffbc7be2aa07c8edb1855ecf3c

See more details on using hashes here.

File details

Details for the file alltoken-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: alltoken-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for alltoken-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 66e9800ccbedc4f6a4923655f6e7fec99fa7f642b707450c89c602fe455afce3
MD5 966823abc5c3c4d3cdbf797b851f5146
BLAKE2b-256 d41476d384889dbb723fd38c272c10fc6c75d7a9ffab8af87d3c98c37dcd07e8

See more details on using hashes here.

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