← Blog
IntegrationGPT APIClaude API

What Is an OpenAI-Compatible API? How It Works and Where It Differs

(prices in the text follow the live price list)

Short answer

An OpenAI-compatible API is any HTTP API that accepts the same requests as OpenAI's API and answers in the same shape: the same paths (/v1/chat/completions, /v1/models and often /v1/responses), the same JSON fields and the same Authorization: Bearer key header. Because of that, the official OpenAI SDKs and the many tools built on them can talk to it after you change only two things: the base URL and the API key. "Compatible" describes the request format, not the model behind it, and every service supports a different subset of OpenAI's features, so test the parts you rely on.

This guide is published by APIVAI, an OpenAI-compatible gateway for Claude and GPT models. The examples use its address; the same steps work with any compatible service.

What "compatible" covers

Most services copy the core of OpenAI's Chat Completions API:

PartWhat a compatible service accepts or returns
POST /v1/chat/completionsA model ID and a messages array of {"role": ..., "content": ...}
Responsechoices[0].message.content, finish_reason and a usage object (prompt_tokens, completion_tokens, total_tokens)
Streaming"stream": true returns server-sent events, one data: {...} chunk per piece of text, ending with data: [DONE]
Toolstools with JSON-schema parameters; the model answers with tool_calls and you send results back as role: "tool" messages
GET /v1/modelsThe list of model IDs your key can use
AuthAuthorization: Bearer <key>
ErrorsJSON of the form {"error": {"message": ..., "type": ..., "code": ...}}

Newer services also implement POST /v1/responses, OpenAI's newer Responses API, which some tools (Codex CLI, for example) use instead of Chat Completions. Fewer services offer /v1/embeddings, image, audio or file endpoints.

Where services differ: a checklist

Compatibility is never complete. Before you move real traffic, check:

  • Model IDs. Each service names models its own way. Read them from GET /v1/models instead of reusing OpenAI's names.
  • Ignored parameters. Unsupported fields are often dropped without an error. response_format, seed, logprobs, n > 1, presence_penalty and the strict flag on tools are common examples, so a request can "work" while doing less than you think.
  • Parameter ranges. Some models reject values OpenAI accepts (for example a temperature above 1, or setting both temperature and top_p).
  • Endpoints beyond chat. Embeddings, images, audio, files, batch and fine-tuning are frequently missing.
  • Usage in streams. Token counts in streamed responses may need "stream_options": {"include_usage": true}, or may not be sent at all.
  • Errors and limits. The error JSON usually has the right shape, but status codes, messages and rate-limit headers (x-ratelimit-*, retry-after) vary.
  • Tool calling and images. Supported on most large models, but check parallel tool calls, forced tool_choice and image inputs on the exact model you plan to use.

Who offers an OpenAI-compatible API

A few well-documented examples:

ServiceBase URLNotes
Ollama (local)http://localhost:11434/v1Chat Completions, Completions, models, embeddings and a stateless Responses endpoint; the key is required but ignored
vLLM (self-hosted)http://localhost:8000/v1Started with vllm serve <model>; serves Chat Completions, Completions, Responses, embeddings and models
LM Studio (local)http://localhost:1234/v1Models, Chat Completions, Completions, Responses and embeddings
Anthropichttps://api.anthropic.com/v1/Anthropic describes it as a layer for testing and comparing models, not a long-term production path; prompt caching and some fields are only in its native API
Google Geminihttps://generativelanguage.googleapis.com/v1beta/openai/In beta according to Google
API gatewaysThe gateway's own URLPut several providers' models behind one key and one format; APIVAI is one, for Claude and GPT (see also APIVAI vs OpenRouter)

Note the base URLs: most end in /v1, Gemini's does not. Always copy the base URL from the provider's documentation.

How to switch an app to another compatible service

The official OpenAI SDKs read two environment variables, so many apps switch without code changes:

export OPENAI_BASE_URL="https://api.apivai.com/v1"
export OPENAI_API_KEY="your-key"

Or set them in code. Python:

from openai import OpenAI

client = OpenAI(base_url="https://api.apivai.com/v1", api_key="your-key")
resp = client.chat.completions.create(
    model="claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(resp.choices[0].message.content)

Node.js:

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.apivai.com/v1", apiKey: "your-key" });
const resp = await client.chat.completions.create({
  model: "gpt-6-luna",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(resp.choices[0].message.content);

Test with curl before touching your app:

curl https://api.apivai.com/v1/models -H "Authorization: Bearer your-key"

The /v1 rule. The SDKs add /chat/completions to the base URL, so the base URL must already contain the version path (.../v1). A 404 almost always means /v1 is missing or doubled. Tools differ in what they append, so follow each tool's own guide.

Tools that accept a custom OpenAI-compatible URL

Most AI coding and chat tools have a "custom OpenAI-compatible" or "OpenAI base URL" setting. Step-by-step guides:

Calling Claude through the OpenAI format

Claude's own API uses a different format (/v1/messages, x-api-key, a top-level system field). To use Claude from an OpenAI-format tool you need something that translates: Anthropic's own compatibility layer above, or a gateway such as APIVAI, which accepts OpenAI-format requests for Claude model IDs at https://api.apivai.com/v1. Tools that speak Anthropic's format natively, such as Claude Code, can use https://api.apivai.com directly; see the Claude Code setup guide and the API docs.

FAQ

Does "OpenAI-compatible" mean every OpenAI feature works?

No. It means the core request and response format matches. Each service supports a subset: chat and streaming almost always, tools and images on most large models, embeddings, audio, files and batch much less often. Unsupported fields are often ignored silently, so test the features you depend on.

Do I need to change my code?

Usually only the base URL, the key and the model ID. If your code uses OpenAI-only features (for example structured outputs with response_format, or the Assistants API), check that the new service supports them.

Can the same code talk to a local model?

Yes. Ollama, vLLM and LM Studio all run an OpenAI-compatible server, so the same SDK code works with base_url set to http://localhost:11434/v1, http://localhost:8000/v1 or http://localhost:1234/v1. Model IDs and supported features change with the server and the model.

Does the base URL end with /v1?

For most services, yes: the SDK appends /chat/completions, so the base URL must end with the version path. Some providers use a different path (Gemini's ends in /v1beta/openai/), so copy it from their documentation.

How do I find out which models a service supports?

Call GET /v1/models with your key; the IDs in the response are the ones to put in model. Prices and context sizes are on the provider's pricing page; for APIVAI, see the models page.

Ready to start?

Get your API key in 30 seconds. Pay as you go for Claude and GPT.

Get Started