Guides

OpenAI-Compatible API Gateways: Managed Routing vs Self-Hosted

A practical decision guide for developers and technical leads choosing between a managed routing gateway and a self-hosted one for OpenAI-compatible APIs — with conformance tests, evaluation criteria, and cost-modeling steps.

Short answer

Pick a managed routing gateway when your constraint is time-to-production, multi-provider failover, and per-key usage accounting that someone else operates. Pick a self-hosted gateway when your constraint is data residency, network isolation, or a compliance regime that forbids a third party sitting in the request path. Most teams that outgrow the first choice end up in a hybrid: managed for external traffic and developer sandboxes, self-hosted inside the private network for regulated workloads.

The rest of this article explains how to make that call on evidence rather than on vibes, and how to test either option before you commit.

What "OpenAI-compatible" actually promises

The phrase is a compatibility claim, not a specification, and vendors apply it with very different levels of rigor. Before comparing deployment models, agree on what you need the compatibility layer to preserve:

  • Request/response schema for chat completions, and whether other endpoints (embeddings, rerank, image, audio) follow the same shape.
  • Streaming semantics — server-sent events with the same delta/chunk structure, correct [DONE] termination, and no buffering that breaks first-token latency.
  • Tool/function calling and structured-output fields, including how unsupported features degrade.
  • Error contract — HTTP status codes and error body shape, so client retry logic doesn't need per-provider branches.
  • Usage reporting — a usage object on responses, and whether it is authoritative for billing or approximate.
  • Model discovery — what /v1/models returns and whether it reflects real availability.

A gateway that is 95% compatible will cost you more in client-side special cases than it saves. Write the compatibility list down before you evaluate anything.

The seven criteria that actually decide it

  1. Protocol fidelity. Does it pass your compatibility list above, including streaming and tool calls?
  2. Routing control. Can you express the routing you need — by model alias, by key, by tenant, by fallback order — and observe what the router actually did?
  3. Identity and key management. Per-tenant keys, scoping, rotation, and revocation. This is the part teams most often underestimate when self-hosting.
  4. Metering and attribution. Can you answer "which team spent what, on which model, this month?" to the granularity finance accepts?
  5. Deployment and data path. Where does the request terminate, what is logged, how long is it retained, and who can read it?
  6. Operational surface. Patching, upgrades, capacity, and on-call. A self-hosted gateway is a service you now own.
  7. Exit path. How hard is it to move to the other model? Standard client libraries plus a base-URL swap is the ideal; a proprietary SDK is a warning sign.

Score both options against the same list. Most disagreements on teams dissolve once the criteria are explicit.

Managed routing: where it wins

A managed gateway sits between your application and one or more third-party inference services. You get a stable base URL, key management, routing across providers, and usage metering without running any of it.

Strengths:

  • Onboarding is a base-URL change rather than a deployment project.
  • Provider credentials are held centrally, not scattered across services and laptops.
  • Usage metering and billing come with the service instead of being built from logs.
  • Failover and routing logic is someone else's on-call problem.

Costs and risks:

  • A third party is in your request path; review its data handling before sending regulated content.
  • Your routing policy is bounded by what the vendor exposes.
  • Latency includes a network hop you don't control.
  • Availability is the vendor's, not yours — read the actual terms rather than assuming.

Self-hosted: where it wins

You run the gateway yourself — either a general-purpose reverse proxy configured for LLM traffic, or a purpose-built LLM gateway deployed in your own environment. In both cases you own the process.

Strengths:

  • Requests can terminate inside your network; egress to providers can be tightly controlled.
  • Logging, retention, and redaction are entirely your policy.
  • Routing logic is arbitrary — you can encode business rules a vendor would never offer.
  • No dependency on a third party's roadmap or pricing changes.

Costs and risks:

  • You now operate a latency-sensitive, high-availability service.
  • Key management, quota enforcement, and metering must be built or integrated.
  • Upgrades must track upstream API changes across every provider you front.
  • The true cost is engineering time, not infrastructure spend.

A hybrid pattern that fits many organizations

