Skip to main content

What is Anthropic Native Format?

Samurai AI supports two API formats side-by-side:
FormatEndpointAuth HeaderSDK
OpenAI-compatiblePOST /v1/chat/completionsAuthorization: Bearer sk-...openai
Anthropic-nativePOST /v1/messagesx-api-key: sk-...anthropic
If you already use the official anthropic Python or TypeScript SDK — or call api.anthropic.com directly — you can switch to Samurai AI by changing one line: the base_url.
# Before (Anthropic Cloud)
from anthropic import Anthropic
client = Anthropic(api_key="sk-ant-...")

# After (Samurai AI — everything else stays the same)
from anthropic import Anthropic
client = Anthropic(
    base_url="https://www.samuraiapi.in/api",
    api_key="YOUR_SAMURAI_KEY"
)
Base URL for Anthropic format: https://www.samuraiapi.in/apiThe Anthropic SDK appends /v1/messages automatically. Do not include it in the base URL.

Supported Claude Models

Model IDContextBest For
claude-opus-4-5200KComplex analysis, research, long documents
claude-sonnet-4-5200KBalanced performance, most tasks
claude-3-5-sonnet-20241022200KCoding, reasoning, instruction-following
claude-3-5-haiku-20241022200KFast, low-latency responses
claude-3-opus-20240229200KDeep reasoning, nuanced writing
You can also use Claude models through the OpenAI-compatible /v1/chat/completions endpoint — Samurai AI converts the format automatically. Use whichever endpoint matches your existing SDK.

Key Differences from OpenAI Format

1. System prompt is a top-level field

# OpenAI format — system message inside messages array
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
]

# Anthropic format — system is a separate top-level parameter
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system="You are a helpful assistant.",   # <-- top-level
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

2. max_tokens is required

The Anthropic API always requires max_tokens. There is no default.

3. Response is a Message object, not a ChatCompletion

// OpenAI response
{
  "object": "chat.completion",
  "choices": [{ "message": { "role": "assistant", "content": "..." } }]
}

// Anthropic response
{
  "type": "message",
  "role": "assistant",
  "content": [{ "type": "text", "text": "..." }]
}

4. Tool definitions use input_schema instead of parameters

# OpenAI format
tools = [{"type": "function", "function": {"name": "get_weather", "parameters": {...}}}]

# Anthropic format
tools = [{"name": "get_weather", "input_schema": {...}}]

5. Auth header is x-api-key

# OpenAI
-H "Authorization: Bearer sk-samurai-..."

# Anthropic
-H "x-api-key: sk-samurai-..."
-H "anthropic-version: 2023-06-01"

Quick Start

from anthropic import Anthropic

client = Anthropic(
    base_url="https://www.samuraiapi.in/api",
    api_key="YOUR_SAMURAI_KEY"
)

message = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    system="You are a helpful assistant.",
    messages=[
        {"role": "user", "content": "Explain the theory of relativity in simple terms."}
    ]
)

print(message.content[0].text)
print(f"Used {message.usage.input_tokens} input + {message.usage.output_tokens} output tokens")

SDK Installation

pip install anthropic

Authentication

Use your Samurai AI API key in the x-api-key header. The same key works for both OpenAI-compatible and Anthropic-native endpoints.
# Get your key from: https://www.samuraiapi.in/dashboard
x-api-key: sk-samurai-YOUR_KEY_HERE
The anthropic-version: 2023-06-01 header is required by the official SDK — Samurai AI accepts it and forwards it as needed.

Rate Limits & Quotas

Anthropic-format requests use the same quotas and rate limits as OpenAI-format requests. Your plan limits apply across both endpoints.
PlanRequests/minNotes
Free10 RPMShared across all endpoints
Starter60 RPM
Pro200 RPM
EnterpriseCustomContact us

Next Steps

Messages API

Full reference for the /v1/messages endpoint — parameters, streaming, tool use, vision.

Function Calling

Tool use with the OpenAI-compatible format (also works with Claude models).