OpenAI Chat Completions to Anthropic Messages
OpenAI Chat Completions to Anthropic Messages
Section titled “OpenAI Chat Completions to Anthropic Messages”This page documents the conversion pair used when a client speaks OpenAI Chat Completions and the selected provider speaks Anthropic Messages.
Inbound
`openai_chat_completions` request payload
Normalize
`src/ingress/` parses Chat messages and tools
Translate request
Chat messages/tools -> Anthropic Messages request
Translate response
Anthropic Message/content blocks -> Chat choices
Outbound
`openai_chat_completions` response or SSE chunks
Request mapping
Section titled “Request mapping”| Chat concept | Anthropic Messages target | Notes |
|---|---|---|
messages[] | messages[] plus normalized system placement | Chat system/developer instructions must not be duplicated as user-visible turns. |
| Assistant text | Assistant content blocks | Preserve ordered visible text. |
tools[] function definitions | tools[] | Preserve name, description, and JSON schema where possible. |
Assistant tool_calls[] | Anthropic tool_use blocks | Chat tool_calls[].index is stream-local; Anthropic content blocks use content-block indices. |
| Tool result messages | Anthropic tool_result blocks | Preserve call id linkage where target protocol can represent it. |
Response mapping
Section titled “Response mapping”| Anthropic concept | Chat target | Notes |
|---|---|---|
| Text content block | choices[0].message.content | Chat has a single assistant message per choice. |
| Tool use block | choices[0].message.tool_calls[] | Assign stable call ids and function names. |
| Thinking/reasoning block | Chat-compatible reasoning extension when supported | Plain Chat has weak reasoning structure; do not mix reasoning into ordinary content unless required. |
stop_reason | finish_reason | Map natural turns, token limits, tool use, and refusals carefully. |
Streaming mapping
Section titled “Streaming mapping”| Anthropic event | Chat SSE expectation |
|---|---|
message_start | Initialize choice and assistant role delta. |
Text content_block_delta | Emit delta.content chunks. |
Tool input_json_delta | Emit delta.tool_calls[].function.arguments chunks keyed by Chat tool index. |
message_delta.stop_reason | Set final finish_reason when terminal state is known. |
message_stop | Emit final chunk and [DONE]. |
Lossy areas
Section titled “Lossy areas”- Chat has no native output item graph.
- Reasoning support is weaker and often extension-based.
- Chat streaming uses
tool_calls[].index; Anthropic streaming uses content blockindex. - Chat
[DONE]is a stream carrier terminator; Anthropicmessage_stopis the semantic terminal event.