Route public and developer traffic through a managed gateway so provisioning stays self-service, and keep an internal self-hosted gateway for workloads with data-handling constraints. Both expose the same OpenAI-compatible surface, so application code uses one client library and switches on base URL. The cost is two configuration surfaces; the benefit is that compliance exceptions stop blocking the whole platform.

Test before you commit

Compatibility claims should be verified with a short conformance script. Run the same script against every candidate — managed or self-hosted.

from openai import OpenAI

client = OpenAI(base_url="https://your-gateway.example/v1", api_key="YOUR_KEY")

# 1. Model discovery
models = [m.id for m in client.models.list().data]
print("models:", models)

# 2. Non-streaming call + usage object
r = client.chat.completions.create(
    model=models[0],
    messages=[{"role": "user", "content": "Reply with the single word: ok"}],
)
print("usage:", r.usage)

# 3. Streaming: confirm incremental deltas, not one buffered blob
chunks = 0
for chunk in client.chat.completions.create(
    model=models[0],
    messages=[{"role": "user", "content": "Count from 1 to 20."}],
    stream=True,
):
    if chunk.choices and chunk.choices[0].delta.content:
        chunks += 1
print("stream chunks:", chunks)  # expect many, not 1

Add three manual checks the SDK hides from you:

  1. Raw SSE shape. curl -N the streaming endpoint and confirm data: lines and the [DONE] sentinel match the OpenAI format.
  2. Error contract. Send a deliberately invalid model name and confirm the status code and error body shape are what your retry logic expects.
  3. Tool calls. Send one function definition and verify the tool_calls structure round-trips.

Keep the script in your repository. Re-run it after gateway upgrades and whenever you add a provider.

Cost modeling without published numbers

Do not budget from marketing pages. Build a small table instead: for each model you plan to use, record the input and output unit prices, the token split your workload produces, and the gateway fee if any. Multiply by measured traffic from your conformance run, not by guesses. Then add the self-hosted line item that is usually omitted — engineering hours per month for operation and upgrades — and compare totals. For TokenAAS specifically, live models, prices, units, and availability are published on the model plaza and should be read there rather than inferred from this article.

Where TokenAAS fits

TokenAAS is an API gateway that provides access to third-party inference services; it does not host model weights itself. It provides API key management, model routing, usage metering, and billing, and its applicable endpoints support OpenAI-compatible requests. That places it in the managed-routing category described above: you point a standard client at the gateway and keep provider credentials and usage accounting centralized. Teams with hard data-residency constraints should confirm current behavior against the documentation before adopting it for those workloads.

Decision summary

Signal Managed routing Self-hosted
Need to ship this quarter Strong fit Slower start
Regulated data in the request path Review required Strong fit
Multi-provider failover wanted Built in, vendor-bounded You build it
Per-tenant metering needed Usually included You build it
Ops team is small Strong fit Risky
Routing rules are unusual Limited Strong fit

Next step

Write your compatibility list and the conformance script first — both take under an hour and will eliminate most of the debate. Then evaluate one managed option and one self-hosted option against the same script and the same seven criteria, and record the scores in your architecture decision record.

To see the managed side concretely, review the TokenAAS documentation at https://tokenaas.ai/docs, check current models and pricing at https://tokenaas.ai/model-plaza, and run the conformance script against a key created in the playground at https://tokenaas.ai/playground.

Published by TokenAAS.

Editorial verification notes

  • Confirm whether TokenAAS currently supports failover/fallback routing configuration, and describe it accurately or remove the implication if not.
  • Confirm which endpoints beyond chat completions (embeddings, rerank, images, audio) are OpenAI-compatible on TokenAAS.
  • Confirm TokenAAS data retention, logging, and residency practices before the article implies any specific posture; the current text only advises readers to check.
  • Confirm whether TokenAAS charges a separate gateway fee or only passes through provider pricing; the cost section is written to avoid stating either.
  • Verify that https://tokenaas.ai/playground supports creating API keys, as the next-step paragraph suggests.
← Back to resources