Qwen-Math models provide mathematical reasoning with detailed, verifiable step-by-step solutions.
NoteThis document applies only to the China (Beijing) region. To use the model, you must use an API key from the China (Beijing) region.
Models and pricing
Commercial ModelsModel name | Input price | Output price | Context window | Max input | Max output | Free quota |
|---|---|---|---|---|---|---|
(per million tokens) | (tokens) | |||||
qwen-math-plus | $0.574 | $1.721 | 4,096 | 3,072 | 3,072 | No free quota is available. |
qwen-math-turbo | $0.287 | $0.861 | ||||
For information about model rate limits, see rate limiting.
Quick start
Obtain an API key and export the API key as an environment variable. If you use the OpenAI SDK or DashScope SDK to make calls, install the SDK.
OpenAI compatible
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("DASHSCOPE_API_KEY"), # For security, do not hard-code your API key. Use an environment variable or a secrets management service.
# China (Beijing) region. The URL varies depending on the region.
base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)
completion = client.chat.completions.create(
model="qwen-math-plus",
messages=[{'role': 'user', 'content': 'Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $'}])
print(completion.choices[0].message.content)
curl --location "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-math-plus",
"messages": [
{
"role": "user",
"content": "Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $"
}
]
}'
DashScope
from http import HTTPStatus
import dashscope
# China (Beijing) region. The URL varies depending on the region.
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
def call_with_messages():
messages = [
{'role': 'user', 'content': 'Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $'}]
response = dashscope.Generation.call(
model='qwen-math-plus',
messages=messages,
# Set result_format to 'message'.
result_format='message',
)
if response.status_code == HTTPStatus.OK:
print(response)
else:
print('Request id: %s, Status code: %s, error code: %s, error message: %s' % (
response.request_id, response.status_code,
response.code, response.message
))
if __name__ == '__main__':
call_with_messages()
import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.Constants;
public class Main {
public static void callWithMessage()
throws NoApiKeyException, ApiException, InputRequiredException {
// China (Beijing) region. The URL varies depending on the region.
Constants.baseHttpApiUrl="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
Generation gen = new Generation();
Message userMsg = Message.builder().role(Role.USER.getValue()).content("Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $").build();
GenerationParam param =GenerationParam.builder()
.apiKey(System.getenv("DASHSCOPE_API_KEY"))
.model("qwen-math-plus")
.messages(Arrays.asList(userMsg))
.resultFormat(GenerationParam.ResultFormat.MESSAGE)
.build();
GenerationResult result = gen.call(param);
System.out.println(result);
}
public static void main(String[] args){
try {
callWithMessage();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
}
}
curl --location "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "qwen-math-plus",
"input":{
"messages":[
{
"role": "user",
"content": "Derive a universal solution for the quadratic equation $ Ax^2+Bx+C=0 $"
}
]
},
"parameters": {
"result_format": "message"
}
}'
Try the model in the Model Studio console.
Recommendations
- Use English and LaTeX: Qwen-Math handles mathematical problems in English. Use LaTeX for symbols and formulas in your input.
- Control content output: Partial mode ensures the model output closely follows a given prefix, improving accuracy.
- The
temperatureparameter defaults to0. Do not change this setting. - Easily extract results: Qwen-Math outputs the final result in a
\boxed{}block by default.
### Final Answer:
The universal solution for the quadratic equation $ Ax^2 + Bx + C = 0 $ is:
$$
\boxed{x = \frac{-B \pm \sqrt{B^2 - 4AC}}{2A}}
$$
Frequently asked questions
How do I solve math problems in images with Qwen-Math? |
Qwen-Math does not support image recognition. Qwen-Math input and output parameters are documented in the Qwen API Reference. |
Where can I find error code details? |
If the model call fails and returns an error message, see Error codes for resolution. |