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.
from openai import OpenAIimport osapi_key = os.getenv("DASHSCOPE_API_KEY")app_id = 'APP_ID' # Replace with your actual Application IDbase_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.