---
title: "What Is an OpenAI-Compatible API? Verify One with 3 curl Commands"
description: "An OpenAI-compatible API matches OpenAI's request and response format, so tools need only a Base URL and key. Common differences plus 3 curl checks."
url: https://cdnping.org/en/blog/openai-compatible-api-explained
language: en
published: 2026-11-22
category: "AI concepts"
tags: ["OpenAI-compatible API","API","curl","Base URL","beginner guide"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# What Is an OpenAI-Compatible API? Verify One with 3 curl Commands

An OpenAI-compatible API is a service whose HTTP interface follows OpenAI's format for paths, request bodies, and response bodies. A client tool sends a request the way it would to OpenAI, and the service understands it and replies in the same structure. That is why many tools only ask for a "Base URL" and an "API Key" and need nothing else changed.

Keep in mind that "compatible" does not mean "identical." Most services only cover the most commonly used part of the format, and the edge-case fields differ from vendor to vendor. Below, we first spell out what is actually compatible, then give you a way to verify it yourself.

## What exactly is "compatible"?

Take the most common endpoint, chat completions. Compatibility shows up in four places:

1. **Path**: `{Base URL}/chat/completions`. The Base URL usually ends in `/v1`, though some services use a different prefix, so check each vendor's docs.
2. **Authentication**: the request header `Authorization: Bearer <your key>`.
3. **Request body**: JSON, with `model` and `messages` (an array of `role` and `content` pairs) as the core fields. Common optional fields are `temperature`, `max_tokens`, and `stream`.
4. **Response body**: the answer is in `choices[0].message.content` and token usage is in `usage`. Streaming responses come back as SSE chunks starting with `data:` and end with `data: [DONE]`.

As long as these line up, tools such as Cline, Cherry Studio, and the various SDKs work out of the box, because they were written against this format in the first place. This is also why you can swap the backend just by changing the address. For what a Base URL means, see [What is a base URL? One diagram to understand the "endpoint" and why you can change it](/en/blog/what-is-base-url-api-endpoint).

## Why do tools only need an address and a key?

What a tool does internally is simple: it appends a fixed path to the Base URL you entered, puts the key in the request header, and packs the conversation into `messages`. When the address changes, the shape of the request does not, and the other side only has to be able to parse it.

The key proves whose account this request should be billed to, and it is paired with the address. Using service A's key against service B's address usually just returns a 401. For the basics of API keys and how to store them safely, see [What is an API key? 5 things beginners should know before using an AI API](/en/blog/what-is-api-key-beginner).

## Beyond compatibility, where do services usually differ?

The table below lists the kinds of differences beginners most often run into. Whether a feature is supported must be checked in the vendor's official documentation.

| Item | Possible differences |
| --- | --- |
| Model name | `model` must be the vendor's own model name, not an arbitrary OpenAI name |
| `tools` / function calling | Some services do not support it, or differ in parameter details |
| `response_format` (structured output) | Support varies, and some services silently ignore it |
| `usage` in streaming | Whether streaming responses include usage is handled differently by each vendor |
| Image and audio input | Not always supported, and the format may differ |
| Error body | Status codes are usually the same; the error message text may not be |
| Other paths | `/models`, `/embeddings`, and so on are not always all implemented |

One more easy point of confusion: Anthropic's native API is not in the OpenAI format. It uses `/v1/messages`, the headers `x-api-key` and `anthropic-version`, a required `max_tokens`, and a separate top-level field for the system prompt (check the official docs for specifics). So a gateway that supports "both the OpenAI and Anthropic formats" provides two separate entry points, not one format that covers everything.

## How do you verify with curl that an address is really compatible?

Set up two variables. The address and model name in the examples are placeholders; replace them with the values from the service you are testing:

```bash
export BASE_URL="https://example.com/v1"
export API_KEY="sk-your-key"
```

**Step 1: List models to confirm authentication and the address.**

```bash
curl -s -i "$BASE_URL/models" \
  -H "Authorization: Bearer $API_KEY"
```

A 200 with a JSON list means the address and key are basically fine. A 401 is most likely a wrong key, and a 404 is most likely a wrong path or a mistake with `/v1`. Some services do not implement `/models`, though, and in that case a 404 does not mean the chat endpoint is unusable. Just go straight to step 2.

**Step 2: Send one minimal chat request.**

```bash
curl -s "$BASE_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "REPLACE_WITH_MODEL_NAME",
    "messages": [{"role": "user", "content": "Reply with only: ok"}],
    "max_tokens": 16
  }'
```

Check whether the response contains `choices[0].message.content` and `usage`. If both fields are present, the basic format is compatible.

**Step 3: Test streaming.**

```bash
curl -N "$BASE_URL/chat/completions" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "REPLACE_WITH_MODEL_NAME",
    "messages": [{"role": "user", "content": "Count to 3"}],
    "stream": true
  }'
```

You should see multiple `data: {...}` lines appear progressively, with `data: [DONE]` as the last line. If everything arrives in one burst, or the format is not SSE, many tools that depend on streaming will misbehave.

If you also need tool calling or structured output, add one more request each with `tools` or `response_format` and test them separately. Passing all three steps only shows that basic chat is compatible. It does not mean every feature is.

## What if verification fails?

- **401**: the key is wrong or expired, or it belongs to a different vendor than this address.
- **404**: most often the Base URL is missing or has an extra `/v1`, or `/chat/completions` has been appended twice. For how specific tools want it written, see [Cline OpenAI Compatible returns 401 or 404: how to fill in the Base URL](/en/blog/cline-openai-compatible-401-404-errors).
- **400**: the request body contains a field or model name the service does not recognize. Trim it down to just `model` and `messages`, then add fields back one at a time.
- **429 or 5xx**: rate limiting or a server-side problem. To tell whether the problem is on your side or the service's, check cdnping's [API status](/en/status). For how latency differs when reaching each vendor's API directly from mainland China, see [AI API latency in China](/en/learn/ai-api-latency-china).

For long-term monitoring, see [Uptime Kuma API monitoring: a three-level probe setup for OpenAI-compatible endpoints](/en/blog/uptime-kuma-monitor-openai-compatible-api).

## Want a ready-made option that saves effort?

If you just want tools like Claude Code and Codex to work, without dealing with overseas accounts and payments yourself, you can look at AGI Plan. AGI Plan is a commercial partner of cdnping. What follows only states facts it has published:

- Monthly subscription, billed in RMB, no overseas credit card needed;
- It offers both the OpenAI and Anthropic API formats, so tools like Claude Code and Codex only need one endpoint address changed;
- The same quota can be switched between multiple capability groups;
- The site states clearly that it is not an officially authorized channel, and some models are marked "overseas only." See the [models page](https://agiplan.dev/models) for specifics.

For setup and plans, see [agiplan.dev/startup](https://agiplan.dev/startup). Once you have an address and key, you can run the same three curl checks above before connecting a tool.

## What to do next

1. Run steps 1 and 2 above against the address you use now, and confirm it really works from your network.
2. To understand APIs and billing more systematically, read [What is an AI API? A one-page explainer for beginners](/en/blog/what-is-ai-api-beginner).
3. To pick a model or check its current availability, see cdnping's [model monitoring](/en/models).
