Skip to main content
POST
Native Claude Format

Introduction

Claude’s native message API, suitable for native Anthropic clients like Claude Code. This API follows Anthropic’s specification and provides full Claude model capabilities, including Extended Thinking, tool calling, and other advanced features.
If you’re using an OpenAI-compatible client (like OpenAI SDK), we recommend using the /v1/chat/completions endpoint instead.

Authentication

string
required
Bearer Token, e.g., Bearer sk-xxxxxxxxxx

Request Parameters

string
required
Claude model identifier, supported models include:
  • claude-fable-5 - Claude Fable 5 (Latest, most capable)
  • claude-opus-5 - Claude Opus 5 (Latest, complex agentic and coding work)
  • claude-sonnet-5 - Claude Sonnet 5 (Best balance of speed and intelligence)
  • claude-opus-4-8 - Claude Opus 4.8
  • claude-opus-4-7 - Claude Opus 4.7
  • claude-opus-4-6 - Claude Opus 4.6
  • claude-sonnet-4-6 - Claude Sonnet 4.6 (Balanced performance)
  • claude-opus-4-5-20251101 - Claude Opus 4.5
  • claude-haiku-4-5-20251001 - Claude Haiku 4.5 (Fastest)
  • claude-sonnet-4-5-20250929 - Claude Sonnet 4.5
  • claude-sonnet-4-20250514 - Claude Sonnet 4
  • Other Claude series models
array
required
List of conversation messages, each containing role (user/assistant) and content. content can be a string or an array of media content.
number
required
Maximum number of tokens to generate. Must be greater than 0.
string|array
System prompt, can be a string or an array of media content. Used to set the model’s behavior and role.
number
default:"1.0"
Randomness control, 0-1. Higher values make responses more random. Recommended to set to 1.0 when using extended thinking.
number
default:"1.0"
Nucleus sampling parameter, 0-1, controls generation diversity. Recommended to set to 0 when using extended thinking.
number
Top-K sampling parameter, only supported by some models.
boolean
default:"false"
Whether to enable streaming output, returns SSE format data chunks. Recommended to enable when using extended thinking.
array
List of stop sequences. Generation stops when the model produces these sequences.
array
Tool definitions list, supports function tools and web search tools.
object
Tool selection strategy, controls how the model uses tools.
object
Extended thinking configuration, enables Claude’s deep reasoning capability.
The default for display varies by model: Claude Fable 5, Opus 5, Sonnet 5, Opus 4.8 and Opus 4.7 default to "omitted"; Claude Opus 4.6, Sonnet 4.6 and earlier default to "summarized". To show the thinking process to users on the former, you must explicitly set "display": "summarized", otherwise the thinking content comes back empty.
object
Output configuration, used to control the model’s reasoning depth and token spend.
This parameter affects all tokens in the response (reply text, tool calls, and thinking), so it takes effect even without thinking enabled.Level availability varies by model: "xhigh" is only supported on Claude Fable 5, Opus 5, Opus 4.8, Opus 4.7 and Sonnet 5; Claude Sonnet 4.5 and earlier models do not support this parameter at all.
On Claude Opus 5, thinking cannot be disabled at "xhigh" or "max" effort — combining those levels with "thinking": {"type": "disabled"} returns a 400 error. To disable thinking, set effort to "high" or lower.
object
Request metadata for tracking and debugging.
array
MCP (Model Context Protocol) server configuration.
object
Context management configuration, controls how conversation context is handled.

Prompt Caching

Prompt Caching allows you to cache frequently used context content, significantly reducing costs and improving response speed. Supports using the cache_control parameter in system and messages.

Cache Control Parameters

cache_control is not a top-level request parameter and cannot be placed at the root of the request body. It is a field marked on content blocks, and may only appear inside system array elements or content array elements in messages.
Fields:
Correct placement:

