Skip to main content
Chat Models

Anthropic Messages API

Call Qwen models using Anthropic SDKs

POST
https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic/v1/messages
import anthropic
import os

client = anthropic.Anthropic(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
    # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
    base_url="https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic",
)

message = client.messages.create(
    model="qwen3.7-plus",
    max_tokens=1024,
    system="You are a helpful assistant",
    messages=[
        {
            "role": "user",
            "content": "Who are you?"
        }
    ],
    thinking={"type": "disabled"},
)

print(message.content[0].text)
{
  "id": "msg_e2898f19-fc0e-4cb3-bd9b-5b7dc4ea3bc9",
  "type": "message",
  "role": "assistant",
  "model": "qwen3.7-plus",
  "content": [
    {
      "type": "thinking",
      "thinking": "Let me analyze this question...",
      "signature": ""
    },
    {
      "type": "text",
      "text": "Hello! I am Qwen..."
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 22,
    "output_tokens": 223,
    "cache_creation_input_tokens": 0,
    "cache_read_input_tokens": 0
  }
}

FAQ

After configuring Claude Desktop or Claude Code, the connection test fails with Model discovery — Gateway /v1/models returned HTTP 404, or the request URL contains /v1/v1/models. How do I fix it? The model discovery feature of clients such as Claude Desktop and Claude Code automatically appends /v1/models to the configured base URL. Check the following two points:
  • Do not end the base URL with /v1/: it should end at /apps/anthropic (for example, for Singapore use https://ap-southeast-1.maas.qwencloudapi.com/apps/anthropic). If you mistakenly enter .../apps/anthropic/v1/, the client appends /v1/models and produces the duplicated path /v1/v1/models, which returns HTTP 404.
  • Add models manually to skip discovery: the Anthropic-compatible endpoint provides only the Messages API (/v1/messages) and does not provide a model list endpoint (/v1/models), so the model discovery request returns 404 as well. Manually add models (for example, qwen3.7-plus) under Models in the client to skip automatic discovery.

Authorizations

string
header
required

QwenCloud API key passed via x-api-key header. Authorization: Bearer header is also supported.

Body

application/json
string
required

Model name. Supported models:

Qwen Max: qwen4-max, qwen3.8-max, qwen3.8-max-0902, qwen3.7-max, qwen3.7-max-2026-06-08, qwen3.7-max-2026-05-20

Qwen Plus: qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen-plus, qwen-plus-latest

Qwen Flash: qwen3.8-flash, qwen3.7-flash, qwen3.7-flash-2026-07-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen-flash, qwen-flash-2025-07-28

Qwen Coder: qwen3.7-plus, qwen3-coder-flash

Qwen VL: qwen3-vl-plus

Qwen Open-source: qwen3.6-27b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b, qwen3.8-2.4t-a95b, qwen3.8-27b

Third-party models (Alibaba Cloud-supplied): deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, kimi-k3.1-pro, kimi-k3, kimi-k2.7-code, kimi-k2.5, glm-5.3, glm-5.2, glm-5.1, glm-5, MiniMax-M2.5

These are third-party models supplied by Alibaba Cloud and can be called directly through this API. Models whose IDs contain / are third-party direct-supply models; activate the corresponding provider's service in the model marketplace first, as they are not included in the list above.

Model availability varies by region; see Regions and endpoints before selecting a model and endpoint. glm-5 and MiniMax-M2.5 are available only in China North 2 (Beijing). Use the cn-beijing endpoint to call them.

integer
required

The maximum number of tokens for the model's reply. Generation stops early when the model output exceeds this value, and stop_reason is max_tokens.

  • qwen4-max, deepseek-v4.1-flash, deepseek-v4.1-flash-1017, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, qwen3.8-max, qwen3.8-flash: max_tokens is the maximum total token count for both the reply content and the chain-of-thought content, limiting the combined length of the reply and the thinking process. When extended thinking is enabled, max_tokens must be greater than thinking.budget_tokens. For qwen4-max, the maximum is 262144 in thinking mode and 131072 in non-thinking mode; omitted values use the current mode’s maximum.
  • glm-5.3: max_tokens is the maximum total token count for both the reply content and the chain-of-thought content. Generation stops early when the model output exceeds this value, and stop_reason is max_tokens. glm-5.3 ignores the thinking.budget_tokens parameter.
  • glm-5.2: When the thinking.budget_tokens parameter is not passed, max_tokens is the maximum total token count for both the reply content and the chain-of-thought content. Generation stops early when the model output exceeds this value, and stop_reason is max_tokens. When the thinking.budget_tokens parameter is passed, max_tokens is only the maximum number of tokens for the reply content, and the thinking tokens are controlled separately by thinking.budget_tokens.
  • Other models: max_tokens does not limit the length of the thinking process. When extended thinking is enabled, the thinking tokens are controlled separately by thinking.budget_tokens.
object[]
required

The message array, arranged in conversational order.

string

System prompt to set the model's role or behavior. Passed as a top-level parameter; the messages array does not accept the system role. A string is equivalent to a single type="text" content block. To use context caching, pass an array of content blocks with cache_control.

boolean
defaultfalse

Enable streaming output. Default is false.

number

Controls diversity of generated text, range [0, 2). Higher values produce more random output. This range differs from Anthropic's native [0.0, 1.0] — verify this parameter when migrating from Anthropic.

qwen3.8-max: Defaults to 0.6 in thinking mode. Values below 0.6 are automatically adjusted to 0.6.

number

Probability threshold for nucleus sampling. Both temperature and top_p control diversity — set only one at a time.

integer

Size of the sampling candidate set during generation.

string[]

Text sequences that stop generation. The model stops before outputting the sequence. After a match, the stop_reason in the response is stop_sequence, and the matched sequence is returned in the response's stop_sequence field.

object

Extended thinking configuration. When enabled, the model reasons before responding, and the response includes thinking-type content blocks. Not all models support thinking mode.

object[]

Tool definition array. Supports custom tools (function calling), the server-side web search tool, and the web scraping tool.

qwen4-max supports web_search, web_fetch, and Beijing-region PDF understanding with pdf_basic_chain. See the corresponding guides for wire formats and constraints.

Custom tool (function calling).

  • Option 1
  • Option 2
  • Option 3
object

Tool choice strategy. {"type": "auto"}: model decides whether to call tools (default). {"type": "any"}: force calling any tool. {"type": "none"}: disable tool calling. {"type": "tool", "name": "tool_name"}: force calling a specific tool.

object
object

qwen4-max only. Top-level automatic caching or a manual content-block breakpoint. Prompt Cache.

Response

200-application/json
string

Unique message identifier.

enum<string>

Always message.

message
enum<string>

Always assistant.

assistant
string

The model used for generation.

object[]

Content array. Element types can be text, thinking (returned when thinking is enabled), tool_use (tool call), server_tool_use (server-side tool call), or web_search_tool_result (web search results). Also includes web_fetch_tool_result (fetched page result).

enum<string>

Stop reason: end_turn (normal completion), max_tokens (token limit reached), tool_use (tool call).

end_turn,max_tokens,tool_use
string | null

Always null.

object

Token usage statistics. In streaming, the usage in the message_start event only contains input_tokens and output_tokens; the full fields (including cache_creation_input_tokens, cache_read_input_tokens, and server_tool_use) appear in the message_delta event.