Skip to main content

Claude OpenAI-Compatible Format

You can call Claude models through the standard OpenAI Chat Completions API format without modifying existing code.
POST /v1/chat/completions

Non-Streaming Request

curl https://crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "messages": [
      {"role": "system", "content": "You are a professional technical consultant."},
      {"role": "user", "content": "Compare the pros and cons of PostgreSQL and MySQL"}
    ],
    "max_tokens": 2048,
    "temperature": 0.7
  }'

Response

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1709123456,
  "model": "claude-sonnet-4-20250514",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is a comparative analysis of PostgreSQL and MySQL:\n\n..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 35,
    "completion_tokens": 420,
    "total_tokens": 455
  }
}

Streaming Request

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://crazyrouter.com/v1"
)

stream = client.chat.completions.create(
    model="claude-sonnet-4-20250514",
    messages=[
        {"role": "user", "content": "Implement a simple LRU cache in Python"}
    ],
    max_tokens=2048,
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="")

Available Claude Models

ModelDescription
claude-sonnet-4-20250514Claude Sonnet 4, balancing capability and speed
claude-opus-4-20250514Claude Opus 4, strongest capability
claude-3.5-sonnetClaude 3.5 Sonnet
claude-3.5-haikuClaude 3.5 Haiku, fast response

Parameter Mapping

Crazyrouter automatically maps OpenAI format parameters to Claude native parameters:
OpenAI ParameterClaude Native ParameterDescription
messages[0].role="system"systemSystem prompt auto-extracted
max_tokensmax_tokensDirect mapping
temperaturetemperatureDirect mapping
top_ptop_pDirect mapping
stopstop_sequencesFormat auto-converted
streamstreamDirect mapping
toolstoolsTool format auto-converted
When using the OpenAI-compatible format, responses are automatically converted to the OpenAI Chat Completion format. If you need access to Claude-specific features (such as Extended Thinking’s thought process), it is recommended to use the native format.