Skip to main content
DashScope API

New Agent Application API Reference

Input and output parameters for invoking Alibaba Cloud Bailian's new agent applications via the DashScope API

This document describes the input and output parameters for invoking Alibaba Cloud Bailian’s new agent applications using the DashScope API.

Prerequisites

Before getting started, ensure you have completed the following steps:
  1. Create an Application: Go to Application Management to create a new Bailian agent application and obtain its Application ID.
  2. Obtain an API Key: Retrieve your API key via API Key Management, then configure it as an environment variable.
  3. Install SDK (Optional): If using an SDK, install the corresponding DashScope SDK for your programming language.

Invocation Methods

  • HTTP API Call Endpoint: POST https://dashscope.aliyuncs.com/api/v1/apps/{APP_ID}/completion
    Replace {APP_ID} with your actual Application ID.
  • SDK Call Python and Java SDKs are preconfigured with the correct endpoint by default. You may also customize it using the base_url parameter.
Online Debugging: Navigate to Application Card → Publish → API Debug, enter required parameters, and click Run to test.

Request Body

ParameterTypeRequiredDescription
app_idstringYesApplication identifier. Obtain it from the application card in Application Management. In Java SDK, use appId; in HTTP calls, substitute it into the URL path where {APP_ID} appears.
promptstringYesUser input instruction guiding the application to generate a response. In HTTP calls, include this inside the input object.
session_idstringNoSession identifier for maintaining conversation history. When provided, the request automatically includes previously stored dialogue history from the cloud. This ID expires after 1 hour of inactivity. In Java SDK, set via setSessionId; in HTTP calls, include in the input object.
workspacestringNoBusiness workspace identifier. Required only when calling applications deployed under a sub-workspace. In HTTP calls, specify via header X-DashScope-WorkSpace.
streambooleanNoWhether to enable streaming responses. Default: false. Recommended: true. In Java SDK, use streamCall; in HTTP, set header X-DashScope-SSE to enable.
incremental_outputbooleanNoWhether to enable incremental output in streaming mode. Default: false. Recommended: true. In Java SDK, use incrementalOutput; in HTTP, include in the parameters object.
enable_thinkingbooleanNoToggle deep-thinking model between “thinking” and “non-thinking” modes. Default: false. When true, the model outputs its reasoning process before returning the final answer. In Java SDK, use enableThinking; in HTTP, include in the parameters object.
has_thoughtsbooleanNoWhether to return the model’s internal reasoning steps. Default: false. When true, reasoning is available in the thoughts field. In Java SDK, use hasThoughts; in HTTP, include in the parameters object.
image_listarrayNoList of images. Supports image URLs and Data URLs (Base64-encoded). A vision-language model must be selected in the application configuration. In Java SDK, use images; in HTTP, include in the input object.
file_listarrayNoList of file URLs. In Java SDK, use files; in HTTP, include in the input object.
model_idstringNoModel name. Overrides console-configured defaults to explicitly specify the model used for this call. In Java SDK, use modelId; in HTTP, include in the parameters object.
dialog_roundintegerNoNumber of prior dialogue rounds to include as context. Sets the maximum number of historical turns passed to the model. In Java SDK, use dialogRound; in HTTP, include in the parameters object.
biz_paramsobjectNoCustom plugin parameters defined by the application. In Java SDK, use bizParams; in HTTP, include in the input object.

biz_params Properties

ParameterTypeDescription
user_prompt_paramsobjectCustom prompt variable definitions. Variable names must be unique within one application; up to 10 variables allowed.
user_defined_paramsobjectCustom plugin parameter definitions. Keys correspond to plugin TOOL_IDs; values are parameter objects required by each plugin.

Code Examples

Single-Turn Conversation

import os
from http import HTTPStatus
from dashscope import Application

response = Application.call(
    # If no environment variable is configured, replace the line below with your Bailian API Key: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    app_id='APP_ID',  # Replace with your actual Application ID
    prompt='Who are you?')

