Building large language model (LLM) applications often requires creating similar prompts for different scenarios, a process that can be time-consuming and difficult to maintain. Prompt templates solve this problem by separating the fixed structure of a prompt from its dynamic variables. This lets you create reusable templates so you can manage, optimize, and generate prompts efficiently.
This topic is applicable only to the International Edition (Singapore region).
Workflow
Create a template: Create and save a template in the Alibaba Cloud Model Studio console or using an API to obtain a unique template ID.
Retrieve the template: Use the API and the template ID to retrieve the template content.
Generate the prompt: Populate the template variables with business data to generate the final prompt.
Use the template: Send the generated prompt to the target model to obtain a result.
Template types
Prompt templates are divided into pre-built prompt templates and custom prompt templates.
Dimension | Pre-built Prompt Template | Custom Prompt Template |
Source | Provided by Model Studio. They cover multiple business scenarios. | You can create custom templates in the console or using an API |
Effectiveness | Optimized for stable performance. | Designed and tested by users. The effectiveness depends on the design quality. |
Ease of use | No extra development is needed. You can call them directly from the console or using an API.
| You may need to optimize them through several iterations. This requires an understanding of prompt design principles and optimization methods, such as using clear instructions, providing examples, and applying format constraints. You also need some development and technical skills. |
Scenarios |
|
|
Modifiable | No. | Yes, as needed. |
Pre-built prompt templates
1. View templates
Go to the Prompts page to view and use the pre-built prompt templates that Model Studio provides for different scenarios.

2. View and manage templates
View: Click View Details on a template card to view the template's name, content, variables, and ID.
Manage:
Click to copy the template content.
Click . The template content is automatically populated in the prompt editor of the Agent Application. You can use it directly or modify it for your business scenario.

Click . A custom prompt template named "Pre-built Template Name_Copy_Timestamp" is created on the Prompts page.

Custom prompt templates
1. Create a template
You can create custom prompt templates in the console or using an API.
Console
Modify a pre-built prompt template
On a pre-built prompt template card, click . A custom prompt template named "Pre-built Template Name_Copy_Timestamp" is created.
Create a template based on business requirements
On the Prompts page, click Create Prompt. After you complete the configurations, click Save to create the template.

API
Obtain a workspace ID: For more information, see Get Application ID and Workspace ID.
Create a custom prompt template: Use the CreatePromptTemplate API.
2. View and manage templates
View: After you create a custom prompt template, you can view it on the Prompts page.
Manage:
Click Modify on a template card to modify the template content.
Click to copy the template content.
Click . The template content is automatically populated in the prompt editor of the Agent Application. You can use it directly or modify it for your business scenario.
Click . A custom prompt template named "Custom Template Name_Copy_Timestamp" is created on the current page.
Click to delete the created template.
Use prompt templates
Console
On a pre-built or custom prompt template, click . The template content is automatically populated in the prompt of the agent application.

Set a model for the application and enter a question to test the prompt.
API
Go to GetPromptTemplate and click Debug.
On the Parameters tab, enter the workspaceId and promptTemplateId.
workspaceId: The ID of the workspace. Get Application ID and Workspace ID.
promptTemplateId: The ID of the prompt template. Get the template ID from the template card.
Click Initiate Call to debug the API online.
SDK
Go to GetPromptTemplate and click Debug.
On the Parameters tab, enter the workspaceId and promptTemplateId. After you complete the settings, the workspaceId and promptTemplateId are automatically populated in the SDK example.
workspaceId: The ID of the workspace. Get Application ID and Workspace ID.
promptTemplateId: The ID of the prompt template. Get the template ID from the template card.
On the debug page, click SDK Sample Code.
You can run the example online, or download the full project and run it after you set the accessKeyId and accessKeySecret.
For more information about how to obtain the keys, see Obtain an AccessKey and an AgentKey.
Error codes
If a call fails and returns an error message, see Error messages to resolve the issue.
FAQ
Q: What is the difference between calling the GetPromptTemplate API and concatenating strings directly in the code?
A: The advantages of managing prompts with the GetPromptTemplate API are:
Separation of logic and content: You can update and optimize prompts in the Model Studio console without modifying or redeploying your application code.
Centralized management and collaboration: All prompts are stored centrally. This makes it easier for teams, such as prompt engineers and developers, to collaborate, manage versions, and reuse prompts.
Guaranteed consistency: Ensures that the version and structure of prompts used in different parts of an application or across different services are consistent. This avoids inconsistencies caused by manual maintenance.