Skip to content
Guides11 min read

Why Switch From Direct Provider APIs to an AI Gateway

Tariqul Islam
Platform Engineer
17 Oct 2026Updated 22 Oct 2026
On this page
Why Switch From Direct Provider APIs to an AI Gateway

TL;DR: If you already call Anthropic, OpenAI, and Google APIs directly, switching to an AI gateway is a one-line code change (base_url + one key) that buys you multi-provider failover, per-key spend caps, and a single BDT invoice. On a realistic multi-provider month (~28M tokens), the gateway route costs ~$39 vs ~$36 direct — a $3.50 premium that buys insurance against 2026's outage record. Migration takes an afternoon. Prices and outage figures checked 17 October 2026.

You're already doing the hard part. You integrated three providers, you handle three SDK quirks, you reconcile three bills, and at 2 a.m. when Anthropic's API starts 500-ing you write the retry logic yourself. The question isn't whether you can keep doing that — you can. The question is why you'd keep paying the ops tax when the switch is one line of code.

This post is the migration guide: what actually changes when you move direct provider calls behind an AI gateway, the real cost math, the five-step checklist, and — honestly — when you shouldn't bother.

For the full "what is a gateway" primer, see What Is an AI Gateway? And When You Actually Need One; for the three-route decision guide, see tokens.bd vs OpenRouter vs Direct APIs.

The switch is smaller than you think#

Every major provider and gateway speaks the same wire format: the OpenAI chat-completions shape. Moving your existing code behind a gateway is not a rewrite — it's this:

python
from openai import OpenAI

client = OpenAI(
    base_url="https://tokens.bd/v1",   # was https://api.anthropic.com or https://api.openai.com
    api_key="tk_live_your_tokens_key",  # one key replaces three
)

resp = client.chat.completions.create(
    model="anthropic/claude-sonnet-5.5",
    messages=[{"role": "user", "content": "Refactor this function"}],
)

One environment variable, one key, one model string. The model IDs differ (anthropic/claude-sonnet-5.5 instead of claude-sonnet-5-5), and that's the whole diff. tokens.bd also exposes an Anthropic-compatible endpoint on the same key, so Claude Code keeps working with ANTHROPIC_BASE_URL pointed at it — the pattern is the same one in our OpenAI SDK guide.

The migration work isn't the code. It's the checklist in step 5.

Reason 1: your uptime stops depending on one provider#

This is the argument with the best data in 2026. DevToolLab read 12 provider status pages for the 90 days from 14 July to 11 October 2026 and pulled every incident they posted. The headline numbers:

  • OpenAI's model APIs had an incident open for 72.7 hours of the 2,160-hour window (3.4%).
  • Anthropic's Claude API had an incident open for 76.5 hours (3.5%).
  • The two were in an incident at the same moment for only 36 minutes.

