Core Guides
Migration Guides
Move existing OpenAI, Anthropic, Gemini, and media clients to TokenLab
Keep the request format your application already uses. OpenAI-compatible clients, Anthropic Messages, Gemini REST, and media endpoints each have a matching TokenLab API address.
API mapping
| Existing API | TokenLab base URL | Endpoint | Keep in mind |
|---|---|---|---|
| OpenAI Chat Completions | https://api.tokenlab.sh/v1 | /chat/completions | Smallest change for OpenAI-compatible chat and function calling |
| OpenAI Responses | https://api.tokenlab.sh/v1 | /responses | Use when your app depends on Responses-specific input, tools, or output handling |
| Anthropic SDK | https://api.tokenlab.sh | /v1/messages | Do not append /v1 to the SDK base URL |
| Gemini REST | https://api.tokenlab.sh | /v1beta/models/:model:generateContent | Keep Gemini-native fields on the Gemini route |
| Media generation | https://api.tokenlab.sh/v1 | /images, /videos, /music, /3d | Discover models with recommended_for and expect async polling where documented |
| Management and billing | https://api.tokenlab.sh/v1 | /management/... | Server-side calls use a management token, not a model API key |
Quick Migration Recipes
OpenAI to TokenLab
Change the SDK base_url / baseURL to https://api.tokenlab.sh/v1, replace the API key, and choose a model ID from GET /v1/models.
OpenRouter to TokenLab
Replace the OpenRouter base URL with https://api.tokenlab.sh/v1. TokenLab model IDs do not include an OpenRouter provider prefix. Use Anthropic Messages or Gemini only when your application needs fields from those formats.
LiteLLM to TokenLab
Use LiteLLM's custom_openai/<model> configuration with api_base: https://api.tokenlab.sh/v1. Keep your LiteLLM alias separate from the TokenLab model ID so either can change without editing application prompts.
Claude Messages via TokenLab
Point Anthropic SDK clients at https://api.tokenlab.sh and call messages.create. Do not append /v1 to the SDK base URL; the SDK owns the /v1/messages path.
Gemini Native via TokenLab
Keep Gemini payloads on https://api.tokenlab.sh/v1beta/models/{model}:generateContent. Gemini-native contents, parts, files, cached contents, function declarations, and built-in tools should stay on this route when your app depends on Gemini behavior.
OpenAI-Compatible Migration
from openai import OpenAI
client = OpenAI(
api_key="sk-your-tokenlab-key",
base_url="https://api.tokenlab.sh/v1",
)
response = client.chat.completions.create(
model="gpt-5.6-terra",
messages=[{"role": "user", "content": "Hello from TokenLab"}],
)Your existing retry, timeout, and streaming code can usually stay. Confirm the model ID with GET /v1/models. Image requests must include a model explicitly; see the image guide for model-specific inputs.
Anthropic Migration
from anthropic import Anthropic
client = Anthropic(
api_key="sk-your-tokenlab-key",
base_url="https://api.tokenlab.sh",
)
message = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Reply with: Connected to TokenLab."}],
)Use /v1/messages for Claude tool calls, thinking blocks, and Anthropic message fields. Chat Completions does not guarantee those fields.
Gemini Migration
curl "https://api.tokenlab.sh/v1beta/models/gemini-3.5-flash:generateContent" \
-H "Authorization: Bearer sk-your-tokenlab-key" \
-H "Content-Type: application/json" \
-d '{"contents":[{"parts":[{"text":"Hello"}]}]}'Keep Gemini built-in tools, File API references, cached contents, function declarations, and native content parts on /v1beta when your app depends on Gemini-native behavior.
Media Migration
- Query
GET /v1/models?recommended_for=image|video|music|3d. - Read
GET /v1/modelsin list responses and the fullGET /v1/models/{model}where available. - Send an explicit
model, especially for image endpoints. - Store
task_id,poll_url, endpoint, model, and your own job ID for async jobs. - Reconcile costs through usage records and
billing_transaction_id, not provider task IDs.
Media generation can finish asynchronously, so save task_id and poll_url before replacing an existing integration. A create-request timeout must not produce a second user job.
Migration Pitfalls
- Do not put every model behind one OpenAI Chat Completions path if your app needs native Anthropic, Gemini, or Responses behavior.
- Do not assume old image defaults. Send
modelexplicitly. - Do not retry async create requests without checking whether a task was already created.
- Use TokenLab task IDs and usage records in your product. Third-party task IDs are not billing identifiers.
API Reference
| Topic | Reference |
|---|---|
| Multi-Format API | Multi-Format API |
| OpenAI SDK | OpenAI SDK |
| Anthropic SDK | Anthropic SDK |
| Gemini Native | Gemini Native API |
| Image Generation | Image Generation |
| Async Jobs & Polling | Async Jobs & Polling |