Caching Mechanism

  • Cache Breakpoints: Up to 4 content blocks can be marked per request. Each breakpoint writes its own cache entry covering the entire prefix from the beginning up to and including that block
  • Cache Hits: The system compares the prefix at your breakpoint; if there is no match it walks backward one block at a time, with a lookback window of up to 20 content blocks. Cache entries outside that window will not be hit — add an earlier breakpoint in that case
  • Cache Threshold: Content shorter than the model’s minimum cacheable length is not cached (no error is returned; it is simply processed as regular input). See the per-model table below
  • Cache Duration: 5 minutes (default) or 1 hour
  • Cost: Cache reads are 10% of the regular input price (90% cheaper); cache writes carry a premium — 1.25x for the 5-minute cache and 2x for the 1-hour cache

Minimum Cacheable Length by Model

Use Cases

  1. Long Document Analysis: Cache large documents in system, ask multiple questions
  2. Codebase Understanding: Cache code context for multi-turn code analysis
  3. Knowledge Base Q&A: Cache knowledge base content for fast queries
  4. Multi-turn Conversations: Cache conversation history to maintain context coherence

Basic Examples

Advanced Features

System Prompt

System prompts can be set as a string or an array of media content:

Extended Thinking

Claude supports extended thinking, allowing the model to perform deep reasoning. When enabled, the model will think internally before generating the final answer.
  • budget_tokens must be greater than 1024
  • When using extended thinking, it’s recommended to set temperature: 1.0 and top_p: 0
  • Streaming output (stream: true) must be enabled to see the thinking process

Tool Calling

Supports function tools and web search tools:

tool_choice Parameter Details

tool_choice controls how the model uses tools: Example:

Multimodal Input (Images)

Supports including images in messages:

Prompt Caching

Caching frequently used context content can significantly reduce costs and improve response speed.
First Request Response:
Second Request within 5 minutes (different question, same system):
Cache Key Points:
  • Content must meet the model’s minimum cacheable length to trigger caching (512–4,096 tokens depending on the model — see the table above)
  • Without ttl, the cache is valid for 5 minutes
  • With ttl: "1h", the cache is valid for 1 hour
  • Cache reads cost 90% less than regular inputs; cache writes carry a premium (1.25x for 5 minutes, 2x for 1 hour)
  • Up to 4 blocks can be marked per request, and each breakpoint writes its own cache entry
  • Cache is based on exact content match; any changes invalidate the cache
Best Practices:
  • Place unchanging long context (documents, codebases, etc.) in system with caching enabled
  • Use the 1-hour cache (ttl: "1h") for long-term stable content
  • Use the default 5-minute cache (omit ttl) for frequently changing content
  • Cache conversation history in multi-turn dialogues
  • Monitor cache_creation_input_tokens and cache_read_input_tokens to optimize costs

Response Format

Usage fields when using cache:
  • input_tokens: Non-cached input tokens for the current request
  • cache_creation_input_tokens: Tokens cached for the first time (only present in first request)
  • cache_read_input_tokens: Tokens read from cache (present when cache hits)
  • output_tokens: Generated output tokens

Error Handling

The system processes upstream Claude API errors and returns standardized error response formats. Error response example:

Comparison with /v1/chat/completions

  • If you’re using Claude Code or other Anthropic native clients, we recommend using the /v1/messages endpoint
  • If you’re using OpenAI SDK or need OpenAI format compatibility, we recommend using the /v1/chat/completions endpoint
  • Both endpoints have essentially the same functionality, the main difference is in request/response format

Notes

  • max_tokens is a required parameter and must be greater than 0
  • messages array cannot be empty
  • When using extended thinking, budget_tokens must be greater than 1024
  • Extended thinking requires streaming output to see the thinking process
  • Tool calling requires multiple rounds of interaction: first round returns tool call request, second round returns tool execution result
  • Image input requires base64 encoding
  • Using streaming output can improve first token response time and interaction experience
  • Tool calling should have proper timeout and retry mechanisms to avoid blocking model responses
  • Extended thinking can significantly improve reasoning quality for complex problems

Chat Completions (OpenAI Compatible)

View OpenAI compatible chat endpoint documentation

Model List

View all supported model information