Skip to main content

Messages API

POST 

/anthropic/v1/messages

Creates a model response in the Anthropic Messages API format.

Send the conversation history in messages on each request. Use https://api.deepseek.com/anthropic as the Anthropic SDK's base_url; the SDK appends /v1/messages. Direct HTTP requests can also use the compatible path /anthropic/messages.

Authenticate with either x-api-key or Authorization: Bearer. If both are supplied, Authorization takes precedence. See the Anthropic API Guide for model mappings, tool-result replay, and compatibility details.

Compatibility fields container, mcp_servers, service_tier, and top_k are ignored.

Request​

Header Parameters

    anthropic-version string

    The Anthropic SDK sends this header automatically; the service currently ignores it.

    Example: 2023-06-01
    anthropic-beta string

    Include files-api-2025-04-14 when referencing an uploaded image with source.type of file. Otherwise not required for this endpoint. See the Files API Guide.

    Example: files-api-2025-04-14

Body

required

    model stringrequired

    ID of the model to use. Use deepseek-flash or deepseek-v4-pro. Claude model-name aliases are also accepted: claude-opus* maps to deepseek-v4-pro, and other claude* names map to deepseek-flash. See the Anthropic API Guide.

    messages

    object[]

    required

    Minimum items: 1

    The conversation history. At least one message is required. This API is stateless: include the messages needed for the current turn in every request. Use the top-level system field for the system prompt. When continuing after a tool call, pass back the complete assistant content, including thinking and tool-use blocks, followed by the matching tool results. The service may restore omitted thinking content from tool-call IDs; if recovery is required but fails, the request returns 400. Preserve the complete content for reliable replay.

  • Array [

  • oneOf

    role stringrequired

    Possible values: user

    content string | object[]

    required

    oneOf

    string

  • ]

  • system string | object[] | null

    nullable

    The system prompt. Supports only a string, an array of text blocks, or null.

    oneOf

    string

    max_tokens integernullable

    Possible values: >= 1

    The requested output token limit, including thinking tokens. This field is optional at the HTTP API level; the Anthropic SDK requires it. The default and effective limit depend on the model, thinking mode, and reasoning effort. Values above the model limit are capped, and the input plus output must fit within the context window. For certain Claude Code or OpenCode main-agent requests in thinking mode, compatibility handling may raise the effective limit above the requested value, within model and context limits. See Models & Pricing.

    stream booleannullable

    Default value: false

    If true, return named server-sent events (SSE), ending with message_stop. There is no data: [DONE] message. Otherwise, return one complete message object.

    thinking

    object

    nullable

    Controls thinking mode. An explicit thinking.type takes precedence over output_config.effort when selecting the mode. When omitted, effort determines the mode. If neither is set, thinking is enabled by default for deepseek-flash and deepseek-v4-pro.

    type stringrequired

    Possible values: enabled, disabled, adaptive

    enabled turns thinking on; disabled turns it off. adaptive is treated as enabled.

    budget_tokens integernullable

    Possible values: >= 0

    Ignored. This parameter does not set a thinking-token budget.

    output_config

    object

    nullable

    Output configuration. Only effort is supported; output-format settings such as format are ignored.

    effort stringnullable

    Possible values: none, minimal, low, medium, high, xhigh, ultra, max, null

    Controls thinking mode and effort. none disables thinking unless thinking.type explicitly enables it. low, high, and max enable thinking, with high as the default effort. Compatibility aliases: minimal maps to low, medium and xhigh both map to high, and ultra maps to max. An explicit thinking.type determines whether thinking is enabled.

    tools

    object[]

    nullable

    Tools available to the model. Supports client-defined tools and the web search server tool. Tool names must be unique. An empty list is treated as no tools. cache_control is ignored.

  • Array [

  • oneOf

    The application executes this tool after receiving a tool_use block and returns a tool_result block. Omit type for client tools. Providing type selects server-tool parsing; unsupported values such as custom return 422. cache_control is ignored.

    name stringrequired

    Minimum characters: 1

    Maximum characters: 128

    Possible values: Value must match regular expression ^[a-zA-Z0-9_-]+$

    A unique tool name containing letters, digits, underscores, or hyphens, up to 128 characters.

    description stringnullable

    A description of what the tool does and when to use it.

    input_schema

    object

    required

    A valid JSON Schema describing the tool arguments. Its top-level type must be object.

    property name* anynullable
  • ]

  • tool_choice object | null

    nullable

    Controls tool selection. Defaults to auto. any is treated as auto and does not force a tool call. Selecting a named client tool requires non-thinking mode. disable_parallel_tool_use is ignored.

    oneOf

    The model decides whether to call a tool. This is the default.

    type stringrequired

    Possible values: auto

    disable_parallel_tool_use booleannullable

    Ignored; it does not disable parallel tool calls.

    stop_sequences string[]nullable

    Minimum characters per item: 1

    Maximum items: 16

    Up to 16 non-empty strings that stop generation. If a string is matched, stop_reason is stop_sequence and stop_sequence contains the matched string.

    temperature numbernullable

    Possible values: >= 0 and <= 2

    Default value: 1

    Sampling temperature, between 0 and 2. Higher values produce more varied output. In thinking mode the value is fixed at 1, and the supplied value has no effect. We generally recommend changing either this or top_p, rather than both.

    top_p numbernullable

    Possible values: > 0 and <= 1

    Nucleus sampling probability, greater than 0 and at most 1. For deepseek-flash, thinking mode defaults to 1 and clamps values below 0.95 to 0.95; non-thinking mode always uses 1. For deepseek-v4-pro, thinking mode uses 0.95 when tools are enabled and 1 otherwise, ignoring the supplied value; non-thinking mode uses the supplied value, defaulting to 1. Setting tool_choice to {"type":"none"} disables tool calling.

    metadata

    object

    nullable

    Request metadata. Only user_id is supported; other metadata fields are ignored.

    user_id stringnullable

    A custom end-user identifier. We recommend using only ASCII letters, digits, underscores (_), and hyphens (-). The UTF-8 encoded value must not exceed 512 bytes. Do not include personal information. See Rate Limit & Isolation.

