Application gateway API reference

Updated at:

Request parameters

Parameter

Type

Description

Example value

input

Object

Contains the input data.

-

messages

Array[Object]

An array of message objects representing the conversation history.

-

role

String

The role of the message author. Valid values are:

  • assistant: A message generated by the assistant.

  • user: A message provided by the user.

assistant

content

String

The content of the message. If the role is assistant, this is the assistant's output. If the role is user, this is the user's input.

Hello, valued Alibaba Cloud user. This is a test of the opening message. We apologize for any inconvenience this may cause.

biz_params

Object

Custom business parameters.

{"city": "China (Hangzhou)"}

parameters

Object

Model-specific parameters, such as top_k.

1

incremental_output

Boolean

Specifies whether to enable incremental output in streaming output mode.

true

flow_stream_mode

String

The streaming output mode for a workflow application. Must be set to agent_format for this type of application.

agent_format

call_id

String

The unique identifier for the call. This must be the same ID that was returned when the call was initiated.

147417592084^1341********

session_id

String

A unique identifier for the conversation session.

Note

This field is optional and not sent by default.

147417592084^1341********

Example request

{
    "input": {
        "messages": [
            {
                "role": "system",
                "content": "You are an Alibaba Cloud customer service assistant. Your task is to play a standard welcome message."
            },
            {
              "role": "assistant",
              "content": "Hello, valued Alibaba Cloud user. This is a test of the opening message. We apologize for any inconvenience."
            },
            {
              "role": "user",
              "content": "What is this about?"
            }
        ],
        "biz_params": {
            "city": "China (Hangzhou)"
        }
    },
    "debug": {},
    "parameters": {
        "incremental_output": true,
        "flow_stream_mode": "agent_format"
    },
    "call_id": "147417592084^1341********"
}

Response fields

Parameter

Type

Description

Example value

output

Object

Contains the results of the API call.

-

text

String

The model-generated response.

I am an Alibaba Cloud customer service assistant

finish_reason

String

The reason the model stopped generating content. A null value indicates that generation is in progress and more data will be streamed. Other possible values are:

  • stop: The model reached a natural stopping point and finished generating tokens.

  • user: The generation was interrupted, for example, by reaching the maximum token limit or being stopped by the user.

null

session_id

String

The unique identifier for the current conversation session.

147417592084^1341********

request_id

String

The unique identifier for the Model Studio API call.

Note

This field is optional and may not be included in every response.

1111111-2222-3333-4444-**********

Example response

{
    "output": {
        "session_id": "c57cb4cb62a8************",
        "finish_reason": "null",
        "text": "I am an Alibaba Cloud customer service assistant"
    },
    "usage": {
        "models": [
            {
                "input_tokens": 158,
                "output_tokens": 7,
                "model_id": "qwen-plus"
            }
        ]
    },
    "request_id": "1111111-2222-3333-4444-555555555555"
}

Verify gateway integration with SSE

Before integrating your large model, you can use SSE streaming to validate its compatibility with the communication engine gateway.

The integration uses HTTP, and the connection must support SSE streaming output.

Run the following cURL command to test the integration.

Note

Before running the command, replace the following placeholders: https://********** with your URL (the Model Address on the configuration page), $AUTH with your authorization code (the Authorization Code on the configuration page), and the model value with your model (the Base Model in Model Configuration settings).

Request:

curl -X POST \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-H "x-dashscope-sse: enable" \
-d '{
    "input": {
        "messages": [
            {
              "role": "assistant",
              "content": "This is a test opening message."
            },
            {
              "role": "user",
              "content": "What is this about?"
            }
        ]
    },
    "debug": {},
    "parameters": {
        "incremental_output": true,
        "flow_stream_mode": "agent_format"
    },
    "call_id": "147417592084^1341********"
}' \
"https://**********"

Output:

data:{"output":{"session_id":"c57cb4cb62a8************","finish_reason":"null","text":"I am an Alibaba Cloud customer service assistant"},"usage":{"models":[{"input_tokens":158,"output_tokens":7,"model_id":"qwen-plus"}]},"request_id":"1111111-2222-3333-4444-555555555555"}