Skip to main content

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

Metadata

Release files for alltoken 0.2.35

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alltoken 0.2.35
File Size Uploaded
alltoken-0.2.35.tar.gz 26.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alltoken 0.2.35
File Interpreter ABI Platform
alltoken-0.2.35-py3-none-any.whl Python 3 none any Details

Total release size: 55.4 kB

Release files / alltoken-0.2.35.tar.gz

Download URL alltoken-0.2.35.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cd50aa4952eace8205a1934750d7d669e3e147a6e99d6ca5b12fcac2c69e271d
BLAKE2b-256 checksum
How to use checksums
2856e79646e8e8e34ff58c8a923069831f9781d62d338f684f0b5e6de9268e9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / alltoken-0.2.35-py3-none-any.whl

Download URL alltoken-0.2.35-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5de380bbfdbf2e0cbb5519b07e81a3492ea9c50c50bcdf966cd370e02d93464e
BLAKE2b-256 checksum
How to use checksums
a6834e702f87286d6c93aeaaa2f1bc758216c0957a5dd0bbe839ce34ace74531
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

0.2.36

2 release files

This release

0.2.35 This release

2 release files

0.2.34

2 release files

0.2.33

2 release files

0.2.32

2 release files

0.2.30

2 release files

0.2.29

2 release files

0.2.28

2 release files

0.2.27

2 release files

0.2.26

2 release files

0.2.25

2 release files

0.2.24

2 release files

0.2.23

2 release files

0.2.22

2 release files

0.2.21

2 release files

0.2.20

2 release files

0.2.19

2 release files

0.2.18

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page