Blog · AI Gateway

OpenAI Compatible API

Keep the client you already know. Change the base URL and key — then call multiple models through one gateway.

Developers search for OpenAI compatible API when they want a familiar request shape — POST /v1/chat/completions, Bearer auth, streaming — without locking every feature to a single vendor SDK.

A multi-model AI gateway that speaks that dialect lets you treat model choice as configuration, not a rewrite.

Minimal curl

curl -X POST "https://api.ai24x.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d "{\"model\":\"flash\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}],\"stream\":false}"

Start with flash for everyday work; switch the model field when you need another capability tier. Same endpoint, same auth.

What “compatible” usually means

  • Chat completions (and often streaming) with familiar JSON fields
  • API key or Bearer token in the header
  • Drop-in with Cursor, Continue, Open WebUI, LobeChat, n8n, and many agents — when they allow a custom base URL

Exact feature parity varies by provider. Treat compatibility as “my existing client works for the paths I use,” then verify streaming, tool calls, or vision if you depend on them.

Why pair it with a gateway

Using a gateway instead of direct provider APIs gives you cost control, automatic model switching, and unified billing. See our gateway comparison for details.

Compatibility alone is not enough in production. You still need somewhere to put multiple keys, automatic switching, and cost visibility. That is the gateway layer: one OpenAI-compatible multi-model API, with BYOK or managed billing.

OpenAI compatible base URL and endpoints

The OpenAI chat completions API reference is the de facto standard. Providers like AI24X implement the same interface so your existing SDK code works with zero changes.

Every OpenAI-compatible API shares the same base URL pattern. You only need to change one string to switch providers:

https://api.ai24x.com/v1          # AI24X Gateway
https://api.openai.com/v1        # OpenAI
https://api.deepseek.com/v1      # DeepSeek
https://dashscope.aliyuncs.com/compatible-mode/v1  # Qwen (DashScope)
https://api.xiaomimimo.com/v1    # MiMo

The endpoint paths are also identical across providers:

  • /v1/chat/completions — chat and streaming
  • /v1/models — list available models
  • /v1/embeddings — text embeddings
  • /v1/audio/transcriptions — speech-to-text (where supported)

Set base_url once in your client and you never touch it again. Most agent frameworks, IDE extensions, and automation tools let you configure this in a settings page rather than code.

Python OpenAI SDK example

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_GATEWAY_KEY",
    base_url="https://api.ai24x.com/v1",
)

resp = client.chat.completions.create(
    model="flash",
    messages=[{"role": "user", "content": "Summarize BYOK in one sentence."}],
)
print(resp.choices[0].message.content)

Swap model when you need a different capability tier. Your application code stays the same; only configuration changes.

OpenAI SDK compatible clients

The OpenAI SDK is the most widely supported format. If a tool or library lets you set a custom base_url, it is almost certainly OpenAI-compatible. Here is what works today:

SDK / FrameworkCompatibleNotes
OpenAI Python SDKYesSet base_url and api_key
OpenAI Node.js SDKYesSame pattern as Python
curl / HTTP clientsYesPOST to /v1/chat/completions
LangChain / LlamaIndexYesOpenAI Chat Model wrapper
Cursor / Continue / CodexYesCustom endpoint in settings
Open WebUI / LobeChatYesOpenAI-compatible provider toggle
n8n / Make / ZapierPartialHTTP nodes work; native app may need custom credential

If your SDK is not listed, test it with a single curl call first. The chat completions format is widely adopted beyond the official OpenAI ecosystem.

Streaming and advanced features

Streaming uses the same endpoint with stream=true. Tool calling and vision depend on the upstream model — test the exact path you ship. If an agent framework lets you set a custom base URL, it is usually compatible with the chat completions path even when vendor-specific SDKs are not.

Clients that work well with a custom base URL

  • Cursor, Continue, Codex-style agents, Open WebUI, LobeChat
  • n8n HTTP nodes, LangChain OpenAI wrappers, many RAG stacks
  • Any script using the official OpenAI SDK with base_url override

For step-by-step IDE setup, see integration guides on integration guides.

