Skip to main content

Endpoint

When using the official anthropic SDK, set base_url="https://www.samuraiapi.in/api" — the SDK appends /v1/messages automatically.

Request Parameters

Message Object

Each entry in messages must alternate user / assistant roles. The first message must be user.
Content can be a string or an array of content blocks (for multimodal input):

Basic Example


Response Format

stop_reason Values


Streaming

Set stream: true to receive tokens as they are generated. The SDK handles SSE parsing automatically.

SSE Event Sequence

Samurai AI emits the full Anthropic SSE event sequence:

Multi-turn Conversations

Build multi-turn conversations by appending each exchange to the messages array:

Tool Use (Function Calling)

Give Claude access to external tools. Tools use input_schema (not parameters).

tool_choice Options


Vision (Image Input)

Claude can analyze images passed as base64 or URLs.

Supported Image Formats


Temperature & Sampling


Error Handling

Errors are returned in Anthropic format:

Error Types

Error Handling in Code


Migration from Anthropic Cloud

Change one line — everything else stays the same:
Your Samurai API key starts with sk-samurai- or a custom prefix. Get yours from the dashboard.