AllToken Python SDK
Offizielles Python SDK mit httpx-basierten OpenAI- und Anthropic-Oberflächen.
Installation
pip
$ pip install alltokenPython 3.10+ erforderlich.
Schnellstart
Ein API-Schlüssel gibt Ihnen sowohl OpenAI-kompatible als auch Anthropic-kompatible Endpunkte:
Python
| 1 | import os |
| 2 | from alltoken import AllToken |
| 3 | |
| 4 | client = AllToken(api_key=os.environ["ALLTOKEN_API_KEY"]) |
| 5 | |
| 6 | # OpenAI-kompatibel (mappt auf /v1) |
| 7 | resp = client.openai.raw.post( |
| 8 | "/chat/completions", |
| 9 | json={ |
| 10 | "model": "gpt-4o", |
| 11 | "messages": [{"role": "user", "content": "Hallo!"}], |
| 12 | }, |
| 13 | ) |
| 14 | print(resp.json()) |
| 15 | |
| 16 | # Anthropic-kompatibel (mappt auf /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": "Hallo!"}], |
| 23 | }, |
| 24 | ) |
| 25 | print(resp.json()) |
Konfiguration
Python
| 1 | AllToken( |
| 2 | api_key="...", # erforderlich |
| 3 | base_url="https://api.alltoken.ai", # optional |
| 4 | default_headers={"X-My-Tag": "a"}, # optional |
| 5 | ) |
API-Oberfläche
.raw ist ein vorkonfigurierter httpx.Client. Basis-URL und Authentifizierung sind gesetzt; rufen Sie .get() / .post() / .stream() direkt auf. Pydantic-v2-Modelle werden aus den OpenAPI-Spezifikationen generiert.
| Feld | Basis-URL |
|---|---|
client.openai.raw | https://api.alltoken.ai/v1 |
client.anthropic.raw | https://api.alltoken.ai/anthropic |