Read that last line twice. Single-provider exposure: ~73 hours of incident time in 90 days. Two-provider exposure behind automatic failover: ~36 minutes — roughly a 120× reduction in provider-caused exposure. (Caveat, honestly: "incident open" on a status page includes degraded periods, not only full outages — incident counts also measure each vendor's posting policy. But the overlap logic holds either way: two providers rarely break together.)

Bar chart comparing provider incident hours from July 14 to October 11, 2026: OpenAI model APIs 72.7 hours, Anthropic Claude API 76.5 hours, both down simultaneously only 36 minutes — failover to the healthy provider works 99.97% of the incident time

The failure mode that should worry you most is the September pattern: on 3 September 2026, ChatGPT, Claude, and Grok all degraded within a ~2-hour window. Direct integrations turned every one of those into your incident. A gateway with a fallback chain turns them into a latency blip.

Reason 2: a runaway bill stops being possible#

Direct APIs bill you per provider, and provider-side usage limits are configured separately in each console, in each vendor's own way — and nothing stops a stuck agent loop from spending across all of them at once. Gateways make spend policy one layer:

  • Per-key monthly caps. tokens.bd lets you set a cap when you create a key; requests past it stop with a clear error instead of billing you. See the setup in spend caps for coding agents.
  • Usage alerts at 50%, 75%, 90%, and 100% on the dashboard.
  • Model allow-lists per key — the experimental key can't touch the $16.50/1M-output model by accident.

One bug at 3 a.m. can send thousands of requests before you wake up. The cap is the difference between an alert email and an invoice.

Reason 3: model churn stops being your migration project#

Models get versioned, upgraded, and retired constantly. Claude Sonnet 4.5 retires on 30 November 2026 — if you call it directly, your migration deadline is Anthropic's. Behind a gateway, model IDs are logical strings on one endpoint: you test the replacement on a staging key, then flip production routing without touching app code. When the next "everything is deprecated" season arrives — and our November 2026 deprecation watch shows they arrive quarterly now — the switching cost drops to a string change. That optionality is worth real money; it's the reason frontier model comparison posts keep mattering.

Reason 4: the bill becomes one invoice you can actually pay#

This one is decisive for developers in Bangladesh, and it rarely appears in Western migration guides. Direct APIs bill each provider in USD by card — and Bangladesh Bank's FE Circular 26 (2019) caps international-card online payments at USD 300 per transaction with an OTAF form each time. Multiply that paperwork by every provider you use. A gateway collapses N provider bills into one, and tokens.bd's is payable in taka via bKash/Nagad with a printable receipt per payment — the same receipts-and-tickets dashboard where your keys live.

Reason 5: your keys stop living in twelve repos#

Raw provider keys scattered across repos, laptops, and CI secrets are how leaks happen and how one compromised credential becomes an unlimited bill. Gateways issue virtual keys — scoped, revocable, capped — while the real provider credentials live in the gateway's vault. Revoking a misbehaving service is one change in one place. On privacy: the better gateways are explicit about it; tokens.bd states it keeps only billing metadata (model, tokens, cost, latency) and never stores prompts or responses. If you send proprietary code, this section outranks the price table.

The honest cost math: a multi-provider month#

List prices and tokens.bd catalog prices checked 17 October 2026. Take a realistic solo-developer month split across two providers — 20M tokens of GPT-6 Luna for bulk work (16M input, 4M output) and 8M of Claude Sonnet 5.5 for hard reasoning (6M input, 2M output):

RouteGPT-6 Luna math (16M in / 4M out)Sonnet 5.5 math (6M in / 2M out)Monthly total
Direct provider APIs16 × $0.10 + 4 × $0.50 = $3.606 × $2.00 + 2 × $10.00 = $32.00$35.60
Via tokens.bd16 × $0.11 + 4 × $0.55 = $3.966 × $2.20 + 2 × $11.00 = $35.20$39.16 (≈ ৳4,895)

Direct list prices: GPT-6 Luna $0.10/$0.50 and Sonnet 5.5 $2.00/$10.00 per 1M input/output tokens. tokens.bd catalog (checked 17 October 2026): GPT-6 Luna $0.11/$0.55, Sonnet 5.5 $2.20/$11.00. BDT at tokens.bd's listed ~৳125 per USD.

The premium is $3.56 — about 10% — and it buys the failover, the spend caps, and one BDT invoice. Direct is cheaper per token and always will be; nobody should migrate over $3.56. Migrate over the other sections of this post.

The 5-step AI gateway migration checklist flow: 1) Audit direct keys — find every provider key in code, env files, CI; 2) Map model IDs — translate each model to its gateway string; 3) Set caps first — per-key monthly caps and model allow-lists; 4) Define fallback order — name a backup model for each primary; 5) Move billing, revoke old keys — pay the invoice, delete raw provider keys

