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
Metadata
Release files for alltoken 0.2.36
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| alltoken-0.2.36.tar.gz | 26.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| alltoken-0.2.36-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.4 kB
Release files / alltoken-0.2.36.tar.gz
| Download URL | alltoken-0.2.36.tar.gz |
|---|---|
| Size | 26.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3c9db58332d5208c724e02390a0ea15cde2b7b3e291a7df14e95afe9bff4cf3e
|
|
BLAKE2b-256 checksum How to use checksums |
b92ab55c40a768d1e006929eca05347025a71bb8d6dd901608abd71df3451132
|
| 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.36-py3-none-any.whl
| Download URL | alltoken-0.2.36-py3-none-any.whl |
|---|---|
| Size | 29.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bbff78aff0d45236283343ab9d75caff2d251911bccad85e89752ce308ffe2e7
|
|
BLAKE2b-256 checksum How to use checksums |
59f4275ed2ed5c416618902b3cbfda94ac60ebed7682aae903c0eb1029741569
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.14
|