← Documentation

Connecting TokRouter to your application

TokRouter exposes an OpenAI-compatible API. A single key lets you call every model enabled in your catalog.

Create an API key

  1. Log in to TokRouter.
  2. Open Settings.
  3. Under API keys, name your key and create it.
  4. Copy the value shown immediately.

The plaintext key is shown only once. Store it in a secrets manager or an environment variable, never in source code.

OpenAI-compatible setup

export OPENAI_API_KEY=sk-tok-...
export OPENAI_BASE_URL=https://tokrouter.mattok.ch/api/v1
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  baseURL: process.env.OPENAI_BASE_URL,
});

const completion = await client.chat.completions.create({
  model: "model-identifier",
  messages: [{ role: "user", content: "Hello!" }],
});

console.log(completion.choices[0]?.message.content);

Use the identifier shown on the Models page (the "API identifier" column), not necessarily the model's public display name. If a public alias has been configured for that model, use the alias — TokRouter translates it to the real underlying model behind the scenes.

Anthropic-compatible setup

Anthropic-compatible tools can use the following variables:

export ANTHROPIC_AUTH_TOKEN=sk-ant-tok-...
export ANTHROPIC_BASE_URL=https://tokrouter.mattok.ch/api

Verify the connection

Send a short request to an enabled model first. A 401 error usually means a missing, invalid, or revoked key. A 404 error means an incorrect model identifier. A 402 error means an insufficient balance. See Error handling for the full list.