Alibaba Cloud Model Studio applications overcome the limitations of large models in handling issues in private realms, retrieving the latest information, executing fixed procedures, and automatically planning complex projects. This capability significantly expands the application scope of large models.
This topic describes how to use Spring AI Alibaba to integrate applications from Alibaba Cloud Model Studio. Only agent applications and workflow applications are supported.
Add the dependencies for Spring AI Alibaba and related components to the
In the
Spring AI Alibaba uses the
Run the following code to start the Spring Boot project. Then, you can test the project using a tool such as Postman.
Model Studio applications are free to use. However, you are charged for model inference when you call models using these applications. For more information about model inference fees, see Billing items.
For more information about common error codes, see Error message.
Prerequisites
-
Obtain and configure an API key and configure the API key as an environment variable. You must name the environment variable
DASHSCOPE_API_KEYto avoid the security threat of hard coding. -
Create an Alibaba Cloud Model Studio application.
You must create one of the following application types, obtain its application ID, and set the ID as an environment variable named
APP_ID. -
If the Alibaba Cloud Model Studio application was created in a child workspace, obtain the workspace ID and set it as an environment variable named
WORKSPACE_ID.
Procedure
1. Initialize a Spring Boot project
Environment requirements
- Spring Boot 3.x
- JDK 17 or later
- Download the sample project for a quick start (Recommended) For the complete sample project, see bailian-agent.zip. After you download the code, you can skip to Step 3. Configure parameters and then proceed to Step 5. Start the Spring Boot project and test it.
- Build a project from scratch You can visit https://start.spring.io/ or use an IDE, such as IntelliJ IDEA, to create an empty Spring Boot project. Then, follow the subsequent steps.
2. Add dependencies
Add the dependencies for Spring AI Alibaba and related components to the pom.xml file of your project:
3. Configure parameters
In the application.yml file, configure the application ID, Model Studio API key, and workspace ID. The workspace ID is required only if the Model Studio application was created in a child workspace.
4. Call the Alibaba Cloud Model Studio large model application
Spring AI Alibaba uses the DashScopeAgent class to call the Alibaba Cloud Model Studio application.
5. Start the Spring Boot project and test it
Run the following code to start the Spring Boot project. Then, you can test the project using a tool such as Postman.

Billing
Model Studio applications are free to use. However, you are charged for model inference when you call models using these applications. For more information about model inference fees, see Billing items.
Error codes
For more information about common error codes, see Error message.
Learn more
- Spring AI Alibaba: Provides documentation, tutorials, hands-on blog posts, and a developer community to help you develop generative AI applications in Java.
- DashScope API Reference: Provides API descriptions and call examples for application calls.
- spring-ai-alibaba-examples: The GitHub repository with more Spring AI Alibaba sample code.