Skip to main content
Qwen-MT

Qwen-MT translation models

Call Qwen-MT translation models through the DashScope native HTTP API.

POST
/api/v1/services/aigc/text-generation/generation
import os
import dashscope

# 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
dashscope.base_http_api_url = 'https://ap-southeast-1.maas.qwencloudapi.com/api/v1'
messages = [
  {
    "role": "user",
    "content": "No me reí después de ver este video"
  }
]
translation_options = {
  "source_lang": "auto",
  "target_lang": "English",
}
response = dashscope.Generation.call(
  # 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'),
  model="qwen-mt-plus",  # This example uses qwen-mt-plus. You can replace the model name as needed.
  messages=messages,
  result_format='message',
  translation_options=translation_options
)
print(response.output.choices[0].message.content)
{
  "status_code": 200,
  "request_id": "9b4ec3b2-6d29-40a6-a08b-7e3c9a51c289",
  "code": "",
  "message": "",
  "output": {
    "text": null,
    "finish_reason": "stop",
    "choices": [
      {
        "finish_reason": "stop",
        "message": {
          "role": "assistant",
          "content": "I didn't laugh after watching this video."
        }
      }
    ],
    "model_name": "qwen-mt-plus"
  },
  "usage": {
    "input_tokens": 53,
    "output_tokens": 9,
    "total_tokens": 62
  }
}

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

Input data containing the messages to translate.

object

Optional parameters for the translation request.

Response

200-application/json
integer

Request status code. 200 indicates success. The Java SDK does not return this parameter; it throws an exception on failure.

string

Unique request identifier. In the Java SDK, this is requestId.

string

Error code. Empty string on success. Only the Python SDK returns this parameter.

string

Error message. Empty string on success. Only the Python SDK returns this parameter.

object

Output information from the model.

object

Token usage information.