Migrate from Anthropic

Move from the Anthropic API to Flux by changing the base URL, key, and model. Nothing else changes.

Flux speaks the Anthropic Messages API. If your code already calls Anthropic, you keep the same SDK and the same request shape. You change three things:

  1. Base URL to https://api.fluxrouter.ai/anthropic
  2. API key to your Flux key (sk-... from the dashboard)
  3. Model to flux-auto (or a specific flux-* id)

The endpoint (/anthropic/v1/messages), the request and response JSON, streaming, and tool use all stay the same.

How auth works on the Anthropic endpoint

The Flux Anthropic endpoint accepts your key two ways:

  • As x-api-key: sk-... (the Anthropic SDK default), or
  • As Authorization: Bearer sk-....

The Anthropic SDK sends x-api-key automatically when you set its API key, so you do not have to do anything special.

Get a Flux key

Sign up at /auth/sign-up and copy your key. It looks like sk-.... Get your key walks through it. The examples below read it from a FLUX_API_KEY environment variable.

Migrate the Python SDK

Before (Anthropic)

python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-ant-...",
)

message = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello."}],
)

print(message.content[0].text)

After (Flux)

python
from anthropic import Anthropic

client = Anthropic(
    api_key="sk-...",                                # your Flux key (sent as x-api-key)
    base_url="https://api.fluxrouter.ai/anthropic",  # the one line you change
)

message = client.messages.create(
    model="flux-auto",                               # let Flux route, or pin a flux-* id
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello."}],
)

print(message.content[0].text)

Migrate the Node SDK

Before (Anthropic)

ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const message = await client.messages.create({
  model: "claude-sonnet-4-5",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Say hello." }],
});

console.log(message.content[0].text);

After (Flux)

ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  apiKey: process.env.FLUX_API_KEY,                  // your Flux key (sent as x-api-key)
  baseURL: "https://api.fluxrouter.ai/anthropic",    // the one line you change
});

const message = await client.messages.create({
  model: "flux-auto",                                // let Flux route, or pin a flux-* id
  max_tokens: 1024,
  messages: [{ role: "user", content: "Say hello." }],
});

console.log(message.content[0].text);

What stays the same

Everything except the three values above:

  • The Anthropic SDK and its method names (messages.create).
  • The endpoint: /anthropic/v1/messages.
  • The request and response JSON, including max_tokens, system prompts, streaming, and tool use.
  • Your prompts, message arrays, and parameters.

What to do about the model field

Anthropic model ids like claude-sonnet-4-5 are not Flux models. Pick one of these instead:

  • flux-auto (recommended): Flux picks among vetted models for each kind of task, cost-aware.
  • A lane alias (flux-fast, flux-standard, flux-reasoning) to choose a class of model and its rate.
  • A flux-pinned-* id when you want the same backing model every time. Claude models are in the catalogue too, so you can pin the one you use today.

What each option costs is on Pricing.

The authoritative list of model ids is GET https://api.fluxrouter.ai/v1/models. See Models.

Reading cost on this endpoint

On the /anthropic endpoint the usage block stays as token counts, just as on Anthropic direct. There is no cost field in the body. The cost of a non-streaming call is in the X-Flux-Cost-Usd header, so read it through your SDK's raw-response path:

python
raw = client.messages.with_raw_response.create(
    model="flux-auto",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
cost_usd = raw.headers.get("x-flux-cost-usd")
message = raw.parse()

A streamed call has no cost header. Its cost shows in Usage and on your bill.

The answer may not come from Claude

Send flux-auto in Anthropic's wire format and the model that answers does not have to be a Claude model. Flux picks per request. On a non-streaming response, X-Flux-Model names the model that answered and X-Flux-Routed says whether Flux changed the model you asked for. If you want Claude every time, pin it with a flux-pinned-* id.

Before you switch production traffic

Run these checks with the new key before real traffic moves.

  1. List models. GET https://api.fluxrouter.ai/v1/models proves the key works and shows the ids you can use.
  2. Send one non-streaming call and read the headers. You should see the receipt headers from Receipts, including X-Flux-Cost-Usd. A streamed response has no cost header.
  3. Send one streaming call. Check that your chunk parsing holds to the end of the stream.
  4. Run one tool-call round trip with your real tool schema. If tools are essential to your product, test the pinned model you will rely on as well as flux-auto, because tool support belongs to the model that answers.
  5. Check any pin. Send your flux-pinned-* id without streaming and read X-Flux-Routed: false and X-Flux-Model.
  6. Log X-Flux-Request-Id from day one. It is the first thing support asks for.
  7. Canary first. Set a prepaid daily or monthly cap in Billing (see Spend caps), send a slice of traffic, compare errors, latency and cost with your Anthropic baseline, and keep the old key until a full day runs clean. The old key is your rollback.

Next steps