Python

Use Python with AllToken via the OpenAI SDK or raw HTTP.

Using the OpenAI SDK

The recommended approach. See OpenAI SDK — Python for the full example.

Using the requests library

Use requests for lightweight usage without the OpenAI SDK:

Python
1import requests
2import os
3
4response = requests.post(
5 "https://api.alltoken.ai/v1/chat/completions",
6 headers={
7 "Authorization": f"Bearer {os.environ['ALLTOKEN_API_KEY']}",
8 "Content-Type": "application/json",
9 },
10 json={
11 "model": "deepseek-chat",
12 "messages": [{"role": "user", "content": "Hello!"}],
13 },
14)
15
16data = response.json()
17print(data["choices"][0]["message"]["content"])