Skip to main content
Toolkit & Framework

Anthropic compatible

Use Anthropic SDKs

Call Qwen models through Anthropic-compatible APIs. To migrate from Anthropic, update these parameters:
  • ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN): Your API key.
  • ANTHROPIC_BASE_URL: https://dashscope-intl.aliyuncs.com/apps/anthropic
  • Model name (model): A supported Qwen model such as qwen3.6-plus. See Supported models.

Quick integration

import anthropic
import os

client = anthropic.Anthropic(
  api_key=os.getenv("ANTHROPIC_API_KEY"),
  base_url=os.getenv("ANTHROPIC_BASE_URL"),
)
# Set ANTHROPIC_API_KEY and ANTHROPIC_BASE_URL. See Compatibility details for parameter support.
message = client.messages.create(
  model="qwen3.6-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)

Supported models

Supported Qwen models:
SeriesModel name (model)
Qwen-Maxqwen3.6-max-preview, qwen3-max, qwen3-max-2026-01-23, qwen3-max-preview
Qwen-Plusqwen3.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-plus-2025-09-11
Qwen-Flashqwen3.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-Turboqwen-turbo, qwen-turbo-latest
Qwen-Coderqwen3-coder-next, qwen3-coder-plus, qwen3-coder-plus-2025-09-23, qwen3-coder-flash
Qwen-VLqwen3-vl-plus, qwen3-vl-flash, qwen-vl-max, qwen-vl-plus
Open-source Qwen modelsqwen3.6-27b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b
For model parameters and billing, see Models.

Configure environment variables

  1. Sign in to Qwen Cloud.
  2. Set these environment variables:
    • ANTHROPIC_BASE_URL: https://dashscope-intl.aliyuncs.com/apps/anthropic.
    • ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN: Your Qwen Cloud API key.
Either ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN works -- set one. This guide uses ANTHROPIC_API_KEY.
  • macOS
  • Windows
  1. Check your default shell type.
echo $SHELL
  1. Set environment variables for your shell:
# Replace YOUR_DASHSCOPE_API_KEY with your Qwen Cloud API Key.
echo 'export ANTHROPIC_BASE_URL="https://dashscope-intl.aliyuncs.com/apps/anthropic"' >> ~/.zshrc
echo 'export ANTHROPIC_API_KEY="YOUR_DASHSCOPE_API_KEY"' >> ~/.zshrc
  1. Apply the environment variables.
source ~/.zshrc
  1. Open a new terminal and verify the environment variables.
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_API_KEY

Call the API

Basic call

  • Python
  • TypeScript
  • curl
  1. Install the Anthropic SDK.
pip install anthropic
  1. Code example
import anthropic
import os

client = anthropic.Anthropic(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/apps/anthropic",
)

message = client.messages.create(
  model="qwen3.6-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)

Streaming

  • Python
  • TypeScript
  • curl
import anthropic
import os

client = anthropic.Anthropic(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
  model="qwen3.6-plus",
  max_tokens=1024,
  stream=True,
  messages=[
    {
      "role": "user",
      "content": "Briefly introduce artificial intelligence."
    }
  ],
  thinking={"type": "disabled"},
)

for chunk in stream:
  if chunk.type == "content_block_delta":
    if hasattr(chunk.delta, 'text'):
      print(chunk.delta.text, end="", flush=True)

Extended thinking

  • Python
  • TypeScript
  • curl
import anthropic
import os

client = anthropic.Anthropic(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
  model="qwen3.6-plus",
  max_tokens=2048,
  stream=True,
  thinking={
    "type": "enabled",
    "budget_tokens": 1024
  },
  messages=[
    {
      "role": "user",
      "content": "Analyze the future prospects of quantum computing."
    }
  ]
)

for chunk in stream:
  if chunk.type == "content_block_delta":
    if hasattr(chunk.delta, 'thinking'):
      print(chunk.delta.thinking, end="", flush=True)
    elif hasattr(chunk.delta, 'text'):
      print(chunk.delta.text, end="", flush=True)

Image understanding

  • Python
  • TypeScript
  • curl
import anthropic
import os

client = anthropic.Anthropic(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/apps/anthropic",
)

stream = client.messages.create(
  model="qwen3.6-plus",
  max_tokens=1024,
  stream=True,
  messages=[
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "url",
            "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250414/mqqmiy/animal_01.jpg",
          },
        },
        {
          "type": "text",
          "text": "Describe the contents of this image."
        },
      ],
    }
  ],
  thinking={"type": "disabled"},
)

for chunk in stream:
  if chunk.type == "content_block_delta":
    if hasattr(chunk.delta, 'text'):
      print(chunk.delta.text, end="", flush=True)

Compatibility details

HTTP header

FieldSupported
x-api-keySupported
Authorization BearerSupported
anthropic-beta/anthropic-versionNot supported

Basic fields

FieldSupportedDescriptionExample
modelSupportedModel name. See Supported models.qwen-plus
max_tokensSupportedMaximum tokens to generate.1024
containerNot supported--
mcp_serversNot supported--
metadataNot supported--
service_tierNot supported--
stop_sequencesSupportedCustom stop sequences for generation.["}"]
streamSupportedStreaming output.True
systemSupportedSystem prompt.You are a helpful assistant
temperatureSupportedControls text diversity.1.0
thinkingSupportedEnables reasoning before responding. Supported by some models only (see Supported models).{"type": "enabled", "budget_tokens": 1024}
top_kSupportedSampling candidate set size.10
top_pSupportedNucleus sampling probability threshold. Controls text diversity.0.1
Set only one of temperature or top_p. Both control text diversity. See Text generation model overview.

Tool fields

tools

FieldSupported
nameSupported
input_schemaSupported
descriptionSupported
cache_controlSupported

tool_choice

ValueSupported
noneSupported
autoSupported
anySupported
toolSupported

Message fields

FieldTypeSubfieldSupportedDescription
contentstring-SupportedText content.
array, type="text"textSupportedText block content.
cache_controlSupportedCache control for this text block.
citationsNot supported-
array, type="image"sourceSupportedImage source (base64 or URL).
array, type="video"-Not supported-
array, type="document"-Not supported-
array, type="search_result"-Not supported-
array, type="thinking"-Not supported-
array, type="redacted_thinking"-Not supported-
array, type="tool_use"idSupportedTool call identifier.
inputSupportedTool parameters.
nameSupportedTool name.
cache_controlSupportedCache control for this tool call.
array, type="tool_result"tool_use_idSupportedCorresponding tool_use ID.
contentSupportedTool result (string or JSON string).
cache_controlSupportedCache control for this tool result.
is_errorNot supported-
array, type="server_tool_use"-Not supported-
array, type="web_search_tool_result"-Not supported-
array, type="code_execution_tool_result"-Not supported-
array, type="mcp_tool_use"-Not supported-
array, type="mcp_tool_result"-Not supported-
array, type="container_upload"-Not supported-