API de mensagens da Anthropic
Ligar Qwen modelos usando SDKs da Anthropic
Perguntas frequentes
Após configurar Claude Desktop ou Claude Code, o teste de conexão falha com Model discovery — Gateway /v1/models returned HTTP 404ou o URL da solicitação contém /v1/v1/models. Como faço para corrigir isso?
O recurso de descoberta de modelo de clientes como Claude Desktop e Claude Code anexa automaticamente /v1/models para o URL base configurado. Verifique os dois pontos a seguir:
-
Não termine o URL base com
/v1/: deve terminar às/apps/anthropic(por exemplo, para uso em Cingapurahttps://maas.qwencloudapi.com/apps/anthropic). Se você inserir por engano.../apps/anthropic/v1/, o cliente anexa/v1/modelse produz o caminho duplicado/v1/v1/models, que retorna HTTP 404. -
Adicione modelos manualmente para ignorar a descoberta: o endpoint compatível com Anthropic fornece apenas a API de mensagens (
/v1/messages) e não fornece um endpoint de lista de modelos (/v1/models), portanto, a solicitação de descoberta de modelo também retorna 404. Adicione modelos manualmente (por exemplo,qwen3.7-plus) em Modelos no cliente para ignorar a descoberta automática.
OpenAPI
openapi: 3.1.0
info:
title: Anthropic compatible Messages API
description: |-
Call Qwen models through the Anthropic-compatible Messages API. Supports thinking, tool use, streaming, image/video understanding, and context caching.
Authentication: pass your API key via the `x-api-key` header or the `Authorization: Bearer` header.
version: 1.0.0
servers:
- url: https://maas.qwencloudapi.com
description: Singapore
security:
- ApiKeyAuth: []
paths:
/apps/anthropic/v1/messages:
post:
operationId: anthropicMessages
summary: Create a message
description: Send messages to a Qwen model via the Anthropic-compatible interface and receive generated replies. Supports multi-turn conversation, streaming, thinking, tool use, image/video understanding, and context caching.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicMessagesRequest"
example:
model: qwen3.7-plus
max_tokens: 1024
system: You are a helpful assistant
messages:
- role: user
content: Who are you?
responses:
"200":
description: Successful response
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicMessage"
example:
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
text/event-stream:
schema:
$ref: "#/components/schemas/AnthropicStreamEvent"
example:
type: content_block_delta
index: 1
delta:
type: text_delta
text: Artificial intelligence (AI) is a major branch of computer science...
"400":
description: Invalid request parameters
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicErrorResponse"
example:
type: error
error:
type: invalid_request_error
message: "max_tokens: Field required"
"401":
description: Authentication failed
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicErrorResponse"
example:
type: error
error:
type: authentication_error
message: invalid x-api-key
"429":
description: Rate limit exceeded
content:
application/json:
schema:
$ref: "#/components/schemas/AnthropicErrorResponse"
example:
type: error
error:
type: rate_limit_error
message: Rate limit exceeded
x-codeSamples:
- lang: python
label: Basic call
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://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)
- lang: javascript
label: Basic call
source: |-
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
async function main() {
const message = await anthropic.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" },
});
console.log(message.content[0].text);
}
main().catch(console.error);
- lang: curl
label: Basic call
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 1024,
"system": "You are a helpful assistant",
"messages": [
{
"role": "user",
"content": "Who are you?"
}
],
"thinking": {"type": "disabled"}
}'
- lang: python
label: Streaming
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
stream = client.messages.create(
model="qwen3.7-plus",
max_tokens=1024,
stream=True,
messages=[
{
"role": "user",
"content": "Give a brief introduction to 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)
- lang: javascript
label: Streaming
source: |-
import Anthropic from "@anthropic-ai/sdk";
async function main() {
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
const stream = await anthropic.messages.create({
model: "qwen3.7-plus",
max_tokens: 1024,
stream: true,
messages: [{
role: "user",
content: "Give a brief introduction to artificial intelligence."
}],
thinking: { type: "disabled" },
});
for await (const chunk of stream) {
if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
process.stdout.write(chunk.delta.text);
}
}
}
main().catch(console.error);
- lang: curl
label: Streaming
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
--no-buffer \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 1024,
"stream": true,
"messages": [
{
"role": "user",
"content": "Give a brief introduction to artificial intelligence."
}
],
"thinking": {"type": "disabled"}
}'
- lang: python
label: Thinking
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
stream = client.messages.create(
model="qwen3.7-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)
- lang: javascript
label: Thinking
source: |-
import Anthropic from "@anthropic-ai/sdk";
async function main() {
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
const stream = await anthropic.messages.create({
model: "qwen3.7-plus",
max_tokens: 2048,
stream: true,
thinking: { type: "enabled", budget_tokens: 1024 },
messages: [{
role: "user",
content: "Analyze the future prospects of quantum computing."
}]
});
for await (const chunk of stream) {
if (chunk.type === "content_block_delta") {
if ('thinking' in chunk.delta) {
process.stdout.write(chunk.delta.thinking);
} else if ('text' in chunk.delta) {
process.stdout.write(chunk.delta.text);
}
}
}
}
main().catch(console.error);
- lang: curl
label: Thinking
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 2048,
"stream": true,
"thinking": {
"type": "enabled",
"budget_tokens": 1024
},
"messages": [
{
"role": "user",
"content": "Analyze the future prospects of quantum computing."
}
]
}'
- lang: python
label: Image input
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
stream = client.messages.create(
model="qwen3.7-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 content 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)
- lang: javascript
label: Image input
source: |-
import Anthropic from "@anthropic-ai/sdk";
async function main() {
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
const stream = await anthropic.messages.create({
model: "qwen3.7-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 content of this image." },
],
}],
thinking: { type: "disabled" },
});
for await (const chunk of stream) {
if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
process.stdout.write(chunk.delta.text);
}
}
}
main().catch(console.error);
- lang: curl
label: Image input
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-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 content of this image."
}
]
}
],
"thinking": {"type": "disabled"}
}'
- lang: python
label: Video input
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
stream = client.messages.create(
model="qwen3.7-plus",
max_tokens=1024,
stream=True,
messages=[
{
"role": "user",
"content": [
{
"type": "video",
"source": {
"type": "url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
},
},
{
"type": "text",
"text": "Describe the content of this video."
},
],
}
],
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)
- lang: javascript
label: Video input
source: |-
import Anthropic from "@anthropic-ai/sdk";
async function main() {
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
const stream = await anthropic.messages.create({
model: "qwen3.7-plus",
max_tokens: 1024,
stream: true,
messages: [{
role: "user",
content: [
{
type: "video",
source: {
type: "url",
url: "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4",
},
},
{ type: "text", text: "Describe the content of this video." },
],
}],
thinking: { type: "disabled" },
});
for await (const chunk of stream) {
if (chunk.type === "content_block_delta" && 'text' in chunk.delta) {
process.stdout.write(chunk.delta.text);
}
}
}
main().catch(console.error);
- lang: curl
label: Video input
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 1024,
"stream": true,
"messages": [
{
"role": "user",
"content": [
{
"type": "video",
"source": {
"type": "url",
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251208/zpupby/3e81ef38-98f0-4d55-bbb6-259334ca18d0.mp4"
}
},
{
"type": "text",
"text": "Describe the content of this video."
}
]
}
],
"thinking": {"type": "disabled"}
}'
- lang: python
label: Function Call
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
tools = [
{
"name": "get_weather",
"description": "Get weather information for a specified city",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
}
},
"required": ["city"]
}
}
]
message = client.messages.create(
model="qwen3.7-plus",
max_tokens=1024,
tools=tools,
messages=[
{
"role": "user",
"content": "What's the weather like in Hangzhou today?"
}
]
)
print(message.content)
- lang: javascript
label: Function Call
source: |-
import Anthropic from "@anthropic-ai/sdk";
async function main() {
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
const message = await anthropic.messages.create({
model: "qwen3.7-plus",
max_tokens: 1024,
tools: [
{
name: "get_weather",
description: "Get weather information for a specified city",
input_schema: {
type: "object",
properties: {
city: { type: "string", description: "City name" }
},
required: ["city"],
},
},
],
messages: [{
role: "user",
content: "What's the weather like in Hangzhou today?"
}],
});
console.log(JSON.stringify(message.content, null, 2));
}
main().catch(console.error);
- lang: curl
label: Function Call
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 1024,
"tools": [
{
"name": "get_weather",
"description": "Get weather information for a specified city",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
}
},
"required": ["city"]
}
}
],
"messages": [
{
"role": "user",
"content": "What's the weather like in Hangzhou today?"
}
]
}'
- lang: python
label: Context caching
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
# Simulate code repository content, must reach minimum cacheable length (1024 tokens)
long_text_content = "<Your Code Here>" * 400
def get_completion(user_input):
response = client.messages.create(
# Choose a model that supports explicit caching
model="qwen3.7-plus",
max_tokens=1024,
system=[
{
"type": "text",
"text": long_text_content,
# Adding cache_control to a text block marks a cache breakpoint; can also be placed on content blocks in the messages array
"cache_control": {"type": "ephemeral"},
}
],
messages=[
{"role": "user", "content": user_input},
],
)
return response
# First request: create cache
first = get_completion("What does this code do")
print(f"Cache creation tokens:{first.usage.cache_creation_input_tokens}")
print(f"Cache read tokens:{first.usage.cache_read_input_tokens}")
print("=" * 20)
# Second request: same long content, different question -> cache hit
second = get_completion("How can this code be optimized")
print(f"Cache creation tokens:{second.usage.cache_creation_input_tokens}")
print(f"Cache read tokens:{second.usage.cache_read_input_tokens}")
- lang: javascript
label: Context caching
source: |-
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
// Simulate code repository content, must reach minimum cacheable length (1024 tokens)
const longTextContent = "<Your Code Here>".repeat(400);
async function getCompletion(userInput) {
return client.messages.create({
// Choose a model that supports explicit caching
model: "qwen3.7-plus",
max_tokens: 1024,
system: [
{
type: "text",
text: longTextContent,
// Adding cache_control to a text block marks a cache breakpoint; can also be placed on content blocks in the messages array
cache_control: { type: "ephemeral" },
},
],
messages: [{ role: "user", content: userInput }],
});
}
// First request: create cache
const first = await getCompletion("What does this code do");
console.log(`Cache creation tokens:${first.usage.cache_creation_input_tokens}`);
console.log(`Cache read tokens:${first.usage.cache_read_input_tokens}`);
console.log("=".repeat(20));
// Second request: same long content, different question -> cache hit
const second = await getCompletion("How can this code be optimized");
console.log(`Cache creation tokens:${second.usage.cache_creation_input_tokens}`);
console.log(`Cache read tokens:${second.usage.cache_read_input_tokens}`);
- lang: curl
label: Context caching
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "qwen3.7-plus",
"max_tokens": 1024,
"system": [
{
"type": "text",
"text": "<Place cacheable content here with at least 1024 tokens>",
"cache_control": {"type": "ephemeral"}
}
],
"messages": [
{"role": "user", "content": "What does this code do"}
]
}'
- lang: python
label: Structured outputs
source: |-
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://maas.qwencloudapi.com/apps/anthropic",
)
message = client.messages.create(
model="deepseek-v4-pro",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}
],
extra_body={
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"plan_interest": {"type": "string"},
"demo_requested": {"type": "boolean"}
},
"required": ["name", "email", "plan_interest", "demo_requested"],
"additionalProperties": False
}
}
}
},
)
# deepseek-v4-pro returns a thinking block; find the text content block
text_block = next(block for block in message.content if block.type == "text")
print(text_block.text)
- lang: javascript
label: Structured outputs
source: |-
import Anthropic from "@anthropic-ai/sdk";
const anthropic = new Anthropic({
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://maas.qwencloudapi.com/apps/anthropic",
});
async function main() {
// output_config is a Model Studio platform extension parameter, pass via body
const message = await (anthropic.messages.create as Function)({
model: "deepseek-v4-pro",
max_tokens: 1024,
messages: [{
role: "user",
content: "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}],
output_config: {
format: {
type: "json_schema",
schema: {
type: "object",
properties: {
name: { type: "string" },
email: { type: "string" },
plan_interest: { type: "string" },
demo_requested: { type: "boolean" }
},
required: ["name", "email", "plan_interest", "demo_requested"],
additionalProperties: false
}
}
}
});
// deepseek-v4-pro returns a thinking block; find the text content block
const textBlock = message.content.find(
(block: { type: string }) => block.type === "text"
);
console.log(textBlock?.text);
}
main().catch(console.error);
- lang: curl
label: Structured outputs
source: |-
curl -X POST "https://maas.qwencloudapi.com/apps/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: $DASHSCOPE_API_KEY" \
-d '{
"model": "deepseek-v4-pro",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Extract key info from this email: John Smith (john@example.com) is interested in the Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
}
],
"output_config": {
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
"plan_interest": {"type": "string"},
"demo_requested": {"type": "boolean"}
},
"required": ["name", "email", "plan_interest", "demo_requested"],
"additionalProperties": false
}
}
}
}'
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: x-api-key
description: "QwenCloud API key passed via `x-api-key` header. `Authorization: Bearer` header is also supported."
schemas:
AnthropicMessagesRequest:
type: object
required:
- model
- max_tokens
- messages
properties:
model:
type: string
description: |-
Model name. Supported models:
**Qwen Max**: qwen3.8-max, qwen3.8-max-0902, qwen3.7-max, qwen3.7-max-2026-06-08, qwen3.7-max-2026-05-20, qwen3.7-max, qwen3.7-max, qwen3.7-max, qwen3.7-max
**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 Turbo**: qwen3.5-flash, qwen-turbo-latest
**Qwen Coder**: qwen3.7-plus, qwen3.7-plus, qwen3.7-plus, qwen3-coder-flash
**Qwen VL**: qwen3-vl-plus, qwen3-vl-plus, qwen3-vl-plus, 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**: deepseek-v4.1-flash, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, deepseek-v4-flash-0731, kimi-k3, kimi-k2.7-code, glm-5.3, glm-5.1
max_tokens:
type: integer
description: |-
deepseek-v4.1-flash, deepseek-v4-pro-0813, deepseek-v4-pro, deepseek-v4-flash-0731, deepseek-v4-flash-0731, qwen3.8-max: `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`. `max_tokens` limits the combined length of the reply content and the thinking process. When extended thinking is enabled, `max_tokens` must be greater than `thinking.budget_tokens`.
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: Maximum number of tokens for the reply content. If the generated content exceeds this value, generation stops early and `stop_reason` is `max_tokens`. `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`.
system:
oneOf:
- type: string
- type: array
items:
type: object
required:
- type
- text
properties:
type:
type: string
enum:
- text
description: Always `text`.
text:
type: string
description: System prompt text.
cache_control:
type: object
description: Mark an explicit cache breakpoint on this content block.
properties:
type:
type: string
enum:
- ephemeral
description: Always `ephemeral`.
description: 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`.
messages:
type: array
description: The message array, arranged in conversational order.
items:
type: object
required:
- role
- content
properties:
role:
type: string
enum:
- user
- assistant
- system
description: Message role.
content:
oneOf:
- type: string
- type: array
description: Structured content array supporting text, image, video, tool_use, and tool_result types.
items:
type: object
required:
- type
properties:
type:
type: string
enum:
- text
- image
- video
- tool_use
- tool_result
description: Content block type.
text:
type: string
description: Text content when `type` is `text`.
source:
type: object
description: Data source when `type` is `image` or `video`.
properties:
type:
type: string
enum:
- url
- base64
description: "Value: `url` (public URL) or `base64` (Base64 encoded)."
url:
type: string
description: Public URL. Required when `type` is `url`.
media_type:
type: string
description: MIME type, e.g. `image/jpeg`, `video/mp4`. Required when `type` is `base64`.
data:
type: string
description: Base64 encoded data. Required when `type` is `base64`.
id:
type: string
description: Unique identifier for the tool call when `type` is `tool_use`.
name:
type: string
description: Name of the tool being called when `type` is `tool_use`.
input:
type: object
description: Tool call input parameters when `type` is `tool_use`.
tool_use_id:
type: string
description: The `tool_use` id this result corresponds to when `type` is `tool_result`.
cache_control:
type: object
description: Mark an explicit cache breakpoint on this content block.
properties:
type:
type: string
enum:
- ephemeral
description: Message content. Can be a plain text string or a structured content array.
stream:
type: boolean
default: false
description: Enable streaming output. Default is `false`.
temperature:
type: number
description: |-
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.
top_p:
type: number
description: Probability threshold for nucleus sampling. Both `temperature` and `top_p` control diversity — set only one at a time.
top_k:
type: integer
description: Size of the sampling candidate set during generation.
stop_sequences:
type: array
items:
type: string
description: 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.
thinking:
type: object
description: Extended thinking configuration. When enabled, the model reasons before responding, and the response includes `thinking`-type content blocks. Not all models support thinking mode.
properties:
type:
type: string
enum:
- enabled
- disabled
description: "`enabled` (enable thinking) or `disabled` (disable thinking)."
budget_tokens:
type: integer
deprecated: true
description: "**To be deprecated.** For new integrations, use `output_config.effort`. Maximum tokens for the thinking process. Does not overlap with `max_tokens`: this parameter limits thinking; `max_tokens` limits the final reply. Takes effect when `type` is `enabled`."
tools:
type: array
description: Tool definition array for function calling.
items:
type: object
required:
- name
- input_schema
properties:
name:
type: string
description: Tool name.
description:
type: string
description: Description of the tool's functionality.
input_schema:
type: object
description: JSON Schema definition for the tool's input parameters.
tool_choice:
type: object
description: '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.'
properties:
type:
type: string
enum:
- auto
- any
- none
- tool
description: Strategy type.
name:
type: string
description: When `type` is `tool`, specifies the name of the tool to call.
output_config:
type: object
properties:
effort:
type: string
enum:
- low
- medium
- high
- xhigh
- max
description: |-
Controls the inference intensity of models. The valid values and default values vary by model.
- **glm-5.3**: Default value: `max`. Valid values: `low`, `high`, and `max`. Passing any other value returns an error.
- **glm-5.2, deepseek-v4-pro, and deepseek-v4-flash-0731 (supplied by Alibaba Cloud)**: Default value: `max`. Valid values: `high` and `max`. `low` and `medium` are mapped to `high`, and `xhigh` is mapped to `max`.
- **qwen3.8-max**: Default value: `xhigh`. Valid values: `xhigh`, `medium`, and `low`. `max` and `high` are mapped to `xhigh`.
format:
type: object
description: |-
Structured output configuration. When enabled, the model returns a JSON string. Behavior varies by model:
- **Strict structured outputs**: Available for qwen3.8, qwen3.7, deepseek, and glm series models. The model strictly follows the provided JSON Schema, guaranteeing the same field types and hierarchy.
- **Regular structured outputs**: For all other models, schema field constraints are not enforced — the API automatically falls back to a plain JSON mode (only guaranteeing that the output is a valid JSON string). In this fallback mode, the request must satisfy both of the following: (1) the `output_config` parameter is explicitly provided; (2) the `system` or `messages` content contains the keyword "JSON" (case-insensitive). If the keyword "JSON" is missing, the API throws: `'messages' must contain the word 'json' in some form`.
required:
- type
- schema
properties:
type:
type: string
enum:
- json_schema
description: "Fixed value: `json_schema`."
schema:
type: object
description: JSON Schema object that follows the standard JSON Schema specification. Should include `type` (data type), `properties` (field definitions), `required` (array of required field names), and `additionalProperties` (must be set to `false`).
AnthropicMessage:
type: object
description: Non-streaming response message object.
properties:
id:
type: string
description: Unique message identifier.
type:
type: string
enum:
- message
description: Always `message`.
role:
type: string
enum:
- assistant
description: Always `assistant`.
model:
type: string
description: The model used for generation.
content:
type: array
description: Content array. Element types can be `text`, `thinking` (returned when thinking is enabled), or `tool_use` (tool call).
items:
type: object
properties:
type:
type: string
enum:
- text
- thinking
- tool_use
description: Content block type.
text:
type: string
description: Model-generated text reply when `type` is `text`.
thinking:
type: string
description: The model's reasoning before the final response.
signature:
type: string
description: Signature when `type` is `thinking`. Currently always an empty string.
id:
type: string
description: Unique identifier for the tool call when `type` is `tool_use`.
name:
type: string
description: Name of the tool being called when `type` is `tool_use`.
input:
type: object
description: Tool call input parameters when `type` is `tool_use`.
stop_reason:
type: string
enum:
- end_turn
- max_tokens
- tool_use
description: "Stop reason: `end_turn` (normal completion), `max_tokens` (token limit reached), `tool_use` (tool call)."
stop_sequence:
type:
- string
- "null"
description: Always `null`.
usage:
$ref: "#/components/schemas/AnthropicUsage"
AnthropicStreamEvent:
type: object
description: "Streaming response event. Events are sent in order: `message_start` → `content_block_start` → `content_block_delta` (repeated) → `content_block_stop` → `message_delta` → `message_stop`, with `ping` keepalive events interspersed."
properties:
type:
type: string
enum:
- message_start
- content_block_start
- content_block_delta
- content_block_stop
- message_delta
- message_stop
- ping
description: "Event type. `message_start`: first event in the stream, marks message start with the initial message object. `content_block_start`: sent at the beginning of each content block, marks the index and type. `content_block_delta`: incremental update containing text or thinking fragments. `content_block_stop`: marks content block end. `message_delta`: second-to-last event with `stop_reason` and final `usage`. `message_stop`: last event. `ping`: keepalive heartbeat."
index:
type: integer
description: Content block index (present in `content_block_start`, `content_block_delta`, `content_block_stop` events).
message:
type: object
description: Initial message object in the `message_start` event, with an empty `content` array.
content_block:
type: object
description: Initial content block object in the `content_block_start` event. `type` is `text`, `thinking`, or `tool_use`.
delta:
type: object
description: Delta object in `content_block_delta` events, or stop info in `message_delta` events.
usage:
$ref: "#/components/schemas/AnthropicUsage"
AnthropicUsage:
type: object
description: Token usage statistics. In streaming, the `usage` in the `message_start` event only contains `input_tokens` and `output_tokens`; all 4 fields appear in the `message_delta` event.
properties:
input_tokens:
type: integer
description: Number of input tokens.
output_tokens:
type: integer
description: Number of output tokens.
cache_creation_input_tokens:
type: integer
description: Number of input tokens consumed for cache creation.
cache_read_input_tokens:
type: integer
description: Number of input tokens consumed by cache reads.
AnthropicErrorResponse:
type: object
description: Error response.
properties:
type:
type: string
enum:
- error
description: Always `error`.
error:
type: object
properties:
type:
type: string
description: Error type, e.g. `invalid_request_error`, `authentication_error`, `rate_limit_error`.
message:
type: string
description: Error details.