if response.status_code != HTTPStatus.OK:
    print(f'request_id={response.request_id}')
    print(f'code={response.status_code}')
    print(f'message={response.message}')
else:
    print(response.output.text)

Multi-Turn Conversation

Multi-turn conversations maintain context using session_id:
  1. First request: Do not provide session_id; the response will include a newly generated session_id.
  2. Subsequent requests: Include the session_id returned in the previous response to continue the conversation.
  3. Validity: session_id remains valid for 1 hour after the most recent request.
import os
from http import HTTPStatus
from dashscope import Application

def call_with_session():
    response = Application.call(
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        app_id='APP_ID',
        prompt='Who are you?')

    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        return response

    responseNext = Application.call(
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        app_id='APP_ID',
        prompt='What skills do you have?',
        session_id=response.output.session_id)

    if responseNext.status_code != HTTPStatus.OK:
        print(f'request_id={responseNext.request_id}')
    else:
        print(f'{responseNext.output.text}\n session_id={responseNext.output.session_id}')

if __name__ == '__main__':
    call_with_session()

Streaming Response

import os
from http import HTTPStatus
from dashscope import Application

responses = Application.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    app_id='APP_ID',
    prompt='Who are you?',
    stream=True,
    incremental_output=True)

for response in responses:
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        print(f'code={response.status_code}')
        print(f'message={response.message}')
    else:
        print(f'{response.output.text}')

Response Object

ParameterTypeDescription
status_codestringHTTP status code. 200 indicates success. Not returned by Java SDK — exceptions are thrown on failure.
request_idstringUnique identifier for this request. In Java SDK, returned as requestId.
codestringError code. Empty on success. Returned only by Python SDK.
messagestringDetailed error message. Ignored on success. Returned only by Python SDK.
outputobjectResult payload.
usageobjectToken usage statistics for this request.

output Properties

ParameterTypeDescription
textstringModel-generated response text.
finish_reasonstringReason for response termination: stop means natural completion; null means forced interruption (e.g., due to max length or manual stop).
session_idstringUnique identifier for the current conversation. Include in subsequent requests to retain history.
thoughtsarrayReasoning trace from deep-thinking models, visible only when has_thoughts=true.

thoughts Properties

ParameterTypeDescription
thoughtstringModel’s internal reasoning step.
action_typestringAction type returned by the LLM, e.g., reasoning for deep-thinking model steps.
action_namestringName of the executed action, e.g., “reasoning”.
actionstringExecuted step description.
action_input_streamstringStreamed input parameter result.
action_inputstringInput parameters passed to the action.

usage Properties

ParameterTypeDescription
modelsarrayList of models invoked in this request.
models[].model_idstringID of the model used.
models[].input_tokensintegerNumber of tokens in the user input.
models[].output_tokensintegerNumber of tokens in the model’s generated output.

Successful Response Example

{
    "status_code": 200,
    "request_id": "fdfc3182-bc9d-4b45-a287-cd83b13aca02",
    "code": "",
    "message": "",
    "output": {
        "text": "Hello! I am Qwen, a large-scale language model developed by Alibaba Group.",
        "finish_reason": "stop",
        "session_id": "cbb2e26ac4cc4cc3b2d114e1f73c127e",
        "thoughts": null,
        "doc_references": null
    },
    "usage": {
        "models": [
            {
                "model_id": "qwen-plus-latest",
                "input_tokens": 142,
                "output_tokens": 296
            }
        ]
    }
}

Error Response Example

request_id=1d14958f-0498-91a3-9e15-be477971967b,
code=401,
message=Invalid API-key provided.

QPM Limits

Default QPM (queries per minute) limit per application is 15,000.

Error Codes

If the API call fails and returns an error, refer to the Error Code Documentation for troubleshooting.
Overview
Managed Agent API
Sandbox API
Memory API
Flow Agent API
RAG API
Connector API
Framework Integration
Assistant API (Deprecating)
  • Overview