AllToken Python SDK

Official Python SDK with httpx-based OpenAI and Anthropic surfaces.

Installation

pip
$ pip install alltoken

Requires Python 3.10+.

Quick start

One API key gives you both OpenAI-compatible and Anthropic-compatible endpoints:

Python
1import os
2from alltoken import AllToken
3
4client = AllToken(api_key=os.environ["ALLTOKEN_API_KEY"])
5
6# OpenAI-compatible (maps to /v1)
7resp = client.openai.raw.post(
8 "/chat/completions",
9 json={
10 "model": "gpt-4o",
11 "messages": [{"role": "user", "content": "Hello!"}],
12 },
13)
14print(resp.json())
15
16# Anthropic-compatible (maps to /anthropic)
17resp = 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)
25print(resp.json())

Configuration

Python
1AllToken(
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.

FieldBase URL
client.openai.rawhttps://api.alltoken.ai/v1
client.anthropic.rawhttps://api.alltoken.ai/anthropic