OpenAI-Compatible API
What Is an OpenAI-Compatible API?
An OpenAI-compatible API is an HTTP interface that follows the same request and response conventions as OpenAI's official API — most importantly the /chat/completions endpoint. Any client, SDK, or framework built to talk to OpenAI can be redirected to a different provider simply by changing two values: the base URL and the model identifier. No other code changes are required. NVIDIA NIM Free Models Guide
This portability is what makes the pattern so widely adopted. Providers like NVIDIA NIM (NVIDIA Inference Microservices) expose their inference endpoints in this format precisely so developers can drop them into existing stacks with minimal friction. NVIDIA NIM Free Models Guide As of mid-2026, NVIDIA Build hosts over 100 models at https://integrate.api.nvidia.com/v1, all accessible through this same interface. NVIDIA NIM Free API Guide
Why It Matters
Because the request and response structures are identical to OpenAI's, your existing parsing logic, retry handling, and tooling all continue to work unchanged. The response object — including choices[0].message.content — is the same shape regardless of which compatible provider is serving the model. NVIDIA NIM Free Models Guide
This makes the OpenAI-compatible API the foundation for Model Tiering Strategy: you can route different tasks to different providers (premium vs. free) without rewriting your integration layer. NVIDIA NIM Free Models Guide
The Two Things You Change
| Parameter | OpenAI default | NVIDIA NIM example |
|---|---|---|
base_url | https://api.openai.com/v1 | https://integrate.api.nvidia.com/v1 |
model | e.g. gpt-4o | e.g. zhipuai/glm-4 |
api_key | OpenAI key | nvapi-xxxxxxxxxxxxxxxx (generated at build.nvidia.com) |
Everything else — message format, temperature, max_tokens, streaming flags — remains identical. NVIDIA NIM Free Models Guide Streaming, function calling, and tool use are all supported on NVIDIA NIM endpoints. NVIDIA NIM Free API Guide
How the Swap Works in Practice
The application sends the same structured request; only the destination changes. The response shape is identical, so downstream logic never needs to know which provider was used. NVIDIA NIM Free Models Guide
Integration Examples
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key="nvapi-xxxxxxxxxxxxxxxx",
base_url="https://integrate.api.nvidia.com/v1"
)
response = client.chat.completions.create(
model="zhipuai/glm-4",
messages=[
{"role": "user", "content": "Explain this function in one paragraph."}
],
temperature=0.3,
max_tokens=512
)
print(response.choices[0].message.content)NVIDIA NIM Free Models Guide
LangChain
from langchain_openai import ChatOpenAI
nim_llm = ChatOpenAI(
model="zhipuai/glm-4",
api_key="nvapi-xxxxxxxxxxxxxxxx",
base_url="https://integrate.api.nvidia.com/v1",
temperature=0.2
)
response = nim_llm.invoke("Summarize this document in three bullet points.")NVIDIA NIM Free Models Guide
CrewAI
from crewai import LLM
nim_model = LLM(
model="openai/zhipuai/glm-4", # CrewAI prefixes with "openai/"
api_key="nvapi-xxxxxxxxxxxxxxxx",
base_url="https://integrate.api.nvidia.com/v1"
)NVIDIA NIM Free Models Guide
AutoGen
config_list = [
{
"model": "zhipuai/glm-4",
"api_key": "nvapi-xxxxxxxxxxxxxxxx",
"base_url": "https://integrate.api.nvidia.com/v1",
"api_type": "openai"
}
]NVIDIA NIM Free Models Guide
Direct HTTP (curl)
curl https://integrate.api.nvidia.com/v1/chat/completions \
-H "Authorization: Bearer nvapi-xxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "zhipuai/glm-4",
"messages": [{"role": "user", "content": "Hello, what can you do?"}],
"max_tokens": 256
}'NVIDIA NIM Free Models Guide
Compatible Frameworks at a Glance
The OpenAI-compatible interface works with virtually every popular AI framework because they all support a configurable base URL: NVIDIA NIM Free Models Guide
- OpenAI Python SDK — pass
base_urlandapi_keyto the constructor - LangChain / LangGraph — use
ChatOpenAIwith a custombase_url - CrewAI — use the
LLMclass, prefixing the model withopenai/ - AutoGen — pass a config dict with
api_type: "openai" - Any HTTP client — raw
curlorfetchcalls to the endpoint - Direct NIM (no wrapper) — the
openailibrary alone is sufficient; no NVIDIA-specific SDK or custom auth flow is required NVIDIA NIM Free API Guide
For a detailed walkthrough of these framework integrations in the context of NVIDIA NIM, see NVIDIA NIM Framework Integrations.
Role in Model Tiering
The OpenAI-compatible API is the enabling mechanism for Model Tiering Strategy. Because swapping providers requires no structural code changes, you can build an agentic pipeline where:
- High-stakes reasoning and planning — routed to a premium model (Claude, GPT-4o)
- Repetitive classification, summarization, formatting — routed to a free NIM model like GLM-4
- Multilingual processing — routed to a model with bilingual strength
According to the NVIDIA NIM Free Models Guide, this tiering approach can reduce API spend by 40–70% on typical agentic workflows without meaningful quality degradation on the tasks routed to free models. NVIDIA NIM Free Models Guide
Common Pitfalls
| Mistake | Effect | Fix |
|---|---|---|
| Wrong model ID format | model not found error | Copy the exact string from the provider's catalog page |
| Reusing OpenAI-tuned system prompts verbatim | Unexpected output quality | Test and adjust prompts for the target model |
| Ignoring context window differences | Requests fail on long inputs | Verify the target model's token limit before routing |
| No retry logic for rate limits | Batch jobs fail silently | Add exponential backoff; check per-model rate limit docs |
| Hitting the 40 RPM free-tier ceiling | 429 errors in batch workloads | Apply from the account dashboard for an upgrade to ~200 RPM NVIDIA NIM Free API Guide |
NVIDIA NIM Free Models Guide
No-Code Alternative
For teams that want multi-model workflows without managing base URLs and API keys, MindStudio provides a visual workflow builder with 200+ models available out of the box. The same model-tiering logic is built into its workflow structure, eliminating the need to write routing code. NVIDIA NIM Free Models Guide