Skip to main content
Qwen-MT

Qwen-MT translation models

Call Qwen-MT translation models through the OpenAI-compatible API.

POST
/compatible-mode/v1/chat/completions
import os
from openai import OpenAI

client = OpenAI(
  # If you have not configured the environment variable, replace the following line with your API key: api_key="sk-xxx",
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  # Singapore (ap-southeast-1). For another region, replace ap-southeast-1 in the URL.
  # API keys are region-specific. See https://docs.qwencloud.com/developer-guides/getting-started/regions
  base_url="https://ap-southeast-1.maas.qwencloudapi.com/compatible-mode/v1",
)
messages = [
  {
    "role": "user",
    "content": "No me reí después de ver este video"
  }
]
translation_options = {
  "source_lang": "auto",
  "target_lang": "English"
}

completion = client.chat.completions.create(
  model="qwen-mt-plus",
  messages=messages,
  extra_body={
    "translation_options": translation_options
  }
)
print(completion.choices[0].message.content)
{
  "id": "chatcmpl-999a5d8a-f646-4039-968a-167743ae0f22",
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "logprobs": null,
      "message": {
        "content": "I didn't laugh after watching this video.",
        "refusal": null,
        "role": "assistant",
        "annotations": null,
        "audio": null,
        "function_call": null,
        "tool_calls": null
      }
    }
  ],
  "created": 1762346157,
  "model": "qwen-mt-plus",
  "object": "chat.completion",
  "service_tier": null,
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 9,
    "prompt_tokens": 53,
    "total_tokens": 62,
    "completion_tokens_details": null,
    "prompt_tokens_details": null
  }
}

Authorizations

string
header
required

QwenCloud API Key. Create one in the QwenCloud console.

Body

application/json
enum<string>
required

The model name.

qwen-mt-plus,qwen-mt-flash,qwen-mt-lite
qwen-mt-plus
object[]
required

An array of messages providing text to translate. Only user messages are supported.

object
required

Translation-specific parameters.

boolean
defaultfalse

Whether to return the response in streaming mode. When true, the response is returned as server-sent event chunks. qwen-mt-flash and qwen-mt-lite return incremental output; qwen-mt-plus and qwen-mt-flash return non-incremental output (each chunk contains the full sequence so far).

object

Configuration for streaming output. Only takes effect when stream is true.

integer

Maximum number of tokens to generate. If the output exceeds this limit, it is truncated. Defaults to the model's maximum output length.

integer

Random number seed for reproducible results. Range: [0, 2^31-1].

number
default0.65

Sampling temperature controlling output diversity. Higher values produce more diverse text. Range: [0, 2). Only set one of temperature or top_p.

number
default0.8

Nucleus sampling probability threshold. Higher values produce more diverse text. Range: (0, 1.0]. Only set one of temperature or top_p.

integer
default1

Size of the candidate token set for sampling. Larger values increase randomness. If None or greater than 100, only top_p applies. Must be >= 0. Non-standard parameter: use extra_body in Python SDK.

number
default1

Penalty for repeated sequences. Higher values reduce repetition. A value of 1.0 means no penalty. Must be > 0. Non-standard parameter: use extra_body in Python SDK.

Response

200-application/json
string

Unique request identifier.

object[]

Generated content from the model.

integer

UNIX timestamp when the request was created.

string

The model used for the request.

string

Always chat.completion.

string | null

Currently fixed to null.

string | null

Currently fixed to null.

object

Token consumption information.