Skip to content
AI Dev Toolkit.
Esc
  • Loading…

AI glossary · Agents and tools

What is an OpenAI-compatible API?

Also called: OpenAI compatibility, OpenAI-compatible endpoint, base_url

Definition

An OpenAI-compatible API is a model API that accepts OpenAI’s Chat Completions request format, so you can call it with the official OpenAI SDK by changing only the base URL, the API key and the model name.

Explained

How does an OpenAI-compatible API work?

Compatibility covers the request shape, not the model: features such as tool calling and structured outputs can still behave differently from one provider to the next. Our guide to the cheapest LLM APIs compares what the same request costs across them.

OpenAI’s Chat Completions shape, a messages list in and a choices array out, became the format other providers copy. Groq, OpenRouter, Google’s Gemini API, Anthropic and local servers such as Ollama all accept it, and the OpenAI SDK sends the same request to whatever base_url you set.

Compatible means the core works, not everything. Groq returns a 400 error for logprobs, logit_bias, top_logprobs and messages[].name, and turns temperature: 0 into 1e-8. Ollama doesn’t support tool_choice. Anthropic’s layer ignores response_format and the strict flag on tools, has no prompt caching, and is meant for testing and comparing models rather than long-term production use in most cases. Gemini’s is in beta and takes Gemini-only options through extra_body.

Example

Five base URLs, checked today

We sent the same Chat Completions request through the OpenAI Python SDK (3.28.0) to the four hosted URLs below with a deliberately invalid key. Each answered with an authentication error, which confirms the URL and path. Groq, OpenRouter and Anthropic replied 401 with an error object; Gemini replied 400 with its error object inside a list, so even error handling can differ.

Switching providers is then a three-line change: the base URL, the key and the model name, as in the OpenRouter example below.

OpenAI-compatible base URLs from each provider’s docs
ProviderBase URLWorth knowing
Groqhttps://api.groq.com/openai/v1400 error on logprobs, logit_bias, top_logprobs
OpenRouterhttps://openrouter.ai/api/v1Model IDs look like provider/model
Google Geminihttps://generativelanguage.googleapis.com/v1beta/openai/Beta; Gemini options via extra_body
Anthropichttps://api.anthropic.com/v1/For testing; response_format ignored
Ollama (local)http://localhost:11434/v1/Key required but ignored

Base URLs from each provider’s compatibility docs, 2026-10-11. Ollama runs on your machine and was not probed.

Python, OpenAI SDK pointed at OpenRouter
import os

from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)

response = client.chat.completions.create(
    model="google/gemini-3.8-flash",
    messages=[
        {"role": "system", "content": "Answer in one sentence."},
        {"role": "user", "content": "What is an OpenAI-compatible API?"},
    ],
)
print(response.choices[0].message.content)

Cost and quality

Why does OpenAI compatibility matter for switching providers?

One client library lets you compare models and prices across providers, or move to a cheaper one, without rewriting your code. Keep each provider’s API key in its own environment variable, never in the code.

Test the features you rely on, such as function calling, JSON output, streaming and usage fields, on each provider. Unsupported fields are often ignored silently rather than rejected, and provider-only features, such as Anthropic’s prompt caching, need the native API.

Don’t mix up

Does “OpenAI-compatible” mean every feature works the same?

Chat Completions vs the Responses API
“OpenAI-compatible” almost always means the Chat Completions endpoint. Support for OpenAI’s newer Responses API varies: Ollama, for example, offers a non-stateful /v1/responses.
Same format vs same model
A compatible API copies the request format, not the model. Prompts tuned for one model may need rework on another, as Anthropic’s compatibility docs point out.

FAQ

Questions people ask

Is there a free OpenAI-compatible API?

Yes, with limits. Google’s Gemini API has a free tier and an OpenAI-compatible endpoint, and Groq has a free plan with lower rate limits. Local servers such as Ollama expose an OpenAI-compatible endpoint on your own machine at no cost. Free tiers can treat your data differently: Google says free-tier content may be used to improve its products. Our Gemini and Groq key guides show how to sign up.

Which providers offer an OpenAI-compatible API?

Many do, including Groq, OpenRouter, Google Gemini and Anthropic, plus local and self-hosted servers such as Ollama and vLLM. Anthropic says its layer is mainly for testing and comparing models and recommends its native API for the full feature set. Each provider documents its own base URL and which parameters it ignores. The OpenRouter key guide covers one key for many models.

How do you use an OpenAI-compatible API in Python?

Install the openai package, then create the client with the provider’s endpoint and key: OpenAI(base_url=..., api_key=...). Call client.chat.completions.create with the provider’s own model name. Keep the key in an environment variable, not in your code, and read the provider’s compatibility notes for parameters it ignores or rejects before relying on them.

Go deeper

Try it and read more

Related

All 41 terms in the AI glossary

Keep exploring