Skip to content

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/completions

Authentication ​

MethodDescription
Bearer TokenPass Authorization: Bearer <API Key> in the request header to verify your account.

Request Headers ​

ParameterTypeRequiredDescription
Content-TypestringYesThe media type of the request body; set it to application/json
AuthorizationstringYesThe Bearer API Key used to verify your account

Request Body ​

ParameterTypeRequiredDefaultDescription
modelstringYes-Model name; supported models include the Qwen large language models, etc.
messagesarrayYes-The context passed to the model, arranged in conversation order
streambooleanNofalseWhether to reply in streaming output mode
stream_optionsobjectNo-Streaming output configuration; takes effect only when stream is true
temperaturefloatNo0.7Sampling temperature, controls generation diversity; range [0, 2)
top_pfloatNo0.8Nucleus sampling probability threshold; range (0, 1.0]
top_kintegerNo20Number of candidate tokens for sampling; not a standard OpenAI parameter, passed via extra_body when using the SDK
max_tokensintegerNo-Maximum length of the model's answer (excluding chain of thought); about to be deprecated, use max_completion_tokens
max_completion_tokensintegerNo-Maximum length of the model output (including chain of thought and the answer)
response_formatobjectNo{"type":"text"}Format of the returned content; can be text or json_object
toolsarrayNo-Array of tool objects, for the model to call in Function Calling
tool_choicestring/objectNoautoTool selection strategy; can be auto, none, or a specified tool
parallel_tool_callsbooleanNofalseWhether to enable parallel tool calls
enable_searchbooleanNofalseWhether to enable web search; not a standard OpenAI parameter, passed via extra_body when using the SDK
search_optionsobjectNo-Web search strategy
enable_thinkingbooleanNo-Whether to enable thinking mode, applicable to mixed thinking models; not a standard OpenAI parameter
thinking_budgetintegerNo-Maximum number of tokens for the thinking process; not a standard OpenAI parameter
reasoning_effortstringNo-Reasoning effort; can be low/medium/high/max/xhigh; not a standard OpenAI parameter
seedintegerNo1234Random seed for reproducible results; range [0, 2^31-1]
stopstring/arrayNo-Stop strings; generation terminates when the specified string appears in the output
nintegerNo1Number of responses to generate; range 1-4
logprobsbooleanNofalseWhether to return the log probabilities of the output tokens
top_logprobsintegerNo0Number of candidate tokens to return; range [0, 5]
repetition_penaltyfloatNo1.05Repetition penalty; any value greater than 0; not a standard OpenAI parameter
presence_penaltyfloatNo0.0Content repetition control; range [-2.0, 2.0]

messages Message Types ​

Message TyperoleDescription
System MessagesystemSystem message that sets the model's role, tone, and task constraints; usually placed first
User MessageuserUser message that passes the question or context
Assistant MessageassistantModel reply, used to pass back multi-turn conversation context
Tool MessagetoolTool 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 ​

ParameterTypeRequiredDefaultDescription
include_usagebooleanNofalseWhether to include token usage information in the last data chunk

search_options Parameters ​

ParameterTypeDefaultDescription
forced_searchbooleanfalseWhether to force web search
search_strategystringturboSearch strategy; can be turbo/max/agent/agent_max
enable_search_extensionbooleanfalseWhether to enable vertical-domain search

Model Notes ​

Supported Models ​

  • qwen-plus, qwen-max, qwen-turbo, qwen-flash
  • The qwen3.5, qwen3.6, qwen3.7 series

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();
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 ​

ParameterTypeDescription
idstringThe unique identifier of this call
choicesarrayArray of the model's generated content
choices[].message.contentstringThe model's reply content
choices[].message.reasoning_contentstringThe model's chain-of-thought content (thinking mode)
choices[].message.rolestringMessage role, always assistant
choices[].message.tool_callsarrayTool call information (returned during Function Calling)
choices[].finish_reasonstringStop reason: stop/length/tool_calls
choices[].indexintegerIndex within the choices array
choices[].logprobsobjectToken probability information
createdintegerUnix timestamp (seconds) when the request was created
modelstringThe model used for this request
objectstringAlways chat.completion
usageobjectToken usage information
usage.prompt_tokensintegerNumber of input tokens
usage.completion_tokensintegerNumber of output tokens
usage.total_tokensintegerTotal number of tokens
usage.prompt_tokens_details.cached_tokensintegerNumber of tokens that hit the cache
usage.completion_tokens_details.text_tokensintegerNumber 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:

ParameterTypeDescription
idstringThe unique identifier of this call; identical for every chunk
choices[].delta.contentstringIncremental message content
choices[].delta.reasoning_contentstringIncremental chain-of-thought content
choices[].delta.rolestringRole; only has a value in the first chunk
choices[].delta.tool_callsarrayIncremental tool call information
choices[].finish_reasonstringStop reason; null when not finished
createdintegerTimestamp when the request was created
modelstringThe model used for this request
objectstringAlways chat.completion.chunk
usageobjectToken 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.