# Move from OpenRouter

Point an existing OpenRouter integration at Tokenlane: two values change, a few behaviors differ.

## Change the connection

Set up Tokenlane first: unlock the organization, add credit and create an inference key ([Quickstart](https://tokenlane.de/docs/guides/quickstart.md?lang=en), steps 1, 2 and 4). OpenRouter keys do not work here. Then swap base URL and key. Replace the entire base URL: `https://openrouter.ai/api/v1` becomes `https://api.tokenlane.de/v1`. Changing only the host leaves `/api/v1` and returns `404 not_found`. Model, messages and parameters stay. The headers `HTTP-Referer` and `X-Title` may stay and are ignored.

### curl

```diff
-curl 'https://openrouter.ai/api/v1/chat/completions' \
-  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
+curl 'https://api.tokenlane.de/v1/chat/completions' \
+  -H "Authorization: Bearer $TOKENLANE_API_KEY" \
   -H "Content-Type: application/json" \
```

### node

```diff
 const client = new OpenAI({
-  baseURL: "https://openrouter.ai/api/v1",
-  apiKey: process.env.OPENROUTER_API_KEY,
+  baseURL: "https://api.tokenlane.de/v1",
+  apiKey: process.env.TOKENLANE_API_KEY,
 });
```

### python

```diff
 client = OpenAI(
-    base_url="https://openrouter.ai/api/v1",
-    api_key=os.environ["OPENROUTER_API_KEY"],
+    base_url="https://api.tokenlane.de/v1",
+    api_key=os.environ["TOKENLANE_API_KEY"],
 )
```

### vercel

```diff
 import { createOpenRouter } from '@openrouter/ai-sdk-provider';
 
-const provider = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
+const provider = createOpenRouter({
+  baseURL: "https://api.tokenlane.de/v1",
+  apiKey: process.env.TOKENLANE_API_KEY,
+});
```

## Vercel AI SDK

If you already use `@openrouter/ai-sdk-provider`, keep it. The connection diff above is the smallest migration; existing `generateText`, `streamText`, tool loops, structured output, reasoning and provider routing calls keep their provider.

For a new integration, `@ai-sdk/openai-compatible` is an alternative. Install it with `ai` and create the provider below; pass its model to the usual AI SDK calls. Use `maxOutputTokens`, `temperature` and other supported AI SDK settings directly. Gateway extensions such as `provider`, `plugins` and `reasoning` belong in `providerOptions.tokenlane`.

```ts
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

const tokenlane = createOpenAICompatible({
  name: 'tokenlane',
  baseURL: 'https://api.tokenlane.de/v1',
  apiKey: process.env.TOKENLANE_API_KEY,
  includeUsage: true,
});
```

## Endpoints

Base URL `https://api.tokenlane.de/v1`, with the same inference key for every endpoint below. The API reference shows a runnable example for each. OpenRouter's own products (hosted agents, Auto Router, rankings) do not exist.

| Endpoint | Format | Differences |
| --- | --- | --- |
| `POST /chat/completions` | OpenRouter and OpenAI | Streaming, tools, structured outputs, reasoning, `provider`, `models` and `plugins`; details in the table below. |
| [`POST /responses`](https://tokenlane.de/docs/gateway/post-L3Jlc3BvbnNlcw.md?lang=en) | OpenAI Responses | Stateless: `previous_response_id` returns `400 invalid_parameter`, so send the complete conversation in `input`. |
| [`POST /messages`](https://tokenlane.de/docs/gateway/post-L21lc3NhZ2Vz.md?lang=en) | Anthropic Messages | For Anthropic SDKs, set `ANTHROPIC_BASE_URL` to the gateway origin without `/v1`; the key works as `x-api-key` or `Authorization: Bearer`. |
| `POST /embeddings` | OpenRouter and OpenAI | `usage.cost` in EUR. |
| [`POST /rerank`](https://tokenlane.de/docs/gateway/post-L3JlcmFuaw.md?lang=en) | Cohere v2 style | Gateway extensions for text objects and returned documents. |
| `POST /audio/transcriptions`, `POST /audio/speech` | OpenRouter | Speech defaults to `pcm`, not `mp3`. |
| [`POST /ocr`](https://tokenlane.de/docs/gateway/post-L29jcg.md?lang=en), [`POST /pii/redact`](https://tokenlane.de/docs/gateway/post-L3BpaS9yZWRhY3Q.md?lang=en) | Tokenlane | No OpenRouter equivalent. |
| `GET /models` | OpenRouter | No key needed. Prices in EUR; each model lists its `routes`. |
| `GET /key`, `GET /generation` | OpenRouter | Amounts in EUR, also in fields named `*_usd`. |

## What stays and what differs

| Topic | Same | Different |
| --- | --- | --- |
| Model IDs | The `vendor/model` format. | Curated European catalog only. Unknown IDs, suffixes such as `:free` and `openrouter/auto` fail with `400 model_not_found`. |
| Routing | `provider` (`order`, `only`, `ignore`, `allow_fallbacks`, `require_parameters`, `max_price`, `sort`) and `models` fallbacks. | European providers only. `max_price` is EUR per million tokens. `sort` by latency or throughput uses this gateway's measurements. [Routing and fallbacks](https://tokenlane.de/docs/guides/routing-and-fallbacks.md?lang=en) |
| Plugins | `file-parser` and `response-healing` use the familiar request shape. | Availability depends on the instance: `web` requires an offered search route and permission for `web_search`; `pii-redact` requires a configured detector. Without a configured detector, `pii-redact` returns `501 feature_unavailable`. If `web` is not offered, it returns `400 invalid_parameter` with an issue code of `not_available` according to the instance configuration. Do not assume that production offers them. |
| Parameters | All of OpenRouter's; unknown ones are ignored. | Ignored names appear in the `x-ignored-params` header. The whole body is checked before any provider call, so problems OpenRouter forwards (unknown role, broken tool schema, bad image URL) fail at once with every issue listed. |
| Errors | `error.code`, `message`, `metadata`; same statuses. | `metadata.type` is stable; `request_id`, `issues`, `remedy_hint` and `retryable` are always set. `raw` stays empty. Provider field paths are deliberately not imported; when no safe field is known, `issues[].path` keeps the `$` fallback. |
| Streaming | Server-sent events ending in `data: [DONE]`; later failures arrive as an error event. | The last chunk before `[DONE]` has `usage` with the cost in EUR. |
| Billing | Prepaid credit, `usage.cost`. | EUR throughout: `usage.cost`, `usage.currency`, `/models` prices, `max_price`, key limits. Fields named `*_usd` in `GET /v1/key` hold EUR; budget objects in `budgets` and `effective_budget` explicitly carry `currency: "EUR"`. |
| Account automation | Management keys. | The Management API on the dashboard host under `/api`, with its own paths and errors. [Authentication](https://tokenlane.de/docs/guides/authentication.md?lang=en) |

`GET /v1/byok/import-key` is infrastructure for importing keys through the console. `GET /v1/media/{token}` is temporary provider transport. These are internal integration helpers, not endpoints for customer application code. The API reference labels them accordingly.

## Deliberate endpoint and behavior differences

These OpenRouter or OpenAI endpoints are not offered and return `404 not_found`:

| Not offered | Alternative |
| --- | --- |
| `GET /v1/credits` | `GET /v1/key`, using `gateway_credits` for the gateway balance. |
| `GET /v1/providers` | `GET /v1/models`, using the model's `routes`. |
| `GET /v1/models/{author}/{slug}/endpoints` | `GET /v1/models`, using the model's `routes`. |
| `POST /v1/completions` | `POST /v1/chat/completions` with a `messages` array. |

`/api/v1` deliberately remains unsupported, not an alias for `/v1`.

For text-to-speech, `POST /v1/audio/speech` defaults to `pcm`, unlike OpenAI's `mp3`. Set `response_format` explicitly when the application expects a specific format.

A required feature that is permanently not configured returns `501 feature_unavailable`, `retryable: false`, without `Retry-After`. Retrying the same request cannot enable it. Temporary outages remain distinct and keep their specific error type and retry guidance; not every unavailable provider or transient failure is a 501.

## Before you switch traffic

- [ ] Every model ID in use is in `GET /v1/models`, without suffixes.
- [ ] Plugins and parameters from the table are removed or replaced.
- [ ] `max_price` and spending limits are EUR amounts.
- [ ] Error handling reads `error.metadata.type`; a 402 leads to a top-up, not a retry.
- [ ] A normal and a streaming request succeed with a plausible `usage.cost` and `usage.currency` `EUR`.
- [ ] Automation built on OpenRouter management keys uses the Management API.

## Next

- [Privacy and compliance](https://tokenlane.de/docs/guides/privacy-and-compliance.md?lang=en): data classes per route
- [Errors and retries](https://tokenlane.de/docs/guides/errors-and-retries.md?lang=en): what deserves a retry