OpenAI compatible providers and gateways

See our multi-model API provider comparison for pricing and features across platforms.

Many model providers now offer an OpenAI compatible API endpoint. You can switch between them by changing just the base URL and API key:

  • AI24X Gateway — https://api.ai24x.com/v1 — 26 models, one compatible endpoint
  • OpenAI — https://api.openai.com/v1 — GPT-5, GPT-4o
  • DeepSeek — https://api.deepseek.com/v1 — V4 Flash, V4 Pro
  • Qwen (DashScope) — https://dashscope.aliyuncs.com/compatible-mode/v1 — Qwen Max, Qwen Turbo
  • MiMo — https://api.xiaomimimo.com/v1 — MiMo V2.5
  • Together AI — https://api.together.xyz/v1 — open-source models
  • Fireworks AI — https://api.fireworks.ai/inference/v1 — fast inference

An OpenAI compatible API gateway like AI24X aggregates multiple providers behind a single compatible endpoint. You get automatic switching, cost tracking, and one billing relationship without managing seven separate API keys.

If you already use any OpenAI-compatible SDK, your code works with zero changes — just update the base_url and you are connected to a different provider or a multi-model gateway.

Self-hosted OpenAI compatible server

You can run an OpenAI-compatible server on your own infrastructure. Popular open-source options include vLLM, LocalAI, llama.cpp with its server mode, and Text Generation Inference (TGI). All expose a /v1/chat/completions endpoint that works with any OpenAI SDK client.

When you self-host, you keep full control over data and latency, but you also take on GPU cost, scaling, and maintenance. A common pattern is to use a gateway like AI24X for production traffic and fall back to a local server for development or sensitive data. The same base_url switch moves traffic between them.

For teams that need on-premise compliance, AI24X offers a BYOK (Bring Your Own Key) mode — your provider keys stay in your gateway vault, and the routing layer handles automatic switching and caching without sending data to a third-party upstream.

Errors you will see in production

OpenAI-compatible gateways surface familiar HTTP codes. 401 means fix the gateway API key. 429 often means rate limits on an upstream path — retry with backoff or let automatic switching pick another pool. 502/503 usually means an upstream outage; check status pages before you blame your app. Logging the model name and request id in your app makes these incidents much shorter.

Security habits

Never ship provider secrets in mobile apps or browser bundles. Issue a gateway key with spend limits, rotate it from the console, and keep BYOK provider keys in the gateway vault instead of scattered env files. If you expose a key, revoke it in one place rather than hunting through six repos.

When you are ready to compare plans, start on the pricing page and top up from Account → Billing after your first successful test call.

How to Find the OpenAI Compatible base_url for Any Provider

Every OpenAI-compatible provider exposes a /v1/chat/completions endpoint, but the base URL differs. Here is a quick reference:

  • AI24X — https://api.ai24x.com/v1
  • OpenAI — https://api.openai.com/v1
  • DeepSeek — https://api.deepseek.com/v1
  • Together AI — https://api.together.xyz/v1
  • Fireworks AI — https://api.fireworks.ai/inference/v1
  • Groq — https://api.groq.com/openai/v1

With AI24X, you only need one base URL to access all these providers.

OpenAI Compatible API Gateway vs Direct Provider Endpoint

An OpenAI compatible API gateway provides a single base_url that routes to multiple upstream providers. A direct provider endpoint connects you to one specific model family. The gateway adds automatic model switching, cost tracking, and unified billing.

Testing Your OpenAI Compatible Endpoint

Before going to production, verify with a simple curl test.

If you get a 200 response with valid JSON, your endpoint is working. Common issues are typos in the base URL (missing /v1) or using the wrong API key format.

Next steps

  1. Sign up free
  2. Get an API key on AI Gateway
  3. Set base_url to the platform endpoint and call flash
  4. See plans when you are ready to top up

OpenAI-compatible · multi-model · start free

Start Building Free Get API Key Live Demo →

Related: OpenAI Compatible API Gateway · What is an AI Gateway? · One API for Multiple Models · BYOK AI Gateway · Multi-model API provider