Qwen Models (OpenAI Compatible)
Invoke the Qwen series of models through a Chat API compatible with the OpenAI format, supporting text conversation, multimodal input, streaming output, tool calling, web search, and more.
Endpoint
http
POST /v1/chat/completionsAuthentication
| Method | Description |
|---|---|
| Bearer Token | Pass Authorization: Bearer <API Key> in the request header to verify your account. |
Request Headers
| Parameter | Type | Required | Description |
|---|---|---|---|
Content-Type | string | Yes | The media type of the request body; set it to application/json |
Authorization | string | Yes | The Bearer API Key used to verify your account |
Request Body
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | - | Model name; supported models include the Qwen large language models, etc. |
messages | array | Yes | - | The context passed to the model, arranged in conversation order |
stream | boolean | No | false | Whether to reply in streaming output mode |
stream_options | object | No | - | Streaming output configuration; takes effect only when stream is true |
temperature | float | No | 0.7 | Sampling temperature, controls generation diversity; range [0, 2) |
top_p | float | No | 0.8 | Nucleus sampling probability threshold; range (0, 1.0] |
top_k | integer | No | 20 | Number of candidate tokens for sampling; not a standard OpenAI parameter, passed via extra_body when using the SDK |
max_tokens | integer | No | - | Maximum length of the model's answer (excluding chain of thought); about to be deprecated, use max_completion_tokens |
max_completion_tokens | integer | No | - | Maximum length of the model output (including chain of thought and the answer) |
response_format | object | No | {"type":"text"} | Format of the returned content; can be text or json_object |
tools | array | No | - | Array of tool objects, for the model to call in Function Calling |
tool_choice | string/object | No | auto | Tool selection strategy; can be auto, none, or a specified tool |
parallel_tool_calls | boolean | No | false | Whether to enable parallel tool calls |
enable_search | boolean | No | false | Whether to enable web search; not a standard OpenAI parameter, passed via extra_body when using the SDK |
search_options | object | No | - | Web search strategy |
enable_thinking | boolean | No | - | Whether to enable thinking mode, applicable to mixed thinking models; not a standard OpenAI parameter |
thinking_budget | integer | No | - | Maximum number of tokens for the thinking process; not a standard OpenAI parameter |
reasoning_effort | string | No | - | Reasoning effort; can be low/medium/high/max/xhigh; not a standard OpenAI parameter |
seed | integer | No | 1234 | Random seed for reproducible results; range [0, 2^31-1] |
stop | string/array | No | - | Stop strings; generation terminates when the specified string appears in the output |
n | integer | No | 1 | Number of responses to generate; range 1-4 |
logprobs | boolean | No | false | Whether to return the log probabilities of the output tokens |
top_logprobs | integer | No | 0 | Number of candidate tokens to return; range [0, 5] |
repetition_penalty | float | No | 1.05 | Repetition penalty; any value greater than 0; not a standard OpenAI parameter |
presence_penalty | float | No | 0.0 | Content repetition control; range [-2.0, 2.0] |
messages Message Types
| Message Type | role | Description |
|---|---|---|
| System Message | system | System message that sets the model's role, tone, and task constraints; usually placed first |
| User Message | user | User message that passes the question or context |
| Assistant Message | assistant | Model reply, used to pass back multi-turn conversation context |
| Tool Message | tool | Tool output information |
Setting a System Message is not recommended for the QwQ model, and setting a System Message for the QVQ model has no effect.
stream_options Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
include_usage | boolean | No | false | Whether to include token usage information in the last data chunk |
search_options Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
forced_search | boolean | false | Whether to force web search |
search_strategy | string | turbo | Search strategy; can be turbo/max/agent/agent_max |
enable_search_extension | boolean | false | Whether to enable vertical-domain search |
Model Notes
Supported Models
qwen-plus,qwen-max,qwen-turbo,qwen-flash- The
qwen3.5,qwen3.6,qwen3.7series
For specific model names and pricing, see the model marketplace on the platform console.
Request Examples
Text Input
bash
curl -X POST 'https://neolink.com/api/v1/chat/completions' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-plus",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"}
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
completion = client.chat.completions.create(
model="qwen-plus",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"},
],
)
print(completion.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen-plus",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Who are you?" },
],
});
console.log(JSON.stringify(completion));
}
main();Streaming Output
bash
curl --location 'https://neolink.com/api/v1/chat/completions' \
--header 'Authorization: Bearer <API Key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen-plus",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"}
],
"stream": true,
"stream_options": {"include_usage": true}
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
completion = client.chat.completions.create(
model="qwen-plus",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who are you?"},
],
stream=True,
stream_options={"include_usage": True},
)
for chunk in completion:
print(chunk.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen-plus",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Who are you?" },
],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of completion) {
console.log(JSON.stringify(chunk));
}
}
main();Image Input
bash
curl -X POST 'https://neolink.com/api/v1/chat/completions' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-vl-plus",
"messages": [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
{"type": "text", "text": "What is this"}
]
}
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
completion = client.chat.completions.create(
model="qwen-vl-plus",
messages=[{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"}},
{"type": "text", "text": "What is this"},
],
}],
)
print(completion.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const response = await openai.chat.completions.create({
model: "qwen-vl-max",
messages: [{
role: "user",
content: [
{ type: "image_url", image_url: { url: "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg" } },
{ type: "text", text: "What is this?" },
],
}],
});
console.log(JSON.stringify(response));
}
main();Video Input (List of Images)
bash
curl -X POST 'https://neolink.com/api/v1/chat/completions' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-vl-max",
"messages": [
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg"
]
},
{"type": "text", "text": "Describe the specific process in this video"}
]
}
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
completion = client.chat.completions.create(
model="qwen-vl-max",
messages=[{
"role": "user",
"content": [
{
"type": "video",
"video": [
"https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
],
},
{"type": "text", "text": "Describe the specific process in this video"},
],
}],
)
print(completion.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const response = await openai.chat.completions.create({
model: "qwen-vl-max",
messages: [{
role: "user",
content: [
{
type: "video",
video: [
"https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
],
},
{ type: "text", text: "Describe the specific process in this video" },
],
}],
});
console.log(JSON.stringify(response));
}
main();Tool Calling (Function Calling)
bash
curl -X POST 'https://neolink.com/api/v1/chat/completions' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-plus",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "How is the weather in Hangzhou"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "Useful when you want to know the current time.",
"parameters": {}
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Useful when you want to query the weather for a specified city.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city or district, e.g. Beijing, Hangzhou, Yuhang District, etc."
}
},
"required": ["location"]
}
}
}
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
tools = [
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "Useful when you want to know the current time.",
"parameters": {},
}
},
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Useful when you want to query the weather for a specified city.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city or district, e.g. Beijing, Hangzhou, Yuhang District, etc.",
}
},
"required": ["location"],
},
}
},
]
messages = [{"role": "user", "content": "How is the weather in Hangzhou"}]
completion = client.chat.completions.create(
model="qwen-plus",
messages=messages,
tools=tools,
)
print(completion.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
const tools = [
{
type: "function",
function: {
name: "get_current_time",
description: "Useful when you want to know the current time.",
parameters: {},
},
},
{
type: "function",
function: {
name: "get_current_weather",
description: "Useful when you want to query the weather for a specified city.",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city or district, e.g. Beijing, Hangzhou, Yuhang District, etc.",
},
},
required: ["location"],
},
},
},
];
async function main() {
const response = await openai.chat.completions.create({
model: "qwen-plus",
messages: [{ role: "user", content: "How is the weather in Hangzhou" }],
tools: tools,
});
console.log(JSON.stringify(response));
}
main();Web Search
bash
curl -X POST 'https://neolink.com/api/v1/chat/completions' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-plus",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "How many gold medals did the Chinese team win at the Paris Olympics"}
],
"enable_search": true
}'python
from openai import OpenAI
client = OpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
completion = client.chat.completions.create(
model="qwen-plus",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "How many gold medals did the Chinese team win at the Paris Olympics"},
],
extra_body={"enable_search": True},
)
print(completion.model_dump_json())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen-plus",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "How many gold medals did the Chinese team win at the Paris Olympics" },
],
enable_search: true,
});
console.log(JSON.stringify(completion));
}
main();Async Invocation
python
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(
api_key="<API Key>",
base_url="https://neolink.com/api/v1",
)
async def main():
response = await client.chat.completions.create(
messages=[{"role": "user", "content": "Who are you"}],
model="qwen-plus",
)
print(response.model_dump_json())
asyncio.run(main())javascript
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "<API Key>",
baseURL: "https://neolink.com/api/v1",
});
async function main() {
const completion = await openai.chat.completions.create({
model: "qwen-plus",
messages: [{ role: "user", content: "Who are you" }],
});
console.log(JSON.stringify(completion));
}
main();Response Body
Non-Streaming Response
| Parameter | Type | Description |
|---|---|---|
id | string | The unique identifier of this call |
choices | array | Array of the model's generated content |
choices[].message.content | string | The model's reply content |
choices[].message.reasoning_content | string | The model's chain-of-thought content (thinking mode) |
choices[].message.role | string | Message role, always assistant |
choices[].message.tool_calls | array | Tool call information (returned during Function Calling) |
choices[].finish_reason | string | Stop reason: stop/length/tool_calls |
choices[].index | integer | Index within the choices array |
choices[].logprobs | object | Token probability information |
created | integer | Unix timestamp (seconds) when the request was created |
model | string | The model used for this request |
object | string | Always chat.completion |
usage | object | Token usage information |
usage.prompt_tokens | integer | Number of input tokens |
usage.completion_tokens | integer | Number of output tokens |
usage.total_tokens | integer | Total number of tokens |
usage.prompt_tokens_details.cached_tokens | integer | Number of tokens that hit the cache |
usage.completion_tokens_details.text_tokens | integer | Number of output text tokens |
Non-Streaming Response Example
json
{
"choices": [
{
"message": {
"role": "assistant",
"content": "I am an ultra-large-scale language model developed by Alibaba Cloud, and my name is Qwen."
},
"finish_reason": "stop",
"index": 0,
"logprobs": null
}
],
"object": "chat.completion",
"usage": {
"prompt_tokens": 3019,
"completion_tokens": 104,
"total_tokens": 3123,
"prompt_tokens_details": {
"cached_tokens": 2048
}
},
"created": 1735120033,
"model": "qwen-plus",
"id": "chatcmpl-6ada9ed2-7f33-9de2-8bb0-78bd4035025a"
}Streaming Response
During streaming output, the object of each chunk is chat.completion.chunk, and incremental content is returned in choices via the delta field:
| Parameter | Type | Description |
|---|---|---|
id | string | The unique identifier of this call; identical for every chunk |
choices[].delta.content | string | Incremental message content |
choices[].delta.reasoning_content | string | Incremental chain-of-thought content |
choices[].delta.role | string | Role; only has a value in the first chunk |
choices[].delta.tool_calls | array | Incremental tool call information |
choices[].finish_reason | string | Stop reason; null when not finished |
created | integer | Timestamp when the request was created |
model | string | The model used for this request |
object | string | Always chat.completion.chunk |
usage | object | Token usage information; returned only in the last chunk when include_usage is true |
Streaming Response Example
json
{"id":"chatcmpl-e30f5ae7","choices":[{"delta":{"content":"","role":"assistant"},"finish_reason":null,"index":0}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","usage":null}
{"id":"chatcmpl-e30f5ae7","choices":[{"delta":{"content":"我是"}}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","usage":null}
{"id":"chatcmpl-e30f5ae7","choices":[{"delta":{"content":"阿里云的超大规模语言模型"}}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","usage":null}
{"id":"chatcmpl-e30f5ae7","choices":[{"delta":{"content":""},"finish_reason":"stop","index":0}],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","usage":null}
{"id":"chatcmpl-e30f5ae7","choices":[],"created":1735113344,"model":"qwen-plus","object":"chat.completion.chunk","usage":{"completion_tokens":17,"prompt_tokens":22,"total_tokens":39,"prompt_tokens_details":{"cached_tokens":0}}}Error Codes
If a model call fails and returns an error message, see the User Error Codes Guide to resolve it.
