Skip to content

Mathematical capabilities (Qwen-Math)

Qwen-Math provides powerful mathematical reasoning and calculation capabilities, with detailed problem-solving steps for easy understanding and verification. Note

This document applies only to the China (Beijing) region. To use a model, use an API key from the China (Beijing) region.

Models and pricing

Commercial

ModelInput priceOutput priceContext windowMax inputMax outputFree quota(Note)
(Million tokens)(Tokens)
qwen-math-plus$0.574$1.7214,0963,0723,072No free quota
qwen-math-turbo$0.287$0.861

Snapshots such as qwen-math-xxx-latest and qwen-math-xxx-YYYY-MM-DD have the same prices and specifications as the preceding qwen-math-xxx versions,

Model capabilities: qwen-math-xxx = qwen-math-xxx-latest = qwen-math-xxx-2024-09-19

Open source

ModelInput priceOutput priceContext windowMax inputMax outputFree quota(Note)
(Million tokens)(Tokens)
qwen2.5-math-72b-instruct$0.574$1.7214,0963,0723,072No free quota
qwen2.5-math-7b-instruct$0.144$0.287

For more information about the rate limits, see Rate limits.

Getting started

Get 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

Python

HELPCODEESCAPE-python
from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"), # Do not hard-code credentials in your code. Always use environment variables or a key management service.
    base_url="https://dashscope.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

HELPCODEESCAPE-shell
curl --location "https://dashscope.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

Python

HELPCODEESCAPE-python
from http import HTTPStatus
import dashscope


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

Java

HELPCODEESCAPE-java
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;

public class Main {
    public static void callWithMessage()
            throws NoApiKeyException, ApiException, InputRequiredException {
        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

HELPCODEESCAPE-curl
curl --location "https://dashscope.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"
    }
}'

You can also go to the Model Studio console to try out the model.

Recommendations

  1. Use English and LaTeX: Qwen-Math is designed for mathematical problems in English. For best results, use LaTeX for mathematical symbols and formulas in your input.

  2. Standardize output : Use partial mode for precise control. It ensures that the output closely follows the provided prefix, which improves the accuracy and control of the results.

  3. The model is set to temperature=0 by default. No adjustment is required.

  4. Retrieve results easily : Qwen-Math places the final result in a \boxed{} block by default.

FAQ

How can I use Qwen-Math to solve mathematical problems in images?
Qwen-Math does not support image input. - If an image contains simple mathematical problems, you can use Qwen-VL or QVQ. - If an image contains complex mathematical problems, you can first use Qwen-VL or QVQ to extract the text from the image. Then, use Qwen-Math to solve the problem. For more information about the input and response parameters of Qwen-Math, see Qwen API reference.
Where can I find detailed information about error codes?
If the model call fails and returns an error message, see Error messages for resolution.

Mirror of Alibaba Cloud Model Studio docs for reference and RAG. Not affiliated with Alibaba Cloud.