Prompt templates let you separate the fixed structure of a prompt from its dynamic variables, creating reusable templates for unified management, optimization, and efficient prompt generation.
This topic is applicable only to the Chinese Mainland Edition (Beijing region).
Workflow
-
Create a template: Create and save a template in the Model Studio console or by 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 a prompt: Fill in the template variables with your business data to generate the final prompt.
-
Use the template: Send the generated prompt to the target model to get results.
Template types
Prompt templates fall into two categories: built-in prompt templates and custom prompt templates.
|
Dimension |
Built-in |
Custom |
|
Source |
Provided by Model Studio to cover a wide range of business scenarios. |
|
|
Effectiveness |
Pre-optimized to ensure stable performance. |
Effectiveness depends on the quality of your design and testing. |
|
Usability |
Ready to use without additional development. You can call them directly from the console or by using an API.
|
May require multiple iterations of refinement. You must be familiar with prompt design principles and optimization methods, such as providing clear instructions, few-shot examples, and format constraints. Basic development and technical skills are also required. |
|
Common scenarios |
|
|
|
Editable |
No. |
Yes. You can modify templates based on your needs. |
Built-in prompt templates
1. View templates
On the Prompts page, you can view and use the built-in prompt templates that Model Studio provides for different scenarios.
Each prompt template is shown on a card that displays a content preview and its template ID. The card includes buttons for View Details, Copy prompt, and more actions (...).
2. View and manage templates
View: Click View Details on a template card to view its name, content, variables, ID, and other information.
Manage:
-
Click to copy the template content.
-
Click . The template content is automatically populated in the prompt editor for the Agent Application. You can use the content as-is or modify it based on your business scenario.
The populated prompt contains the custom variables
${number}and${content}for generating content in the Xiaohongshu style. -
Click to view code examples for calling the prompt template. These are core code examples and cannot be run directly. For a complete code example, see the SDK example in GetPromptTemplate - Get a prompt template.
-
Click to create a custom prompt template on the Prompts page. The new template is named "Built-in Prompt Template Name_Copy_Timestamp".
The copied template card displays a preview of the template content and the template ID (click the icon on the right to copy it). The bottom of the card provides buttons for Edit, Copy prompt, and more actions.
Custom prompt templates
1. Create a template
You can create custom prompt templates in the console or by using an API.
Console
-
Modify a built-in prompt template
On a built-in prompt template card, click to create a copy named "Built-in Prompt Template Name_Copy_Timestamp".
-
Create a template based on your business needs
On the Prompts page, click Create Prompt. After you complete the configuration, click Save to create the template. For more information, see Custom prompt templates. On the prompt template management page, you can find existing templates by using the type filters (All, Text Generation, and Image Generation) or the search bar. Click + Create Prompt in the upper-right corner to create a new prompt template. Created templates are displayed as cards that show the template title, a content preview, and the template ID, with options to Edit and Copy prompt.
API
-
Get your workspace ID: For more information, see Get an app ID and a workspace ID.
-
Create a custom prompt template: Use the CreatePromptTemplate API operation.
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 change its content.
-
Click to copy the template content.
-
Click . The template content is automatically populated in the prompt editor for the Agent Application. You can use the content as-is or modify it based on your business scenario.
-
Click to view code examples for calling the template. These are core code examples and cannot be run directly. For a complete code example, see the SDK example in GetPromptTemplate - Get a prompt template.
-
Click to create a copy on the current page named "Custom Prompt Template Name_Copy_Timestamp".
-
Click to delete the template.
Use prompt templates
Console
-
Click on a built-in or custom prompt template card. The template content automatically populates the prompt field of the Agent Application.
Template variables, such as
${name}, are visible in the prompt input box. A character counter in the lower-right corner shows the current count, with a maximum of 6,144 characters. -
Set a model for the application and enter a question to test the prompt.
On the left side of the model debugging page, select a model, such as Qwen-Plus-Latest 128K, and write system instructions in the prompt area. On the right side, enter a test question in the user input area and click Run. The model's response and token statistics for the input and output are displayed below.
API
-
Open the GetPromptTemplate API reference and click Debug.
-
In the Configure Parameters panel, enter your workspaceId and promptTemplateId.
-
workspaceId: Your workspace ID. For more information, see Get an app ID and a workspace ID.
-
promptTemplateId: The ID of a built-in or custom prompt template. You can find the ID on the template card.
-
-
Click Initiate Call to debug the API operation online.
Example of a successful call:
{ // Schema of Response "variables": [ // A list of template variables "platform", // A template variable "topic", // A template variable "num1", // A template variable "num2" // A template variable ], "promptTemplateId": "cfec40c311f14f3e976403059d8f0116", // The template ID "requestId": "8C616xxx", // The request ID "name": "Marketing Copy Generation", // The template name "content": "You are a professional marketing copywriter with extensive experience on the ${platform} platform. Now, please write a highly engaging piece of ${platform} marketing content with \"${topic}\" as the core theme. The content must include a captivating and SEO-friendly title, and a detailed and emotionally compelling body. In the body, please insert at least ${num1} different emoji to increase interactivity and visual appeal. Additionally, based on this theme, design and provide up to ${num2} popular recommended tags that highly summarize the theme and attract the target audience.", // The template content }
SDK
-
Open the GetPromptTemplate API reference and click Debug.
-
In the Configure Parameters panel, enter the workspaceId and promptTemplateId. After you enter the parameters, the workspaceId and promptTemplateId are automatically populated in the SDK example.
-
workspaceId: Your workspace ID. For more information, see Get an app ID and a workspace ID.
-
promptTemplateId: The ID of a built-in or custom prompt template. You can find the ID on the template card.
-
-
On the debugging page, click SDK Example.
-
Run the example online, or download the complete project, set your accessKeyId and accessKeySecret, and then run it.
For more information about how to obtain an AccessKey, see Obtain an AccessKey and AgentKey.
On the right side of the OpenAPI Explorer page, click the SDK Example tab. Select the SDK version V2.0 (Recommended) and your target language, such as Java, to view the corresponding SDK example code.
Examples
|
Template |
Description |
Recommended scenarios |
Template content |
Generated output |
|
Marketing Title Generation |
Generates eye-catching titles for various channels. |
Marketing and promotion |
You are an expert at writing viral titles for [Xiaohongshu]. Generate [10] eye-catching titles on the theme of the [Hangzhou Asian Games], using the keywords [YYDS, bookmark, reveal]. Each title must be under [20] characters. |
|
Error codes
If a call fails and an error message is returned, see error codes to resolve the issue.
FAQ
Q: What is the difference between calling the GetPromptTemplate API and concatenating strings directly in your code?
A: Using the GetPromptTemplate API to manage prompts offers the following advantages:
-
Separate logic from content: You can update and optimize prompt content in the Model Studio console without modifying or redeploying your application code.
-
Centralized management and collaboration: Storing all prompts in a central location makes it easy for teams, such as prompt engineers and developers, to collaborate, manage versions, and reuse templates.
-
Consistency: Ensures the same prompt version and structure are used across different parts of your application or between different services, which avoids inconsistencies caused by manual maintenance.