Message Formats
The OpenRouter SDK provides helper functions to convert between popular message formats. This makes it easy to migrate existing code or integrate with different APIs.
Convert OpenAI chat-style messages to OpenResponses input:
Convert an OpenResponses response to chat message format:
Tool responses are converted to function call outputs:
Convert Anthropic Claude-style messages to OpenResponses input:
Convert an OpenResponses response to Claude message format:
Claude’s content block format is supported:
Claude’s tool use format is converted:
Both URL and base64 images are supported:
Some Claude features are not preserved in conversion.
e.g. is_error flag on tool_result blocks
These features are Claude-specific and not supported by OpenRouter.
Accumulate messages across multiple calls: