Endpoint
Authentication
Requires authentication using Bearer token or x-api-key header. See Authentication.Request Body
The model to use for completion.Example:
"claude-3-5-sonnet-20241022"Array of message objects in the conversation.Each message can have:
role(string):"user","assistant","tool", or"function"content(string | array): Message content or array of content blockstool_call_id(string, optional): For tool role messagesname(string, optional): Message sender nametool_calls(array, optional): Tool calls made by assistant (OpenAI format)function_call(object, optional): Function call (legacy OpenAI format)
- Text:
{"type": "text", "text": "...", "cache_control": {...}} - Image:
{"type": "image", "source": {"type": "base64", "media_type": "...", "data": "..."}} - Tool use:
{"type": "tool_use", "id": "...", "name": "...", "input": {...}} - Tool result:
{"type": "tool_result", "tool_use_id": "...", "content": "...", "is_error": false}
Maximum number of tokens to generate.Example:
1024System prompt to provide context.Can be:Or:
- String: Simple text prompt
- Array: Array of text blocks with cache control
Sampling temperature between 0 and 1.Example:
0.7Available tools for the model to use.Each tool has:
name(string): Tool namedescription(string): Tool descriptioninput_schema(object): JSON schema for tool parameters
Whether to stream the response as Server-Sent Events.Example:
falseResponse
Unique identifier for the message.
Object type, always
"message".Message role, always
"assistant".The model used for completion.
Array of content blocks.Each block can be:
- Text:
{"type": "text", "text": "..."} - Tool use:
{"type": "tool_use", "id": "...", "name": "...", "input": {...}}
Why the model stopped generating.Values:
"end_turn"- Natural stop"max_tokens"- Reached token limit"stop_sequence"- Hit stop sequence"tool_use"- Model wants to use a tool
The stop sequence that ended generation, if any.
Token usage information.Contains:
input_tokens(number): Tokens in the inputoutput_tokens(number): Tokens in the output
Examples
Basic Message
With System Prompt
With Tool Calls
Streaming Response
Multimodal with Images
Response Example
Streaming Events
Whenstream: true, the response is a stream of Server-Sent Events:
message_start
content_block_start
content_block_delta
content_block_stop
message_delta
message_stop
Error Responses
Invalid Request
Missing max_tokens
Format Conversions
The gateway automatically converts between Anthropic and OpenAI formats:Message Roles
tool→tool(OpenAI tool message)function→tool(legacy OpenAI function)assistantwithtool_use→assistantwithtool_callsuserwithtool_result→toolmessages
Content Blocks
- Text blocks → Simple string or text content part
- Image blocks →
image_urlcontent parts with data URLs - Tool use blocks →
tool_callsarray - Tool result blocks →
toolrole messages
System Prompt
- String system →
systemrole message in OpenAI - Array system → Concatenated text in
systemmessage
Notes
- The gateway converts Anthropic format to OpenAI format internally
- All OpenAI-compatible models can be used through this endpoint
- The response is converted back to Anthropic format
- Streaming uses Anthropic’s event format
- Cache control is preserved during conversion
- Tool calls are bidirectionally converted between formats