Skip to main content

Synchronous API Reference

Synchronously invoke Alibaba Cloud Bailian applications via the OpenAI-compatible Responses API

This document describes how to synchronously invoke Alibaba Cloud Bailian applications (including Agent and Workflow applications) using the OpenAI-compatible Responses API. It is suitable for real-time interactive scenarios where you need immediate results, enabling seamless reuse of existing OpenAI codebases or rapid integration with tools from the OpenAI ecosystem.
This document applies only to legacy Agent applications (Agent 1.0). If you are using the new Agent applications (Agent 2.0), invoking the APIs described here will return a version-incompatibility error (the actual error looks like server_error: Model not found: <APP_ID>). For Agent 2.0, refer to the New Agent Application API.How to identify your application version: On the Application Management page, clicking Create Agent creates an Agent 2.0 application by default. To create an Agent 1.0 application, click the Legacy Agent creation link at the bottom of the creation dialog — the page will redirect to the legacy Bailian console.
Related References

Prerequisites

  • You have obtained an API Key and configured it in your environment variables.
  • You have created an Alibaba Cloud Bailian application and retrieved its Application ID.
  • If invoking via SDK, you must also install the OpenAI Python SDK.

Endpoint

  • SDK base_url: https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/
  • HTTP Endpoint: POST https://dashscope.aliyuncs.com/api/v2/apps/agent/{APP_ID}/compatible-mode/v1/responses
Replace {APP_ID} with your actual Application ID.
Online Debugging: Navigate to the debugging interface via Application Card → Publish → API Debug, fill in the parameters, and click Run.

Quick Start: Send Your First Message

from openai import OpenAI
import os

api_key = os.getenv("DASHSCOPE_API_KEY")
app_id = 'APP_ID'  # Replace with your actual Application ID
base_url = f'https://dashscope.aliyuncs.com/api/v2/apps/agent/{app_id}/compatible-mode/v1/'

client = OpenAI(
    api_key=api_key,
    base_url=base_url
)

response = client.responses.create(
    input="Who are you?",
)

print(response.model_dump_json(indent=2))
When invoking the API directly with cURL or other HTTP clients, input must be a message array structure (e.g., "input": [{"role": "user", "content": "..."}]). Passing a plain string is silently accepted by the server but returns an empty output without any error. The Python SDK automatically wraps a simple string (e.g., input="Hello") into the full JSON structure.

Request Parameters

ParameterTypeRequiredDescription
inputstring/arrayYesUser input content. Can be a plain string or an array of messages.
modelstringNoModel name — does not affect the actual model used for invocation.
streambooleanNoWhether to enable streaming output. Default: false.

Response Object

ParameterTypeDescription
idstringUnique identifier for this response.
outputarrayArray of output messages.
statusstringResponse status, e.g., completed.
usageobjectToken usage information.

Error Codes

If the call fails and returns an error message, consult the Responses API reference for troubleshooting.