OpenAI vs Anthropic API: 7 Differences That Matter When You Switch

AnyRouter3 min read

TL;DR

Both APIs take a list of messages and return a model reply, but the details differ. Anthropic uses /v1/messages, a top-level system field and a required max_tokens. It also returns content as typed blocks, and it streams named events. Most migration bugs come from tool calls and streaming, not from plain text.

1. Endpoints and authentication

OpenAI Chat Completions uses POST /v1/chat/completions with a bearer token. Anthropic uses POST /v1/messages with an x-api-key header and an anthropic-version header.

bash507 B
# OpenAIcurl https://api.openai.com/v1/chat/completions \  -H "Authorization: Bearer $OPENAI_API_KEY" \  -H "Content-Type: application/json" \  -d '{"model": "your_model", "messages": [{"role": "user", "content": "Hello"}]}' # Anthropiccurl https://api.anthropic.com/v1/messages \  -H "x-api-key: $ANTHROPIC_API_KEY" \  -H "anthropic-version: 2023-06-01" \  -H "Content-Type: application/json" \  -d '{"model": "your_model", "max_tokens": 1024, "messages": [{"role": "user", "content": "Hello"}]}'

2. System prompts

In OpenAI Chat Completions, the system prompt is a message with the role system. In Anthropic Messages, it is a separate top-level system field, and the messages array only holds user and assistant turns.

3. max_tokens is required on Anthropic

Anthropic rejects a request without max_tokens. OpenAI treats the output limit as optional. Code that never set this value needs a sensible default before it can move over.

4. Message content is made of blocks

An OpenAI reply is read from choices[0].message.content, which is normally a string. An Anthropic reply has a content array of typed blocks, so the text is at content[0].text only when the first block is text. If thinking or tool use is enabled, the first block may be something else. Loop over the blocks and filter by type.

The stop reason differs as well: finish_reason on OpenAI, stop_reason on Anthropic, with different values such as length and max_tokens.

5. Tool calls

This is the largest difference in practice.

OpenAI Chat CompletionsAnthropic Messages
Tool schema fieldfunction.parametersinput_schema
Model asks for a tooltool_calls on the assistant messagetool_use content block
ArgumentsJSON stringJSON object
You return the resultMessage with role tooltool_result block in a user message

Arguments are the classic bug. On OpenAI you parse a string, which may be invalid JSON. On Anthropic you already have an object.

6. Streaming

Both use server-sent events, but the shapes are different. OpenAI sends unnamed data: chunks with a delta and ends with data: [DONE]. Anthropic sends named events: message_start, content_block_start, content_block_delta, content_block_stop, message_delta and message_stop.

A parser written for one will not read the other, and tool arguments are especially awkward because they arrive in fragments on both sides.

7. Usage and caching fields

OpenAI reports prompt_tokens and completion_tokens in Chat Completions. Anthropic reports input_tokens and output_tokens, plus separate fields for tokens read from and written to the prompt cache. Check how each provider counts cached tokens before you compare costs, because the input figure does not always mean the same thing.

Do you have to rewrite your code to switch?

Not always. A gateway that speaks both protocols lets you keep the SDK you already use and call models from either side. AnyRouter accepts both formats. When the client and the upstream use the same protocol, the request passes through unchanged. When they differ, the gateway converts the request, including streaming events, in both directions.

Conversion cannot hide everything. Features that only exist on one side have no exact match on the other, so test the parts your app relies on, especially tools and long streams.

Frequently asked questions

Can I use the OpenAI SDK with Claude models?

Yes, through a gateway or compatibility layer that accepts the OpenAI format. Point the SDK at the /v1 address of the gateway and use the model name it lists.

Which API is easier to migrate to?

Plain text is easy in both directions. The effort depends on how much you use tool calls, streaming and provider-only features.

Is the OpenAI Responses API the same as Chat Completions?

No. Responses is a newer, separate endpoint with its own request and event formats. Check which one your SDK or client uses before you change providers.

Next steps

One API for every major model

Use the OpenAI or Anthropic SDK you already have. Failover and billing are handled for you.