Content generation service
This topic describes the API parameters of the OpenAI-compatible content generation service.
URL
{host}/compatible-mode/v1/chat/completionshost: the endpoint used to call the service. You can call the API service over the Internet or a virtual private cloud (VPC). For more information, see Obtain a service endpoint.

Request parameters
Parameter | Type | Required | Description | Example |
messages | List[Dict] | Yes | The list of messages in the conversation so far:
| [ {"role": "system", "content": "You are a robot assistant"}, {"role": "user", "content": "What is the capital of Henan Province?"}, {"role": "assistant", "content": "Zhengzhou"}, {"role": "user", "content": "What fun things are there to do there?"} ] |
model | String | Yes | The service ID. For information about supported service IDs, see | ops-qwen-turbo |
max_tokens | Int | No | The maximum number of tokens to generate for the chat completion. If generation has not finished when this value is reached, the value of finish_reason is length. Otherwise, the value is stop. | 1024 |
temperature | Float | No | The temperature value controls the probability distribution over candidate words during text generation and is used to control the randomness and diversity of model responses. Valid values: [0, 2). A value of 0 is meaningless. A higher temperature value lowers the peak of the probability distribution so that more low-probability words are selected, which produces more diverse results. A lower temperature value sharpens the peak of the probability distribution so that high-probability words are more likely to be selected, which produces more deterministic results. | 1 |
top_p | Float | No | The probability threshold for nucleus sampling during generation. Valid values: (0, 1.0). A larger value results in higher randomness, and a smaller value results in higher determinism. | 0.8 |
presence_penalty | Float | No | Controls the repetition across the entire sequence generated by the model. Valid values: [-2.0, 2.0]. Default value: 0. Increasing presence_penalty reduces repetition in the generated content. | 0 |
frequency_penalty | Float | No | The frequency penalty. Valid values: [-2.0, 2.0]. Default value: 0. A positive value penalizes newly generated words based on their current frequency in the text, which reduces the likelihood that the model repeats the same phrases. | 0 |
stop | String, List[String] | No | The stop words. The model automatically stops generating when the generated content is about to include the specified string or token_id. The generated content does not include the specified content. stop can be of the String or Array type. | Default: null |
stream | Boolean | No | Specifies whether to use streaming output. When results are output in stream mode, the API returns a generator, and you must iterate over it to obtain the results. Each output is the incremental sequence generated so far. Default value: false. | false |
Response parameters
Parameter | Type | Description | Example |
id | String | The system-generated ID that identifies this call. | 2244F3A8-4201-4F37-BF86-42013B1026D6 |
object | String | The object type. The value is fixed as chat.completion. | chat.completion |
created | Long | The current UNIX timestamp. Unit: seconds. | 1719313883 |
model | String | The name of the model that is called. | ops-qwen-turbo |
choices.index | Int | The sequence number of the result generated by the model. 0 indicates the first result. | 0 |
choices.message | Map | The message output by the model. | { "role":"assistant", "content":"This is an example" } |
choices.finish_reason | String | Non-streaming + streaming
| stop |
usage.completion_tokens | Int | The length of the model-generated response after it is converted into tokens. | 150 |
usage.prompt_tokens | Int | The number of tokens converted from the input content of the user request to the LLM. | 180 |
usage.total_tokens | Int | The total number of tokens used, which is the sum of usage.prompt_tokens and usage.completion_tokens. | 330 |
Sample curl request
curl http://xxxx-cn-shanghai.opensearch.aliyuncs.com/compatible-mode/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Your-API-Key" \
-d '{
"model":"ops-qwen-turbo",
"messages":[
{"role": "system", "content": "You are a robot assistant"},
{"role": "user", "content": "Recommend one science fiction book"}
]
}'Sample response
{
"id":"fb4b3860e051ecad0b019971******",
"object":"chat.completion",
"created":1749804786,
"model":"ops-qwen-turbo",
"choices":
[
{
"index":0,
"message":
{
"role":"assistant",
"content":"The Three-Body Problem series by Liu Cixin. It tells the story of......"
},
"finish_reason":"stop"
}
],
"usage":
{
"prompt_tokens":22,
"completion_tokens":48,
"total_tokens":70
}
} Status codes
For more information, see API and SDK status codes and error codes of AI Search Open Platform.