如何用一行設定切換模型供應商:OpenAI 相容端點檢查清單
One line to switch providers: an OpenAI-compatible endpoint checklist
OpenAI 相容端點可讓應用程式沿用同一 SDK、提示詞和程式碼,只改 base URL 切換模型供應商;文章列出遷移前應核對的六項檢查。清單涵蓋錯誤碼、用量欄位、串流、並發、逾時及回滾,並提醒單改設定不能確認數據流、計費行為和支援安排。
I have moved production traffic between model providers four times in three years. The first time took a week and involved a rollback at 11 p.m. The last time took forty minutes, including the coffee.
The difference was not the providers. It was that the fourth migration ran against a written checklist, and the first one ran on optimism.
An OpenAI-compatible endpoint is a service that implements the same request and response shapes as the OpenAI API, so an application can change its provider by changing one configuration value — the base URL — without changing its SDK, prompts or application code.
That is the promise. This article is about verifying whether the promise holds before you send real traffic through it.
The migration itself
Here is the whole change, in a form you can run today. It is deliberately boring, because boring migrations are the ones that finish.
import os
from openai import OpenAI
# Before: pointing at the original provider
# client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
# After: same SDK, same calls, different endpoint
client = OpenAI(
api_key=os.environ["AIOKEYS_KEY"],
base_url="<your-endpoint>/v1",
timeout=60.0,
max_retries=2,
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a terse assistant."},
{"role": "user", "content": "Summarise this support ticket in one sentence."},
],
temperature=0.2,
max_tokens=120,
)
print(response.choices[0].message.content)
print(response.usage.prompt_tokens, response.usage.completion_tokens)
Three things to notice, because they are the difference between a demo and a deployment.
Keys live in the environment, not the file. A migration is also a good moment to check that your key is not in git history.
Timeouts and retries are explicit. Default client timeouts are optimistic. A gateway that queues under load will expose that optimism as hanging requests rather than errors, which is worse.
You read usage, not just the content. The first real signal that something is off is usually the token count, not the prose.
AIO Keys keeps the endpoint OpenAI-compatible so that this file stays the only thing that changes; the coefficient is published as vendor list price × 3.4, which you can compute against the upstream price list before you move anything.
The checklist that matters
Six items. I verify all six, in this order, because each one catches a different class of problem.
| # | Check | What to do | What failure looks like |
|---|---|---|---|
| 1 | Error codes | Send a malformed request, an auth failure and an oversized payload | Custom error shapes, HTML error pages, or 200 responses with an error inside — all break your retry logic |
| 2 | Usage fields | Compare prompt_tokens and completion_tokens for an identical request against the old endpoint |
Missing or zeroed usage; cached-token accounting that changes totals between calls |
| 3 | Streaming | Run one streamed request and confirm incremental chunks plus a final usage block | Whole-response buffering, missing [DONE], or usage only available on the last chunk |
| 4 | Concurrency | Ramp from 1 to your peak request rate; note the first 429 and its headers | Silent queueing instead of rate-limit errors; no retry-after; latency cliff past a threshold |
| 5 | Timeouts | Force a long generation and confirm your client timeout fires before the server drops it | Server closes first, client retries into a second charge |
| 6 | Rollback path | Point at the old URL and confirm the application recovers with no code change | Old URL decommissioned, or a key that stopped working after the switch |
Each of these takes minutes and catches a category of failure that will otherwise appear in production, at the worst time, with a customer watching.
Item 1, in more detail: error shapes are a contract
The single most common breakage is not model quality. It is a gateway returning a 200 with an error object inside, because a proxy in the middle swallowed the upstream status code.
Your retry logic likely keys on HTTP status. If the failure arrives as 200 OK with {"error": ...} in the body, your code treats it as success and your application logs a blank completion. That bug is invisible in testing and loud in production.
Test it deliberately: wrong model name, revoked key, 100k-token prompt. Confirm each produces the status you expect, with a machine-readable body.
Item 4, in more detail: concurrency is where "works" ends
Every endpoint works at one request per second. The interesting question is what happens at your peak.
Watch for two failure modes:
-
429 with
retry-afteris a well-behaved gateway. Your existing backoff handles it. - Latency creep with no errors is a badly-behaved one. Queueing without signalling means your p99 rises and your timeout fires instead of your retry logic, which is a harder failure to diagnose.
Ramp deliberately. The first 429 tells you where the ceiling is; the absence of any 429 past your peak tells you the gateway is absorbing load in a way you cannot see.
Items 2 and 3, briefly: token counts and streaming
These two are usually fine, and that is exactly why they are worth checking — a quiet failure in either one invalidates the cost comparison you are about to make.
Token counts. Send one identical request with a fixed prompt to both endpoints and compare prompt_tokens exactly. They should match for the same model and the same input. A small difference is worth investigating before scale, because a 3% discrepancy on a large bill is a line item nobody approved. If the gateway counts cached input differently, ask how; cached tokens are usually the explanation, and it should be documented rather than discovered.
Streaming. Run one streamed completion and confirm three things: chunks arrive incrementally rather than after a pause, the stream terminates cleanly, and the final chunk carries usage information. A gateway that only reports usage on non-streamed requests leaves your cost monitoring blind on the endpoint type your users actually touch.
Neither check takes more than ten minutes, and both produce an artefact — the usage diff and the stream trace — that is worth keeping next to the migration ticket.
Item 6, in more detail: rollback is the real feature
The reason a one-line migration is safe is not that the change is small. It is that the change is reversible.
Keep the old configuration in an environment variable, not in your head:
# ship with both, switch with one env var
export LLM_BASE_URL="<your-endpoint>/v1"
export LLM_BASE_URL_FALLBACK="https://api.openai.com/v1"
Then rollback is restoring the previous value and restarting. No redeploy, no revert commit, no discussion about whether the old key still works.
This is also the argument that makes a trial meaningful. A pilot whose rollback requires a deployment is not a reversible pilot — and irreversible pilots get approved with a different level of scrutiny, usually after a month of meetings.
There is a quieter benefit too. When rollback is one variable, teams are willing to run the migration earlier, on a smaller slice of traffic, and with a more honest test. Reversibility buys better evidence, not just less risk — and evidence is what a procurement approval actually runs on.
What you cannot verify in one line
A configuration change proves the request shape. It does not prove three other things, and pretending otherwise is how teams get surprised.
Data path. Where inference runs determines whether the scenario is eligible at all if it touches personal data. That question is answered in an assessment, before traffic moves, not during a security review afterwards. AIO Keys fixes the data-flow split in that assessment, with the endpoint identical on both sides.
Billing behaviour. Token counting should match for the same model and input, but confirm it on your own workload for a full cycle before you scale. Discrepancies compound quietly.
Support path. When the endpoint breaks at 2 a.m., you want to reach the party who signed your contract, not a form that promises a response within two business days.
A short pre-flight sequence
If you want to run this today, in order:
- Run the same fifty prompts against old and new endpoints; diff the outputs by eye, then diff the
usagenumbers exactly. - Hammer one endpoint at peak concurrency for ten minutes and watch p99, not the average.
- Break the request on purpose three ways and confirm the error shapes.
- Set both URLs in configuration, deploy once, and switch by variable.
- Keep the old route warm for a week. Then remove it, deliberately.
Forty minutes, if the endpoint behaves. If it does not, you have found out at 2 p.m. instead of 2 a.m.
Every check above can be run before you commit to anything, which is the only reason the migration is worth doing as a checklist rather than as an act of faith. AIO Keys publishes the endpoint address and the coefficient — vendor list price × 3.4 — on the same page, so the sequence above can be executed against it without a sales conversation in between.
The endpoint, coefficient and trial terms referenced here are published at aiokeys.com/tokens and were verified on 24 November 2026. Behaviour described is for OpenAI-compatible endpoints generally; verify the specifics against the provider you are evaluating.
Baonty works on integrations at AIO Keys, which exposes models over an OpenAI-compatible endpoint so that switching providers is a change to the base URL, with a published coefficient of 3.4 against vendor list price.
來源:DEV Community · dev.to