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.
Related References
Online Debugging: Navigate to the debugging interface via Application Card → Publish → API Debug, fill in the parameters, and click Run.
If the call fails and returns an error message, consult the Responses API reference for troubleshooting.
- Asynchronous Invocation: For long-running tasks, see the Asynchronous API Reference.
- DashScope API: For broader functionality and higher performance, see the DashScope API.
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.Quick Start: Send Your First Message
When using the Python SDK and passing a simple string (e.g.,
input="Hello"), the SDK automatically wraps it into the full JSON structure required by the API. If you use cURL or another HTTP client directly, you must manually construct the complete JSON payload.Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| input | string/array | Yes | User input content. Can be a plain string or an array of messages. |
| model | string | No | Model name — does not affect the actual model used for invocation. |
| stream | boolean | No | Whether to enable streaming output. Default: false. |
| previous_response_id | string | No | The ID of the previous response, used for multi-turn conversations. |
Response Object
| Parameter | Type | Description |
|---|---|---|
| id | string | Unique identifier for this response. |
| output | array | Array of output messages. |
| status | string | Response status, e.g., completed. |
| usage | object | Token usage information. |