AllToken Python SDK
Official Python SDK with httpx-based OpenAI and Anthropic surfaces.
Installation
pip
$ pip install alltokenRequires Python 3.10+.
Quick start
One API key gives you both OpenAI-compatible and Anthropic-compatible endpoints:
Python
| 1 | import os |
| 2 | from alltoken import AllToken |
| 3 | |
| 4 | client = AllToken(api_key=os.environ["ALLTOKEN_API_KEY"]) |
| 5 | |
| 6 | # OpenAI-compatible (maps to /v1) |
| 7 | resp = client.openai.raw.post( |
| 8 | "/chat/completions", |
| 9 | json={ |
| 10 | "model": "gpt-4o", |
| 11 | "messages": [{"role": "user", "content": "Hello!"}], |
| 12 | }, |
| 13 | ) |
| 14 | print(resp.json()) |
| 15 | |
| 16 | # Anthropic-compatible (maps to /anthropic) |
| 17 | resp = client.anthropic.raw.post( |
| 18 | "/messages", |
| 19 | json={ |
| 20 | "model": "claude-sonnet-4", |
| 21 | "max_tokens": 1024, |
| 22 | "messages": [{"role": "user", "content": "Hello!"}], |
| 23 | }, |
| 24 | ) |
| 25 | print(resp.json()) |
Configuration
Python
| 1 | AllToken( |
| 2 | api_key="...", # required |
| 3 | base_url="https://api.alltoken.ai", # optional |
| 4 | default_headers={"X-My-Tag": "a"}, # optional |
| 5 | ) |
API surface
.raw is a pre-configured httpx.Client. Base URL and auth are set; call .get() / .post() / .stream() directly. Pydantic v2 models are generated from the OpenAPI specs.
| Field | Base URL |
|---|---|
client.openai.raw | https://api.alltoken.ai/v1 |
client.anthropic.raw | https://api.alltoken.ai/anthropic |