OpenAI-Compatible API Quickstart
If your app already uses the OpenAI SDK, the first request usually takes replacing base URL, key and model ID. Compatibility covers the API format, not identical behavior of every model.
Short answer
To make the first request, replacing base URL, key and model ID is usually enough — but format compatibility does not guarantee identical model behavior.
Check the contract before code
Read three things before the first line of code: the model list with exact IDs, the supported routes per model (responses, chat, messages) and the error table. An ID from someone else's article may be renamed or closed to your key — take it from the catalog or from GET /v1/models with your key.
Pin down currency and units in advance: per-1M-token input/output rates, per-generation image price, per-second video price. Mixing units in one estimate is the most common source of bill shock.
- exact IDs from the catalog, not articles
- routes and capabilities per model
- units and currency upfront
Minimal request
Send one short request with a small max_tokens and read three things back: the text, the usage block and the request ID. Success means all three are present and sane — HTTP 200 alone proves the transport, not the billing.
Keep the key in a process environment variable, never in code or the repo. One key per environment from day one: prod, test and experiments split before the first incident, not after.
- one short request, small max_tokens
- check text, usage and request ID
- key in env, one key per environment
Prepare for production load
Set timeouts, retries only for transient errors (429/5xx with backoff), and a spend limit on the key before traffic. Log time, endpoint, model, status, error code and request ID for every call.
Run a 1–5% shadow slice for a day before switching traffic, then compare answers, errors and cost. Rollback is three lines back: old URL, key and model ID.
- timeouts and retries for transient only
- spend limit before traffic
- 1–5% shadow slice, then switch
Sources and related pages
Next step
Russian version: все статьи на русском.