---
title: "Messages API gateway for Claude, GPT and DeepSeek · Selan"
description: "Point an Anthropic SDK's base URL at Selan's gateway and send one token: your scripts run on your company's accounts, metered in Usage and Logs per token."
url: https://selan.ai/docs/api
updated: 2026-11-24T21:07:20+02:00
---

Build

Docs · API

# Call Claude, GPT and DeepSeek from your own code

The gateway speaks the Anthropic Messages API: change a base URL and a token. For Claude Code itself, start at [the docs](https://selan.ai/docs).

## How do I get an API token?

An owner mints one under [**Settings → API tokens**](https://control.selan.ai/settings/access). It is shown once:

```bash
export SELAN_TOKEN=selanct_...
```

A token **spends as itself**, under an address like `billing-sync@tokens.selan.ai`, so a service's cost shows as that service in Usage and Logs. Give each caller its own token, named after the caller.

**Revoking is immediate**, with no grace period. Mint the new token first.

## How do I make a request?

`POST /v1/messages` with the body you would send to Anthropic (see the [Messages API reference](https://docs.claude.com/en/api/messages)):

```bash
curl https://gw.selan.ai/anthropic/v1/messages \
  -H "Authorization: Bearer $SELAN_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -H "x-selan-repo: gitlab.com/selan-ai/billing-sync" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
```

The gateway leases one of your company's connected credentials for the request. Your IP address and trace headers such as `x-forwarded-for` and `traceparent` are never forwarded to the provider.

Send `"stream": true` and the server-sent events arrive as the provider emits them, never buffered.

## How do I call it from an Anthropic SDK?

The Anthropic SDKs take both values in the constructor:

```typescript
import Anthropic from "@anthropic-ai/sdk"

const client = new Anthropic({
  baseURL: "https://gw.selan.ai/anthropic",
  authToken: "selanct_...",
  defaultHeaders: {
    "x-selan-repo": "gitlab.com/selan-ai/billing-sync",
  },
})

const message = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello" }],
})
```

Python:

```python
from anthropic import Anthropic

client = Anthropic(
    base_url="https://gw.selan.ai/anthropic",
    auth_token="selanct_...",
    default_headers={
        "x-selan-repo": "gitlab.com/selan-ai/billing-sync",
    },
)

message = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
```

**It has to be `authToken`, not `apiKey`.** An API key sends `x-api-key`, and the gateway reads only `Authorization: Bearer`, so every request gets `401`. Setting both options in code also stops a stray `ANTHROPIC_API_KEY` in the environment from deciding this for you.

## How do I attribute usage to a repository?

Send `x-selan-repo` with a host-qualified slug such as `gitlab.com/selan-ai/billing-sync`: no scheme, credentials, leading slash or final `.git`, 1 to 200 UTF-8 bytes. If the repository is unknown, omit the header.

It feeds Usage and Insights and is never forwarded to the provider. It is recorded only when an owner has enabled **Repository attribution**. The Selan CLI and `agent-run` set it automatically; a custom Claude Code Agent SDK launch sends it through `ANTHROPIC_CUSTOM_HEADERS`:

```typescript
function runRepositoryTask(authToken: string, repository: string) {
  return query({
    prompt: "Review this repository",
    options: {
      env: {
        ...process.env,
        ANTHROPIC_BASE_URL: "https://gw.selan.ai/anthropic",
        ANTHROPIC_AUTH_TOKEN: authToken,
        ANTHROPIC_CUSTOM_HEADERS: `x-selan-repo: ${repository}`,
      },
    },
  })
}
```

## How do I name a model?

A bare id like `claude-opus-5-5` runs on your company's Anthropic accounts. Otherwise name a provider and its model id:

```json
{ "model": "openrouter:deepseek/deepseek-v4.1-flash-1017" }
{ "model": "openrouter:moonshotai/kimi-k3" }
{ "model": "openai:gpt-6.1-sol" }
```

The part before the first colon is the provider: `openrouter`, `openai`, `openai-api` or `ollama`. The rest is that provider's own model id. Any model the provider serves works, except that a model Selan lists must first be switched on by an owner at that provider. Capitals, dashes and dots do not change which model you get. [Providers and models](https://selan.ai/docs/providers) lists what each can serve.

A DeepSeek request:

```bash
curl https://gw.selan.ai/anthropic/v1/messages \
  -H "Authorization: Bearer $SELAN_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "openrouter:deepseek/deepseek-v4.1-flash-1017",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
```

Your company's connected provider keys decide what you can reach. A provider it has not connected, or a model that provider does not serve, is a `403`, never a quiet fallback. The one exception is an outage at the provider, below.

## What happens when Anthropic is down?

When Anthropic fails with a `500`, `502`, `503`, `504` or `529`, or gives no answer, and Selan's own retries have not helped, the request is sent once more as the _same model_ through another connected provider, Claude on Vertex first. Your client sees one ordinary answer. Three such failures in a row make Selan skip Anthropic for five minutes, then try it with a single request. A `429` or bad request never triggers this. If no other connected provider serves the model, the original failure stands.

A streamed request with no first byte within 90 seconds counts as no answer: it ends as a `504`, or moves to another provider. No new retry starts once a request has been trying for about two minutes, apart from the first failover.

Under **Settings**, **Reliability**, an owner can switch on **Switch model when Claude is down** (off by default). For each Claude family (Opus, Sonnet, Fable, Haiku) the owner picks a model switched on under Models, or **No fallback**. Only once the same model has failed at every connected provider is the request answered by the chosen model. It can differ in quality, speed and price, is billed to the key that served it, and Usage shows it under that model.

## How do I see which route answered?

Every answer from a provider, success or error, carries `x-selan-routed-via`:

```bash
x-selan-routed-via: kind=openrouter; attempts=2; failover=true; model=moonshotai/kimi-k3
```

| Parameter | What it means |
| --- | --- |
| `kind` | The kind of provider connection that answered, such as `oauth`, `api`, `vertex` or `openrouter`. |
| `attempts` | How many attempts Selan sent upstream before this answer, the answering one included. |
| `failover` | `true` when the request left the kind of connection it started on, such as a subscription seat to a metered key, or one provider to another. Another key of the same kind does not count. |
| `model` | Present only when a different model answered than the one you named: a fallback model, a company rule or a retired name. |

Parameters are separated by `;` ; read them by name. The header is set with the first bytes, so a stream later continued on another connection still names the first. It never names a key, token or project. Answers Selan makes itself, such as a refused request, do not carry it.

## What does a failed request tell me?

Every error the gateway mints says whose fault it was, in the body and in the headers `x-selan-source`, `x-selan-fault` and `x-selan-request-id`, mirroring `{ error, source, fault, request_id }`. Quote the request id when you ask us. Our messages are prefixed `selan:`, a provider's never. A response with `x-selan-source: upstream` and no fault is the provider's own, relayed untouched.

| Status and fault | What it means |
| --- | --- |
| `401` `no_session` | No bearer, or none matching a live token. Check for a stray `ANTHROPIC_API_KEY` first. |
| `403` `model_not_allowed` | Your company has not connected that provider, or it does not serve that model. The message says which when it is something else: `selan: "<id>" is switched off for your company — an owner can switch it on in Models`, or, for a bare id Selan does not list, `selan: "<id>" is not a model Selan offers. Your company can use: …` with the ids that would work. |
| `403` `own_proxy` | Your company runs [Own proxy](https://selan.ai/docs/self-hosted), and Selan's hosted proxy serves none of its requests: `selan: your company runs Selan on its own proxy at <address>`. Send the request to that address, on your VPN. Retrying here will not help, and neither Claude Code nor Codex retries it. |
| `400` `request_untranslatable` | Selan could not translate the request for the provider that serves the model: `selan: the request could not be translated for the connected provider — retrying will not help`. Change the request rather than retrying it. |
| `413` `request_too_large` | The body is over 24 MiB and Selan had to read it whole, to sweep it for secrets or to change it for the provider that serves the model: `selan: request too large`. A body Selan forwards unchanged streams through and is not held to that limit. Send less rather than retrying. |
| `408` `body_stalled` | The body stopped arriving for 30 seconds while Selan was reading it whole: `selan: the request body stopped arriving`. Nothing was sent to the provider, so a retry is safe. |
| `402` `over_budget` | A spend limit, or a member's daily token limit, stopped the request. `retry-after` is when the window resets. |
| `429` `user_cap` | This caller's own concurrency cap never cleared. Retry, with less in flight. |
| `503` `no_capacity` | No credential in the company's pool could take the request, and no `retry-after` comes with it. If they are busy, a retry soon works. If every subscription seat has used up its 5-hour or weekly window and no API key serves the model, nothing frees until a window resets. |
| _theirs_, no fault | The provider answered. A `429` or `529` here is theirs, and means what it always did. |

## What does my company see in Usage and Logs?

Every request lands in Usage and Logs under the token's address, with the model, token count and cost.

Two optional headers: `x-selan-application` names which of your programs made the call, and `x-selan-end-user` says whose work it was, a customer of yours, shown in Logs and never treated as a member. Neither is billed or capped on its own. Selan's own agents send the first: Usage names `selan-agent` **Selan remote agents**, for Reactor runs, and `selan-local-agent` **Selan local agents**, for [`selan agent-run`](https://selan.ai/docs/agents).

```bash
curl https://gw.selan.ai/anthropic/v1/messages \
  -H "Authorization: Bearer $SELAN_TOKEN" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -H "x-selan-repo: acme/checkout-service" \
  -H "x-selan-application: support-bot" \
  -H "x-selan-end-user: rita@customer.test" \
  -d '{
    "model": "claude-opus-5-5",
    "max_tokens": 1024,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'
```

`x-selan-end-user` shows once your owner turns that setting on; until then it is dropped, not stored.

## Are requests scanned for secrets?

If an owner has switched **secret scanning** on, a credential found is replaced with `[REDACTED: rule-id]` and the request goes through. See [Secret scanning](https://selan.ai/docs/secrets).

## Related

-   [How Claude Code and Codex run without API keys on laptops](https://selan.ai/guides/claude-code-without-api-keys)
-   [Claude Agent SDK](https://selan.ai/docs/claude-agent-sdk)
-   [Reference](https://selan.ai/docs/reference)
-   [LiteLLM and Selan compared](https://selan.ai/compare/litellm)
