Developer documentation
Tokenly is a drop-in replacement for the OpenAI and Anthropic APIs. Point your SDK at Tokenly, change the key — and everything else works as before. Below: how to send your first request, how authentication works, ready-to-use code samples and streaming.
Quick start
Three steps to your first request. If you already use the OpenAI or Anthropic SDK, only the base URL and the key change.
- Create an API key in your dashboard — you can copy it any time from the API keys page.
- Top up your balance with a card, SBP or cryptocurrency — Tokenly is prepaid.
- Set the base URL and the key in your SDK and send your first request.
https://tokenly.plus/api/v1
Keys live on the API keys page; the current model slugs are in the model catalogue.
Authentication
Every request is authenticated with an API key passed in the Authorization header as a Bearer token. One key routes to every provider — the provider is chosen by the model in the request body.
You can copy an API key at any time from the API keys page. Keep it secret and revoke any compromised key there.
Error codes
- 401Invalid or disabled key
- 402Insufficient balance
- 404Unknown model
- 503Provider unavailable or server busy
Endpoints
Pick the endpoint that matches your model's provider dialect — the model in the request body decides which upstream provider the request is routed to.
| Endpoint | Dialect | Providers |
|---|---|---|
POST /api/v1/chat/completions |
OpenAI Chat Completions | OpenAI, Gemini, Anthropic |
POST /api/v1/responses |
OpenAI Responses | OpenAI |
POST /api/v1/messages |
Anthropic Messages | Anthropic |
GET /api/v1/balance |
Tokenly | — |
Check balance
Fetch your current prepaid balance programmatically with the same API key you use for requests — handy for dashboards, low-balance alerts or a pre-flight check in CI before a big job.
balance is a decimal string in US dollars at full precision. This endpoint is never funds-gated, so you can poll it even at a zero or negative balance to decide when to top up.
Code examples
The API is fully compatible with the OpenAI and Anthropic SDKs. Pick your stack — the only change is the base URL and the key.
Streaming
Streaming is supported on every endpoint. Add "stream": true to the request body and the response arrives as a Server-Sent Events (SSE) stream — exactly as it does with the provider directly.
Billing is metered from the final stream chunk, so a streamed request costs the same as a non-streamed one.
Integrations
Tokenly speaks the native Anthropic and OpenAI dialects, so tools built against those APIs work after changing two settings. Below are ready-to-paste configurations.
Claude Code CLI
Claude Code talks to the Anthropic Messages API, so pointing it at Tokenly takes a single settings file — no plugin, no local proxy. Requests are billed at Tokenly prices and show up in your statistics like any other API call.
- Create an API key in your dashboard and copy it.
- Open ~/.claude/settings.json (create the file if it does not exist).
- Paste the configuration below, put your key into ANTHROPIC_AUTH_TOKEN and restart claude.
~/.claude/settings.json
| Key | What it does |
|---|---|
ANTHROPIC_AUTH_TOKEN |
Your Tokenly API key. Claude Code sends it as a Bearer token on every request. |
ANTHROPIC_BASE_URL |
The Tokenly gateway. Note there is no /v1 at the end — Claude Code appends /v1/messages itself. |
ANTHROPIC_DEFAULT_OPUS_MODEL |
Which catalogue model the opus alias resolves to. |
ANTHROPIC_DEFAULT_SONNET_MODEL |
Which catalogue model the sonnet alias resolves to. |
ANTHROPIC_DEFAULT_HAIKU_MODEL |
Which catalogue model the haiku alias resolves to — Claude Code uses it for background tasks. |
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC |
Turns off non-essential calls to Anthropic's own servers so all traffic goes through Tokenly. |
model |
The alias Claude Code starts with. You can switch at any time with the /model command. |
Any model from the model catalogue works here — just swap in the slugs you want. Models are resolved by exact slug, so write the identifier exactly as it appears in the catalogue.
OpenCode
OpenCode reaches Tokenly through its OpenAI-compatible provider adapter, so it is a matter of one block in the config — and both Anthropic and OpenAI models end up under a single provider, on one key and one balance.
- Create an API key in your dashboard and copy it.
- Open ~/.config/opencode/opencode.json (or opencode.json in the project root, for a per-project setup).
- Add the provider block below, put your key into apiKey and pick the models you need under models.
~/.config/opencode/opencode.json
| Field | What it does |
|---|---|
provider.tokenly |
The provider id. Models appear in the picker under this prefix — for example tokenly/claude-opus-5. |
npm |
The OpenAI-compatible adapter OpenCode loads for the provider. Leave it as is. |
options.baseURL |
The Tokenly gateway. Unlike Claude Code, the /v1 belongs here — OpenCode appends only /chat/completions. |
options.apiKey |
Your Tokenly API key. |
models |
The models available in the picker. Each key is a catalogue slug; name is only the display label. |
Both dialects go through one provider: Anthropic, OpenAI and Gemini models alike are served by /api/v1/chat/completions. Add as many models from the model catalogue as you like — the key of each entry must match the catalogue slug exactly.