The five-step migration checklist#

  1. Audit your direct keys. List every provider key in code, env files, CI, and teammates' machines. You can't migrate what you can't find.
  2. Map model IDs. Every model you call gets a gateway model string (e.g. claude-sonnet-5-5 → anthropic/claude-sonnet-5.5). Check the model catalog for the exact IDs and BDT prices before you write anything.
  3. Set caps before traffic. Create one key per environment (dev, staging, prod) with a monthly cap and an allow-list. See spend caps for coding agents.
  4. Define the fallback order. For each primary model, name the backup (e.g., Sonnet 5.5 → GPT-6.1 Sol → Gemini 3.8 Flash). tokens.bd fails over automatically to another upstream on 429, 5xx, and connection errors — your job is picking a sensible order, not writing retry code.
  5. Move billing, then retire the old keys. Pay the BDT invoice, confirm usage and alerts on the dashboard, then delete the raw provider keys from every repo. A migrated key you didn't revoke isn't migrated.

To sanity-check your monthly bill before and after, run the method in how to estimate your monthly token bill against your own input/output split.

When you shouldn't switch#

Honesty requires this section. Don't migrate when:

  • It's one model, one key, low volume. A weekend prototype calling GPT-6 Luna gains nothing from a control layer.
  • You're latency-critical at the millisecond level. A gateway proxy adds single-digit milliseconds; on hot single-request paths, measure first. (For coding agents, it's noise.)
  • You need the provider's SLA or negotiated terms. A gateway doesn't sell you Anthropic's or OpenAI's SLA — uptime sources move to the gateway's status page.
  • You want fine per-request provider ordering and price-sorting flags. Power features some gateways have; if your architecture depends on them, check the feature list first — see the full side-by-side at /vs/openrouter.

The common middle ground: start direct, migrate the week you add a second model or a second developer. That week arrives sooner than most teams expect.

Migration FAQ#

How long does the migration actually take? The code change is minutes — one base_url and key swap. The checklist above is the real work: auditing keys, mapping model IDs, and setting caps. Budget an afternoon, most of it step 1.

Will a gateway raise my per-token costs? On tokens.bd the margin is roughly 10% over provider list price on the worked example above — about $3.56/month at this workload. Against that: no per-request markup (OpenRouter's cut comes at the credit-purchase step instead), and the premium buys failover, caps, and BDT billing. Run your own split through the monthly bill estimator.

What happens when my primary model has an outage? The gateway retries with backoff and routes to the next upstream on 429s, 5xx errors, and connection failures — no code change on your side. Over July–October 2026, OpenAI and Anthropic model-API incidents overlapped for only 36 minutes, so a two-provider fallback chain shrinks your provider-caused exposure dramatically.

Can I still use Claude Code and other agents? Yes. tokens.bd exposes an Anthropic-compatible endpoint on the same key, so ANTHROPIC_BASE_URL keeps Claude Code working; the one-key setup guide covers Claude Code, Codex CLI, OpenCode, and Crush.

Does switching mean rewriting prompts or SDKs? No — every major route speaks the OpenAI chat-completions shape. You change base_url, the key, and the model string. Prompt behavior is provider-model-specific, not route-specific, so your prompts carry over unchanged.

List prices and outage figures checked 17 October 2026. Promotional prices, incident counts, and gateway fees change; the maker's page is the authority for list prices, and the model catalog for prices on Tokens. BDT conversions at tokens.bd's listed ~৳125 per USD.

Sources: DevToolLab: LLM API Outages in 2026 — 90 Days of Data · Tokens model catalog · Tokens vs OpenRouter · What Is an AI Gateway? · tokens.bd vs OpenRouter vs Direct APIs

A real-world example of the gateway-vs-marketplace-vs-direct decision: OpenAI on Google Cloud: The Developer's Buying Guide works the same comparison on OpenAI's newest models, with Google Cloud Marketplace entering as a third buying route.

Was this page helpful?

Still stuck? Open a support ticket

Use the coding models you already know, through one API

One key for OpenAI- and Anthropic-compatible tools. Pay in BDT or USD, and keep the coding agent you already use.

Create an account

Follow us for more articles