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

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.34.tar.gz (25.7 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.34-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: alltoken-0.2.34.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for alltoken-0.2.34.tar.gz
Algorithm Hash digest
SHA256 ab71cce65601d174933da67c6452e04d4dd76d172642c59e65782bd0529a2511
MD5 e77933978ede3456fd0d6d9f4e90d310
BLAKE2b-256 d79407a050ba957bcfbeddea3d8471c1fa9b66b6cb3dbd58e3b77c0c56a5191c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: alltoken-0.2.34-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.14

File hashes

Hashes for alltoken-0.2.34-py3-none-any.whl
Algorithm Hash digest
SHA256 39f1060ed021bfc5a7574df3f8542534fedb61441e4d255e668f6a7763f56045
MD5 b3d94bc2d59cf6700ec884eb8746153a
BLAKE2b-256 cdd1259a6239b0323f53801e705d6abe2e98b268dedc071993292db0c2a9f653

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.36

2 files

0.2.35

2 files

This release

0.2.34 This release

2 files

0.2.33

2 files

0.2.32

2 files

0.2.31

2 files

0.2.30

2 files

0.2.29

2 files

0.2.28

2 files

0.2.27

2 files

0.2.26

2 files

0.2.25

2 files

0.2.24

2 files

0.2.23

2 files

0.2.22

2 files

0.2.21

2 files

0.2.20

2 files

0.2.19

2 files

0.2.18

2 files

0.2.17

2 files

0.2.16

2 files

0.2.15

2 files

0.2.14

2 files

0.2.13

2 files

0.2.12

2 files

0.2.11

2 files

0.2.10

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 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