In short:
- Both formats send a list of chat messages and get text back, so simple prompts port easily. The differences show up in system prompts,
max_tokens, tool calling, streaming events and usage fields. - Your tool usually decides the format for you: Claude Code speaks the Anthropic format; Codex CLI, Cursor, Cline and most other agents speak the OpenAI format.
- For your own code, choose the format whose SDK you already use. Choose the native Anthropic format when you need Claude-specific features such as explicit prompt-cache breakpoints.
- On One AI API Key, the same key works with both:
https://api.oneaiapikey.com/v1for OpenAI format,https://api.oneaiapikey.comfor Anthropic format.
The OpenAI Chat Completions format and Anthropic’s Messages API are near-identical for plain chat, since both send a list of chat messages and return text, but they differ in system prompt placement, required max_tokens, tool-call shapes, streaming events and usage fields. “OpenAI-compatible” has become the default promise of almost every LLM provider and gateway. Anthropic’s Messages API is the other format you will meet often, mainly because Claude Code and the Claude Agent SDK use it. This post explains, field by field, where the two actually differ, so you can choose with confidence and debug faster when a request that worked in one format fails in the other.
What does the same request look like in each format?
Here is the same one-question request in each format, using the official Python SDKs pointed at our gateway. Both use the same key and the same model.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.oneaiapikey.com/v1",
api_key=os.environ["LLM_API_KEY"],
)
resp = client.chat.completions.create(
model="claude-sonnet-5",
max_tokens=200,
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain idempotency in one sentence."},
],
)
print(resp.choices[0].message.content)
print(resp.choices[0].finish_reason) # "stop", "length", "tool_calls"
print(resp.usage.prompt_tokens, resp.usage.completion_tokens)import os
import anthropic
client = anthropic.Anthropic(
base_url="https://api.oneaiapikey.com", # no /v1: the SDK adds /v1/messages
api_key=os.environ["LLM_API_KEY"],
)
msg = client.messages.create(
model="claude-sonnet-5",
max_tokens=200, # required in this format
system="You are a concise assistant.", # top-level, not a message
messages=[
{"role": "user", "content": "Explain idempotency in one sentence."},
],
)
print(msg.content[0].text)
print(msg.stop_reason) # "end_turn", "max_tokens", "tool_use"
print(msg.usage.input_tokens, msg.usage.output_tokens)They look nearly identical, and for plain chat they are. Now the details.
How do the two formats differ at a glance?
The two formats differ in endpoint, auth header, system prompt placement, max_tokens, response shape, tool-call arguments, streaming events and prompt caching, as the table shows.
| Topic | OpenAI format | Anthropic format |
|---|---|---|
| Endpoint | POST /v1/chat/completions (also /v1/responses) |
POST /v1/messages |
| Auth header | Authorization: Bearer sk-... |
x-api-key: sk-... (gateways often also accept Bearer) |
| Version header | none | anthropic-version: 2023-06-01 |
| System prompt | a message with role system (or developer) |
top-level system field |
max_tokens |
optional | required |
| Response text | choices[0].message.content |
content array of blocks, e.g. content[0].text |
| Stop signal | finish_reason: stop, length, tool_calls |
stop_reason: end_turn, max_tokens, tool_use, stop_sequence |
| Usage | prompt_tokens, completion_tokens |
input_tokens, output_tokens, plus cache read and write counts |
| Tool call arguments | JSON string in arguments |
JSON object in input |
| Streaming | data: chunks, ends with data: [DONE] |
named events: message_start, content_block_delta, message_stop and others |
| Prompt caching | automatic on supported models | explicit cache_control breakpoints |
How do system prompts differ?
In the OpenAI format, the system prompt is just the first message, with role system (newer OpenAI models also accept developer). In the Anthropic format, it is a separate top-level system field, which can be a string or a list of text blocks. Putting {"role": "system"} inside messages in an Anthropic request is one of the most common porting errors and is rejected.
This matters more than it seems. Because the Anthropic system field can be a list of blocks, you can attach a cache breakpoint to a long system prompt and pay the cached-input rate when it is reused. More on that in our cost estimation guide.
Is a required max_tokens a good thing?
Yes, a required max_tokens is a good thing because it forces you to cap output, the expensive side of every price. The Anthropic format requires max_tokens on every request. The OpenAI format lets you omit it, and the model then writes until it stops naturally or reaches the model’s own output limit.
Setting it explicitly in both formats is a good habit. Output tokens are the expensive side of every model’s price: on our catalogue, output costs several times more than input for every model (for example, Claude Sonnet 5 is $2 per million input tokens and $10 per million output). A sensible cap protects you from a runaway response. When the cap is hit you get finish_reason: "length" or stop_reason: "max_tokens", which your code should treat as “the answer may be truncated”, not as success.
Content: strings vs blocks
OpenAI-format message content is usually a string, or a list of parts when you send images. Anthropic-format content is always conceptually a list of blocks: text, image, tool_use, tool_result, thinking and so on. The response is also a list of blocks, so msg.content[0].text works for simple answers but will break when the first block is a thinking or tool-use block. Robust code loops over blocks and joins the ones with type == "text".
How does tool calling differ?
Both formats support function calling, but the shapes differ enough that a hand-written adapter needs care.
Defining a tool. OpenAI wraps the schema in a function object and calls it parameters. Anthropic puts the name at the top level and calls the schema input_schema:
// OpenAI format
{ "type": "function",
"function": { "name": "get_weather",
"parameters": { "type": "object", "properties": { "city": { "type": "string" } } } } }
// Anthropic format
{ "name": "get_weather",
"input_schema": { "type": "object", "properties": { "city": { "type": "string" } } } }
Receiving a call. OpenAI returns message.tool_calls, each with function.arguments as a JSON-encoded string that you must parse. Anthropic returns a tool_use content block whose input is already an object.
Returning the result. OpenAI expects a new message with role tool and the matching tool_call_id. Anthropic expects a user message containing a tool_result block with the matching tool_use_id.
If you only ever use one SDK, none of this matters. It matters when you switch formats, or when a tool’s “OpenAI-compatible” provider setting is used with a Claude model: the gateway translates between the two, which works well for standard tool calls but may not carry newer, format-specific features.
How does streaming differ?
Both formats stream over Server-Sent Events, but the events differ:
- OpenAI format: every event is an unnamed
data:line holding a chunk object. Text arrives inchoices[0].delta.content. The stream ends with a literaldata: [DONE]. Token usage is only included in the final chunk if you ask for it withstream_options: {"include_usage": true}. - Anthropic format: events are named. You get
message_start, then for each block acontent_block_start, severalcontent_block_deltaevents (text arrives astext_delta), and acontent_block_stop. Thenmessage_delta(carryingstop_reasonand output usage) andmessage_stop. There may bepingevents in between and anerrorevent if something goes wrong mid-stream.
The SDKs hide these differences, so prefer them over hand-written parsers. If you need to write one, our streaming guide has working parsers for both.
How do usage fields and prompt caching differ?
Usage fields are named differently (prompt_tokens vs input_tokens), and the Anthropic format reports cache activity separately as cache_creation_input_tokens and cache_read_input_tokens. In the OpenAI format, cached tokens appear under usage.prompt_tokens_details.cached_tokens on models that support it.
The bigger difference is control. OpenAI-format caching is automatic for long, repeated prompt prefixes on supported models. Anthropic-format caching is opt-in: you mark the end of a reusable prefix with "cache_control": {"type": "ephemeral"}. Explicit control is more work, but it is predictable, which is why agent tools that resend large contexts on every turn use it.
So when does the format actually matter?
1. When your tool only speaks one. This is the most common case and it decides itself:
- Claude Code uses the Anthropic format via
ANTHROPIC_BASE_URL. - Codex CLI, Cursor, Cline and most other editors and agents use the OpenAI format via a custom base URL.
2. When you need a model only one format exposes. On One AI API Key, Claude models are available in both formats; the other families are OpenAI format only:
- OpenAI format (78 models): Claude Opus 5.5, Claude Sonnet 5, Claude Haiku 4.5, GPT-6.1 Sol, GPT-6 Astra, GPT-5.6 Sol, GPT-5.6 Terra, Grok 4.6, Claude Sonnet 5.5, Grok 4.7, DeepSeek V4 Flash, DeepSeek V4 Pro, Kimi K3, GLM 5.3, MiniMax M3, GLM 5.3 Flash, Qwen3.8 27B, Qwen3.8 27B Fast, StepAudio 3 Chat Preview, Step 5, GPT-6 Luna, GPT-6.2 Astra, GPT-6 Luna, GPT-6.2 Astra, DeepSeek V4.1 Flash, MiniMax M3.1 Flash, DeepSeek V4 Flash 0731 Thinking, DeepSeek V4 Flash 0731, DeepSeek V4 Flash 0731, Beam 1.0, Qwen3.8 27B, Qwen3.8-27B Uncensored, GLM 5.3 Flash Uncensored, Nemotron 3 Ultra 550B, GLM 5.3, DeepSeek V4.1 Flash, GLM 5.3 Flash, ERNIE 5.5 Flash Preview, GLM 4.6V Flash, GLM 4.7 Flash, Hy4 Flash, DeepSeek V4.1 Flash Uncensored, GLM 5.3 Uncensored, Kimi K3.1 Pro, DeepSeek V4 Flash, ERNIE 5.5 Flash Preview, ERNIE 5.5 Flash Preview, Gemma 4 31B, Gemma 4 31B Alt, Laguna XS 2.1, LFM 3.1 7B, LongCat 2.5, Laguna XS 2.1, Laguna XS 2.1 Uncensored, Llama 3.3 70B Instruct, Nemotron 3 Nano Omni 30B Reasoning, Nemotron 3.5 Super VL, Nemotron 3.5 Lightning, Nemotron 3 Ultra 550B, Solar Mini 4, Nemotron 3 Ultra 550B Uncensored, Jais 3 Mova 36B, Mistral Large 4, K2 Horizon 375B Uncensored, K2 Horizon 375B, GLM 4.6V Flash, GLM 4.7 Flash, Grok 4.7 Fast, Roleplay Chat, Claude Fable 5.1, Gemini 4 Argon, Muse Wonder, MiMo V2.6 Pro, Step 5 Preview, Claude Haiku 5.5, Muse Spark Open, Mistral Large 4, GPT-6 Luna.
- Anthropic format (4 models): Claude Opus 5.5, Claude Sonnet 5, Claude Haiku 4.5, Claude Sonnet 5.5.
If you want to compare Claude with GPT or Grok in your own app using one code path, the OpenAI format is the practical choice.
3. When you rely on Claude-specific features. Explicit cache breakpoints, extended thinking blocks and other Claude features are first-class in the Messages API. Through a translation layer they may be simplified or missing. If you are building on Claude specifically, use the Anthropic SDK.
4. When you parse responses yourself. Any code that reads raw JSON, logs usage or bills customers per token must handle the field names in the table above. This is where most “it worked yesterday” bugs come from after switching formats.
How do you port code between the two formats?
Porting takes seven steps, from the base URL to streaming. When moving code from one format to the other:
- Change the base URL: OpenAI SDKs need
/v1on the end; Anthropic SDKs must not have it. - Move the system prompt between
messagesand the top-levelsystemfield. - Add
max_tokensif you are moving to the Anthropic format. - Rewrite tool definitions, tool-call parsing (string vs object) and tool-result messages.
- Update the response reading code:
choices[0].message.contentvs looping overcontentblocks. - Update usage and stop-reason handling, including truncation checks.
- Re-test streaming; event names and the end-of-stream signal differ.
Next steps
- Try both formats in two minutes with the quickstart.
- Browse the model catalogue to see which formats each model supports, and the pricing page for how credits work.
- Read about using Claude Code with a custom base URL if Claude Code is your main tool.