Responses​

OK, returns a message object. Its content may include text, thinking, and tool-use blocks.

Schema

    id stringrequired

    Unique identifier for this message.

    type stringrequired

    Possible values: message

    role stringrequired

    Possible values: assistant

    model stringrequired

    The model identifier supplied in the request. When using a Claude-compatible model name, the response retains that name.

    content

    object[]

    required

    Generated content blocks. Preserve the full content when adding this assistant turn to the next request.

  • Array [

  • oneOf

    Each text block must have type: "text", with its content in the text field. On input, additional cache_control and citations fields are ignored.

    type stringrequired

    Possible values: text

    text stringrequired

    The text content.

  • ]

  • stop_reason stringnullablerequired

    Possible values: end_turn, max_tokens, stop_sequence, tool_use, refusal, null

    Why generation stopped: natural completion, output limit, a stop sequence, a client tool call, or content filtering. Null in message_start.

    stop_sequence stringnullablerequired

    The matched stop sequence, or null when no stop sequence was matched.

    usage

    object

    required

    input_tokens integerrequired

    Possible values: >= 0

    Input tokens not served from the context cache. Total input tokens equal input_tokens + cache_read_input_tokens + cache_creation_input_tokens.

    cache_creation_input_tokens integerrequired

    Possible values: 0

    Always 0. Anthropic-style cache creation is not used; context caching is automatic.

    cache_read_input_tokens integerrequired

    Possible values: >= 0

    Input tokens served from the context cache.

    output_tokens integerrequired

    Possible values: >= 0

    Generated output tokens, including thinking tokens when thinking is enabled. In message_delta this is the cumulative count, not an increment.

    service_tier stringrequired

    Possible values: standard

    server_tool_use

    object

    Server-side web search counts, separate from token usage. Present only when at least one web search was attempted; otherwise omitted. Both fields are present when this object is returned. Read the final message's usage for non-streaming responses or the final message_delta.usage for streaming responses. These counts are cumulative, not deltas. See Server tool usage.

    web_search_requests integerrequired

    Possible values: >= 0

    Number of server-side web search attempts, including failed attempts and attempts exceeding max_uses.

    tool_search integerrequired

    Possible values: >= 0

    Number of successful server-side web searches that returned nonempty results. Failed attempts and empty results are not counted. This field can be used as a basis for billing.

Loading...