Input and output parameters for calling Qwen-MT through the OpenAI compatible interface or the DashScope API.
References: Machine translation (Qwen-MT)
OpenAI compatible
Singapore region
base_url for SDK: https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1
HTTP endpoint: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
Virginia region
base_url for SDK: https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1
HTTP endpoint: POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/compatible-mode/v1/chat/completions
Beijing region
base_url for SDK: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1
HTTP endpoint: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/chat/completions
ImportantAlibaba Cloud Model Studio has released workspace-specific domains for the China (Beijing), Singapore, and China (Hong Kong) regions. The new dedicated domains deliver superior performance and higher stability for inference requests. We recommend migrating to the new domains:
- China (Beijing): from
https://dashscope.aliyuncs.comtohttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com - Singapore: from
https://dashscope-intl.aliyuncs.comtohttps://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com - China (Hong Kong): from
https://cn-hongkong.dashscope.aliyuncs.comtohttps://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com
{WorkspaceId} is your workspace ID, which can be found on the Workspace Details page in the Alibaba Cloud Model Studio console. The existing domain remains fully functional.
First, create an API key and configure it as an environment variable . If you use the OpenAI SDK, install the SDK .
Request body | Basic usagePythonNode.jscurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Term interventionPythonNode.jscurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Translation memoryPythonNode.jscurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Domain promptingPythonNode.jscurlEndpoints and API keys differ by region. The following is the Singapore endpoint. |
model Model name. Supported: qwen-mt-plus, qwen-mt-flash, qwen-mt-lite, qwen-mt-turbo. | |
messages Array of messages providing context to the model. Only user messages are supported. | |
stream Enable streaming output mode. Valid values:
Noteqwen-mt-flash and qwen-mt-lite return data incrementally (each chunk contains only new content). qwen-mt-plus and qwen-mt-turbo return data non-incrementally (each chunk contains entire sequence to date). This behavior cannot be changed. Example: I I didn I didn't I didn't laugh I didn't laugh after ... | |
stream_options The configuration items for streaming output. This parameter takes effect only when | |
max_tokens Maximum number of tokens to generate. If the output exceeds this value, the response is truncated. The default and maximum values are the maximum output length of the model. For more information, see Model selection. | |
seed Random number seed for reproducible results. Using the same Value range: | |
temperature Sampling temperature that controls the diversity of generated text. Higher values produce more diverse text. Lower values produce more deterministic text. Value range: [0, 2) Both | |
top_p Probability threshold for nucleus sampling that controls the diversity of generated text. Higher values produce more diverse text. Lower values produce more deterministic text. Value range: (0, 1.0] Both | |
top_k Size of the candidate set for sampling during generation. For example, setting this to 50 means only the top 50 tokens by score form the sampling pool. Larger values increase randomness; smaller values increase determinism. If the value is None or greater than 100, top_k is disabled and only top_p takes effect. The value must be greater than or equal to 0. Non-standard OpenAI parameter. Python SDK: place in extra_body object | |
repetition_penalty Penalty for repetition in consecutive sequences. Higher values reduce repetition. A value of 1.0 applies no penalty. Must be greater than 0, with no strict upper limit. Non-standard OpenAI parameter. Python SDK: place in extra_body object | |
translation_options Translation parameters. Non-standard OpenAI parameter. Python SDK: place in extra_body object |
Chat response object (non-streaming output) | |
id Unique request ID. | |
choices Array of model-generated content. | |
created The UNIX timestamp when the request was created. | |
model The model used for the request. | |
object This is always | |
service_tier Currently fixed to | |
system_fingerprint Currently fixed to | |
usage Token consumption for the request. Properties completion_tokens Number of tokens in the model output. prompt_tokens Number of tokens in the input. total_tokens Total tokens consumed, equal to completion_tokens_details Currently fixed to prompt_tokens_details Currently fixed to |
Chat response chunk object (streaming output) | |
id The unique ID of the call. Each chunk object has the same ID. | |
choices An array of content generated by the model. If | |
created The UNIX timestamp when the request was created. Each chunk has the same timestamp. | |
model The model used for the request. | |
object This is always | |
service_tier Currently fixed to | |
system_fingerprint Currently fixed to | |
usage The tokens consumed by the request. This is returned in the last chunk only when Properties completion_tokens The number of tokens in the model output. prompt_tokens The number of input tokens. total_tokens The total number of tokens. This is the sum of completion_tokens_details Currently fixed to prompt_tokens_details Currently fixed to |
DashScope
Singapore
HTTP endpoint: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
Set base_url to:
Python code
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
Java code
- Method 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1");
- Method 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
Virginia
HTTP endpoint: POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
Set base_url to:
Python code
dashscope.base_http_api_url = 'https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1'
Java code
- Method 1:
import com.alibaba.dashscope.protocol.Protocol;
Generation gen = new Generation(Protocol.HTTP.getValue(), "https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1");
- Method 2:
import com.alibaba.dashscope.utils.Constants;
Constants.baseHttpApiUrl="https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1";
Beijing
HTTP endpoint: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/text-generation/generation
You do not need to configure base_url for SDK calls. The default value is https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1.
You must create an API key and export the API key as an environment variable . If using the DashScope SDK, install the DashScope SDK .
Request body | Basic usagePythonJavacurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Term interventionPythonJavacurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Translation memoryPythonJavacurlEndpoints and API keys differ by region. The following is the Singapore endpoint. Domain promptingPythonJavacurlEndpoints and API keys differ by region. The following is the Singapore endpoint. |
model Model name. Supported: qwen-mt-plus, qwen-mt-flash, qwen-mt-lite, qwen-mt-turbo. | |
messages Array of messages providing context to the model. Only user messages are supported. | |
max_tokens Maximum number of tokens to generate. If the output exceeds this value, the response is truncated. The default and maximum values are the maximum output length of the model. For more information, see Model selection.
| |
seed Random number seed for reproducible results. Using the same Value range:
| |
temperature Sampling temperature that controls the diversity of generated text. Higher values produce more diverse text. Lower values produce more deterministic text. Value range: [0, 2) Both
| |
top_p Probability threshold for nucleus sampling that controls the diversity of generated text. Higher values produce more diverse text. Lower values produce more deterministic text. Value range: (0, 1.0] Both
| |
repetition_penalty Penalty for repetition in consecutive sequences. Higher values reduce repetition. A value of 1.0 applies no penalty. Must be greater than 0, with no strict upper limit.
| |
top_k Size of the candidate set for sampling during generation. For example, setting this to 50 means only the top 50 tokens by score form the sampling pool. Larger values increase randomness; smaller values increase determinism. If the value is None or greater than 100, top_k is disabled and only top_p takes effect. The value must be greater than or equal to 0.
| |
stream Enable streaming output mode. Valid values:
Noteqwen-mt-flash and qwen-mt-lite return data incrementally (each chunk contains only new content). qwen-mt-plus and qwen-mt-turbo return data non-incrementally (each chunk contains entire sequence to date). This behavior cannot be changed. Example: I I didn I didn't I didn't laugh I didn't laugh after ...
| |
translation_options Translation parameters.
|
Chat response object (same for streaming and non-streaming output) | |
status_code Request status code. 200 indicates success; other values indicate failure.
| |
request_id Unique request ID.
| |
code Error code. Empty on success.
| |
output Call result. Properties text Currently fixed to finish_reason Reason why the model stopped generating content. Valid values:
choices Model output. Properties finish_reason Valid values:
message Model output message. Properties role Output message role. Fixed to content Translation result. model_name Model used for this request. | |
usage Token usage for the request. Properties input_tokens Number of input tokens. output_tokens Number of output tokens. total_tokens Total tokens, equal to input_tokens + output_tokens. |
Error codes
If the call fails, see Error codes to resolve the issue.