Skip to content
AI Dev Toolkit.
Esc
  • AI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.Tool
  • LLM API Cost CalculatorEstimate per-request, daily and monthly API costs.Tool
  • AI Model ComparisonCompare prices, context windows and features across models.Tool
  • AI Model Pricing PagesSpecs, real costs and cheaper alternatives for popular models.Tool
  • Context Window CheckerSee whether your text fits each model’s context window.Tool
  • Subscription vs API CalculatorFind out whether a chat plan or the API is cheaper for you.Tool
  • GPU / VRAM CalculatorCheck how much VRAM a local model needs and which GPUs fit.Tool
  • Prompt Caching CalculatorEstimate savings from prompt caching.Tool

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 it works

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 it matters

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

Common confusions

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.

Go deeper

Try it and read more

Related

All 40 terms in the AI glossary