Skip to content

Add BYOK to an Existing App

Attach your own provider keys to AnyRouter so your existing integration bills against your provider accounts at list price, with one base URL change.

You already have an app talking to OpenAI, Anthropic, or another provider, and you pay that provider directly. Bring Your Own Key (BYOK) keeps that billing relationship while moving your traffic through AnyRouter — so you get unified logs, analytics, routing, and presets without paying a markup on tokens.

The idea

The only code change is the base URL and the key. Your provider keys stay in AnyRouter as encrypted BYOK credentials; your app never sends them again. When a request matches a model served by a provider you've configured, AnyRouter forwards the call with your key and charges you nothing extra per token.

flowchart LR
  app["Your app"] -->|sk-ar-... only| ar["AnyRouter"]
  ar -->|your encrypted key| prov["OpenAI / Anthropic / ..."]
  ar --> extras["Logs · analytics · routing · presets"]

How it works

PathWho you payAnyRouter fee
BYOK (your provider key matches the model)The upstream provider, directlyNone per token
AnyRouter credits (no BYOK key for that model)AnyRouter creditsListed model price

BYOK requests never draw down AnyRouter credits. If you want a safety net, keep credits funded so requests still succeed when a BYOK provider is out of quota — see the fallback step below.

Implementation

Store your provider key

Open Settings → BYOK and add the provider key you already use — for example your OpenAI or Anthropic key. AnyRouter encrypts it at rest and only uses it to sign your own requests. You can add more than one provider.

Create an AnyRouter key

Create an sk-ar- key in Dashboard → Keys. This is the only key your app sends from now on.

Point your app at AnyRouter

Swap the base URL and key. The request body is unchanged — AnyRouter speaks the same OpenAI-compatible protocol.

import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://anyrouter.dev/api/v1",
  apiKey: process.env.ANYROUTER_API_KEY, // sk-ar-v1-...
})

const completion = await client.chat.completions.create({
  model: "openai/gpt-5.4-mini",
  messages: [{ role: "user", content: "Hello from my app" }],
})

Because you stored an OpenAI BYOK key in the first step, this request is served with your OpenAI account — same bill from OpenAI, plus AnyRouter's logs and analytics on top.

Fall back to credits when BYOK is exhausted (optional)

Pair BYOK with Smart Routing so that if your provider account hits a rate limit or runs out of quota, AnyRouter can fall back to a credit-billed upstream and keep your app running:

{
  "model": "openai/gpt-5.4-mini",
  "messages": [{ "role": "user", "content": "Hello" }],
  "provider": { "allow_fallbacks": true }
}