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.

OpenAI Chat Format

fromChatMessages()

Convert OpenAI chat-style messages to OpenResponses input:

toChatMessage()

Convert an OpenResponses response to chat message format:

Supported Message Types

Chat RoleDescription
systemSystem instructions
userUser messages
assistantAssistant responses
developerDeveloper instructions
toolTool response messages

Tool Messages

Tool responses are converted to function call outputs:

Anthropic Claude Format

fromClaudeMessages()

Convert Anthropic Claude-style messages to OpenResponses input:

toClaudeMessage()

Convert an OpenResponses response to Claude message format:

Content Blocks

Claude’s content block format is supported:

Tool Use Blocks

Claude’s tool use format is converted:

Base64 Images

Both URL and base64 images are supported:

Limitations

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.

Migration Examples

From OpenAI SDK

From Anthropic SDK

Building Conversations

Accumulate messages across multiple calls:

Next Steps