U2 - Unisound

Updated at:

This topic describes how to call Unisound's U2 series models on Alibaba Cloud Model Studio.

ImportantThe features described in this topic are available only in the China (Beijing) region. To call the model, you must obtain and configure an API key in the China (Beijing) region.

Quick start

unisound/unisound-u2 is a reasoning model provided by Unisound. It runs in thinking mode by default. Use the thinking parameter to control thinking mode: pass {"type": "enabled"} to enable it or {"type": "disabled"} to disable it. Use reasoning_effort to control the thinking depth. The following example calls unisound/unisound-u2 in thinking mode with streaming enabled.

Before you begin, make sure you have obtained and configured an API key. If you are using an SDK, you also need to install the SDK.

Notethinking and reasoning_effort are not standard OpenAI parameters. In the OpenAI Python SDK, pass them via extra_body. In the Node.js SDK, pass them as top-level parameters.

Python

Sample code

from openai import OpenAI
import os

# Initialize the OpenAI client
client = OpenAI(
    # If you have not configured the environment variable, replace with your Model Studio API key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. The URL varies by region.
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

messages = [{"role": "user", "content": "Which is larger, 9.9 or 9.11?"}]
completion = client.chat.completions.create(
    model="unisound/unisound-u2",
    messages=messages,
    stream=True,
    stream_options={
        "include_usage": True
    },
    # unisound-u2 runs in thinking mode by default. To disable it, set "thinking": {"type": "disabled"}
    extra_body={
        "thinking": {"type": "enabled"},
        "reasoning_effort": "xhigh"
    }
)

reasoning_content = ""  # Full chain-of-thought
answer_content = ""  # Full response
is_answering = False  # Whether the response phase has started
print("\n" + "=" * 20 + "Chain-of-thought" + "=" * 20 + "\n")

for chunk in completion:
    if not chunk.choices:
        print("\n" + "=" * 20 + "Token usage" + "=" * 20 + "\n")
        print(chunk.usage)
        continue

    delta = chunk.choices[0].delta

    # Collect only the thinking content
    if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
        if not is_answering:
            print(delta.reasoning_content, end="", flush=True)
        reasoning_content += delta.reasoning_content

    # Content received. The response phase starts.
    if hasattr(delta, "content") and delta.content:
        if not is_answering:
            print("\n" + "=" * 20 + "Full response" + "=" * 20 + "\n")
            is_answering = True
        print(delta.content, end="", flush=True)
        answer_content += delta.content

Sample response

====================Chain-of-thought====================

The user wants to compare 9.9 and 9.11.
Align the decimal places: 9.9 = 9.90, and 9.11 = 9.11.
Compare the decimal parts: 0.90 > 0.11, so 9.9 is larger.
====================Full response====================

9.9 is larger.

Align the decimal places before comparing: 9.9 = 9.90, and 9.11 = 9.11. Because 0.90 > 0.11, 9.9 > 9.11.
====================Token usage====================

CompletionUsage(completion_tokens=96, prompt_tokens=10, total_tokens=106, prompt_tokens_details={'cached_tokens': 0})

Node.js

Sample code

import OpenAI from "openai";
import process from 'process';

// Initialize the OpenAI client
const openai = new OpenAI({
    // If you have not configured the environment variable, replace with your Model Studio API key: apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    // The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. The URL varies by region.
    baseURL: 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1'
});

let reasoningContent = ''; // Full chain-of-thought
let answerContent = ''; // Full response
let isAnswering = false; // Whether the response phase has started

async function main() {
    try {
        const messages = [{ role: 'user', content: 'Which is larger, 9.9 or 9.11?' }];

        const stream = await openai.chat.completions.create({
            model: 'unisound/unisound-u2',
            messages,
            stream: true,
            stream_options: {
                include_usage: true
            },
            // unisound-u2 runs in thinking mode by default. To disable it, set thinking: { type: 'disabled' }
            thinking: { type: 'enabled' },
            reasoning_effort: 'xhigh'
        });

        console.log('\n' + '='.repeat(20) + 'Chain-of-thought' + '='.repeat(20) + '\n');

        for await (const chunk of stream) {
            if (!chunk.choices?.length) {
                console.log('\n' + '='.repeat(20) + 'Token usage' + '='.repeat(20) + '\n');
                console.log(chunk.usage);
                continue;
            }

            const delta = chunk.choices[0].delta;

            // Collect only the thinking content
            if (delta.reasoning_content !== undefined && delta.reasoning_content !== null) {
                if (!isAnswering) {
                    process.stdout.write(delta.reasoning_content);
                }
                reasoningContent += delta.reasoning_content;
            }

            // Content received. The response phase starts.
            if (delta.content !== undefined && delta.content) {
                if (!isAnswering) {
                    console.log('\n' + '='.repeat(20) + 'Full response' + '='.repeat(20) + '\n');
                    isAnswering = true;
                }
                process.stdout.write(delta.content);
                answerContent += delta.content;
            }
        }
    } catch (error) {
        console.error('Error:', error);
    }
}

main();

Sample response

====================Chain-of-thought====================

The user wants to compare 9.9 and 9.11.
Align the decimal places: 9.9 = 9.90, and 9.11 = 9.11.
Compare the decimal parts: 0.90 > 0.11, so 9.9 is larger.
====================Full response====================

9.9 is larger.

Align the decimal places before comparing: 9.9 = 9.90, and 9.11 = 9.11. Because 0.90 > 0.11, 9.9 > 9.11.
====================Token usage====================

{ prompt_tokens: 10, completion_tokens: 96, total_tokens: 106, prompt_tokens_details: { cached_tokens: 0 } }

HTTP

Sample code

curl

# The following URL is for the China (Beijing) region. Replace {WorkspaceId} with your Model Studio workspace ID. The URL varies by region.
curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "unisound/unisound-u2",
    "messages": [
        {
            "role": "user",
            "content": "Which is larger, 9.9 or 9.11?"
        }
    ],
    "stream": true,
    "stream_options": {
        "include_usage": true
    },
    "thinking": {
        "type": "enabled"
    },
    "reasoning_effort": "xhigh"
}'

Other features

Feature

Supported

Notes

Multi-turn conversation

Supported

Function calling

Supported

The model cannot stream tool call arguments through tool_stream

Structured output

Supported

response_format supports only {"type": "text"} and {"type": "json_object"}. json_schema is not supported

Web search

Not supported

Multimodal input

Not supported

Text input only

unisound/unisound-u2 does not support the following parameters: n, stop, preserve_thinking, thinking_budget, tool_stream, enable_code_interpreter, enable_search, search_options, and skill. These parameters are ignored or return an error if passed.

For some supported parameters, the valid values or behavior differ from Model Studio:

Parameter

Model Studio

U2

temperature

Valid values: [0, 2)

Valid values: [0, 2). Default value: 1.0

top_k

An integer greater than or equal to 0. Setting it to null or greater than 100 disables the top_k strategy

Must be an integer greater than or equal to 1. Default value: 40

thinking

Use enable_thinking to turn thinking mode on or off

Thinking mode is enabled by default. Use thinking (set to {"type": "enabled"} or {"type": "disabled"}) to control thinking mode, and reasoning_effort to control the thinking depth

Models and pricing

The U2 series models are reasoning models provided by Unisound. They run in thinking mode by default.

For context length and pricing details, see the Model Studio console.

You are charged based on the input and output tokens of the model.

In thinking mode, the chain-of-thought is billed as output tokens.

Error codes

If a model call fails and returns an error message, see Error codes for troubleshooting.