OpenAI and Anthropic API protocols explained

  • API protocols
  • OpenAI
  • Anthropic
  • Tool calling

A common point of confusion: you grab an API key from a provider that hosts Claude models, paste it into a general chat app, and it works—then you paste the same key into Claude Code and immediately get a 404 or 401.

The reason is simple: same model name does not mean same wire protocol. Client and server have to speak the same dialect.

The three major protocols

Protocol Endpoint path Typical clients Typical base URL
OpenAI Chat Completions /v1/chat/completions Chat apps, OpenCode, Pi, DeepSeek Harness https://api.example.com/v1
OpenAI Responses /v1/responses Codex CLI, newer OpenAI SDKs https://api.example.com/v1
Anthropic Messages /v1/messages Claude Code, Anthropic SDKs Prefix without /v1 (e.g. https://api.example.com/api)

Four differences that break integrations

1. Authentication headers

OpenAI-style endpoints use Authorization: Bearer YOUR_KEY. Anthropic Messages natively expects x-api-key plus an anthropic-version header (though many third-party gateways accept Bearer tokens too). If both ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN stay set in Claude Code, the two auth variables can conflict or trigger 401 errors.

2. System prompts and message layout

  • Chat Completions: system/developer prompts sit inside the messages array (role: "system" or "developer").
  • Anthropic Messages: system is a separate top-level field rather than a message inside messages (consecutive same-role messages in messages are merged).
  • Responses: passes high-level instructions in instructions and replaces messages with input.

3. Streaming (SSE) event formats

All three stream over Server-Sent Events when stream: true, but with incompatible payloads. Chat Completions emits chunks with choices[].delta.content ending in [DONE]. Anthropic Messages sends typed events (message_start, content_block_delta, message_stop) with separate content-block indices for text, thinking, and tool calls. Responses emits typed events such as response.output_text.delta.

4. Tool calling schemas

Coding agents live on tool calls. In Chat Completions, the model returns tool_calls on the assistant message, and the client sends tool results back in role: "tool" messages tied to tool_call_id. Anthropic puts tool_use and tool_result blocks inside message content arrays. Responses uses function_call and function_call_output items. Plenty of gateways translate plain text chat accurately but break when converting tools or streaming—always test a file edit or tool call, not just "hi".

Using an OpenAI-only provider with Claude Code

  1. Check the provider’s docs for a second endpoint. Many platforms actually expose both an OpenAI path (/v1) and an Anthropic path (/anthropic or /api), even if the landing page only highlights OpenAI.
  2. Run a local protocol translator. Tools like LiteLLM Proxy can translate Anthropic Messages requests to an OpenAI upstream locally on 127.0.0.1—just verify tool calls and streaming survive translation.
  3. Pick a multi-protocol client. Tools like OpenCode, Pi, and DeepSeek Harness speak OpenAI Chat Completions natively without any proxy layer.

See the coding-agent setup guide for working configs and the free AI offers directory for current providers.