When building large language model (LLM) applications, repeatedly constructing and fine-tuning structurally similar Prompts across different business scenarios is time-consuming and difficult to maintain. By using Prompt templates, you can separate fixed template structure from dynamic variables—enabling reusable, centrally managed, and optimized Prompt generation.
Workflow
- Create a template: Create and save a template via the Alibaba Cloud Bailian console or API, obtaining a unique template ID.
- Retrieve the template: Fetch the template content using the API and its template ID.
- Generate a Prompt: Populate template variables with business data to produce the final Prompt.
- Use the template: Send the generated Prompt to the target LLM to obtain results.
Template Types
Prompt templates fall into two categories: predefined templates and custom templates.
| Dimension | Predefined Prompt Templates | Custom Prompt Templates |
|---|---|---|
| Source | Provided by Alibaba Cloud Bailian, covering multiple common business scenarios. | Created by users via console or API. |
| Effectiveness | Optimized and stable in performance. | Effectiveness depends on user design quality; requires iterative testing and tuning. |
| Ease of Use | No additional development required—ready for immediate use via console or API. | May require multiple iterations. Users must understand Prompt engineering principles and optimization techniques (e.g., clear instructions, few-shot examples, format constraints) and possess basic development/technical skills. |
| Applicable Scenarios | General-purpose use cases, e.g., creative copywriting, office assistants. Recommended for users with limited Prompt design experience. | Complex or domain-specific needs, e.g., financial risk control, medical consultation. Required when strict output formatting is needed (e.g., JSON, lists). |
| Modifiability | Not editable. | Fully customizable per business requirements. |
Predefined Prompt Templates
Viewing
Navigate to the Prompt page to browse and use predefined Prompt templates provided by Alibaba Cloud Bailian for various scenarios.
Each template appears as a card displaying a summary of its content and its template ID. At the bottom of each card are buttons: View Details, Copy Prompt, and more actions (...).
Viewing & Managing
- View: Click a template card to see its name, content, variables, and ID.
- Copy Prompt: Click Copy Prompt to copy the full template content.
- Fill into Editor: Click ... → Fill into Editor to auto-populate the prompt editor with the template. You may use it as-is or adapt it to your business context. The pre-filled prompt includes custom variables like
${number}and${content}, designed for generating Xiaohongshu-style copy. - Duplicate: Click ... → Duplicate to create a new custom template named
"[Original Template Name]_Copy_[Timestamp]". - Code Example: Click ... → Code Example to view core SDK usage code. Note: This is a minimal working snippet—not executable standalone. For complete, runnable examples, refer to the SDK section under GetPromptTemplate – Retrieve a Prompt Template.
Custom Prompt Templates
Creation
You can create custom Prompt templates either via the console or API.
Console
- Based on a predefined template: On any predefined template card, click ... → Duplicate to generate a custom copy named
"[Predefined Template Name]_Copy_[Timestamp]". - From scratch: On the Prompt page, click + Create Prompt. Complete configuration and click Confirm to create the template. In the Prompt Template Management page, filter templates by type (All, Text Generation, Image Generation) or search by keyword. Click the top-right + Create Prompt button to start. Newly created templates appear as cards showing title, content preview, and template ID—and support editing and copying.
- Obtain your workspace ID: How to Get Workspace ID.
- Create a custom template: Use the
CreatePromptTemplateAPI.
Viewing & Managing
- View: After creation, custom templates appear on the Prompt page.
- Manage:
- Click Edit on a template card to modify its content.
- Click Copy Prompt to copy the full template content.
- Click ... → Fill into Editor to auto-populate the prompt editor. Use as-is or adapt further.
- Click View Details to view core SDK usage code in the side drawer. Note: This is a minimal working snippet—not executable standalone. For complete, runnable examples, refer to the SDK section under GetPromptTemplate – Retrieve a Prompt Template.
- Click ... → Duplicate to create a new custom template named
"[Custom Template Name]_Copy_[Timestamp]". - Click ... → Delete to remove the template permanently.
Using Prompt Templates
Console
Click ... → Create Application on any predefined or custom template card to auto-fill its content into the agent application's system prompt field.
The filled-in prompt input box shows template variables (e.g., ${name}). A character counter appears at the bottom-right corner—maximum supported length is 6,144 characters.
Configure your application's model and test the prompt by entering a sample question. In the model debugging interface, select a model (e.g., Qwen-Plus-Latest 128K) on the left and write your system instruction in the prompt area; enter a test query in the user input field on the right and click Run. Model response, along with token count statistics (input/output), appears below.
API
- Open the API reference documentation, then click Try It Out.
- Enter your
workspaceIdandpromptTemplateIdin the corresponding fields:- workspaceId: Your business workspace ID. See How to Get Workspace ID.
- promptTemplateId: The ID of either a predefined or custom template—found directly on its template card.
- Click Send Request to invoke and debug the API online.
SDK
- Open the API reference documentation, then click Try It Out.
- Enter your
workspaceIdandpromptTemplateId. Upon configuration, these values auto-populate in the SDK code samples.- workspaceId: Your business workspace ID. See How to Get Workspace ID.
- promptTemplateId: The ID of either a predefined or custom template—found directly on its template card.
- Click SDK Examples, then choose to:
- Run the example online, or
- Download the full project, configure
accessKeyIdandaccessKeySecret, and run locally. See How to Obtain Credentials for setup instructions.
- On the OpenAPI debugging page, click the SDK Examples tab on the right. Select SDK Version 2.0 (Recommended) and your preferred language (e.g., Java) to view the corresponding SDK code.
Production Deployment Best Practices
Cache template content: The response from GetPromptTemplate (i.e., the template content) remains unchanged unless the template is modified. We recommend caching this content at your application layer using templateId as the cache key. This significantly reduces redundant API calls, lowering latency and cost. When updating a template, manually invalidate—or programmatically expire—the associated cache entry.
Sample Outputs
| Template | Description | Recommended Use Cases | Template Content | Generated Output |
|---|---|---|---|---|
| Marketing Title Generator | Quickly generates eye-catching titles for various traffic channels. | Marketing & Promotion | You are a professional Xiaohongshu viral title expert. Generate 10 attention-grabbing titles about "Hangzhou Asian Games", incorporating keywords "YYDS", "Save for Later", and "Behind-the-Scenes". Each title must be ≤20 Chinese characters. | 【YYDS】Behind-the-Scenes of Hangzhou Asian Games!【Save for Later】Unmissable Highlights from Hangzhou Asian Games!Hangzhou Asian Games 【YYDS】Exclusive Interview with Gold Medalists!【Behind-the-Scenes】Full Reveal of Hangzhou Asian Games Venues!Hangzhou Asian Games 【YYDS】Gold Medal Event Recap!【Save for Later】Touching Stories of Hangzhou Asian Games Volunteers!Hangzhou Asian Games 【YYDS】Exclusive Insights from Gold Medal Coaches!【Behind-the-Scenes】Food Exploration Tour at Hangzhou Asian Games!Hangzhou Asian Games 【YYDS】Golden Moments Recap! |
| Marketing Copy Generator | One-click generation of high-quality promotional copy for diverse channels. | Marketing & Promotion | You are a professional Xiaohongshu viral marketing copy expert. Write promotional content about "Smart Bluetooth Headphones", including a title and body text, plus trending hashtag suggestions. | Title: Smart Bluetooth Headphones: Your New Music Companion Body: Tired of tangled cables? Craving music freedom anytime, anywhere? Meet our smart Bluetooth headphones! Equipped with cutting-edge Bluetooth 5.0, they deliver rock-solid connectivity and crystal-clear audio—perfect for music, movies, or gaming. Touch controls let you skip tracks or answer calls with a tap. Battery lasts up to 8 hours per charge—ideal for all-day use. Available in sleek monochrome or vibrant colors—there's a style for every personality. Order now—limited-time discount applies! Trending Hashtags: #SmartBluetoothHeadphones #WirelessAudio #TouchControl #LongBatteryLife #ColorfulOptions |
| Product Review Generator | Rapidly creates high-conversion product "recommendation" copy. | Marketing & Promotion, E-commerce | You're an experienced Xiaohongshu product reviewer. Write a Xiaohongshu-style review for "Negative-Ion Hair Dryer", covering appearance, performance, benefits, and competitive advantages to drive purchase intent. | Title: Negative-Ion Hair Dryer: Revive Your Hair's Natural Shine! Body: Still battling frizzy, dull, split ends? Try this negative-ion hair dryer! Its advanced negative-ion tech neutralizes static, leaving hair smoother and shinier. Adjustable heat settings suit quick-drying or gentle styling. Sleek, minimalist design fits beautifully in any bathroom or bedroom. Grab yours today—special offer active! Trending Hashtags: #NegativeIonHairDryer #HairCare #AdjustableHeat #SleekDesign #LimitedOffer |
| Summary Extraction | Efficient summarization tool for office and learning contexts. | Productivity Tools, Learning Aids | You're a professional article summarizer. Generate a concise summary (<200 chars) of the following text: ["Green" is one of the core concepts behind the Hangzhou Asian Games; "Zero-Waste Asian Games" embodies this green principle...] | The Hangzhou Asian Games embraces "green" principles, notably through its pioneering "Zero-Waste Asian Games" initiative—reducing solid waste via lifecycle management. Over 33 venues, 81 hotels, and 4 factories have been certified. Construction prioritized renovation over new builds, adopted prefabricated structures and recyclable materials, cut steel use by ~1/3, and deployed solar lighting saving 30% energy annually. Food waste was minimized via centralized prep and "Cloud Asian Games Village" low-carbon accounts rewarding eco-actions. |
| Copy Polishing | Refines input text per specified stylistic requirements. | Productivity Tools, Learning Aids | You're a professional copy editor. Polish this text: "The weather today is absolutely wonderful—I saw a kitten playing among flowers on my way to school. It looked so happy. After school, I shared this fun moment with Mom." Apply modern diction and rhetorical devices to make it more concise and engaging. | Original: The weather today is absolutely wonderful—I saw a kitten playing among flowers on my way to school. It looked so happy. After school, I shared this fun moment with Mom. Polished: What a glorious day! On my way to school, I spotted a kitten frolicking among blossoms—pure joy in motion. Back home, I couldn't wait to tell Mom all about it! |
| Style Rewriting | Rewrites input text in multiple specified styles. | Productivity Tools, Learning Aids | You're a professional style-rewriting expert. Rewrite this text in 3 distinct Xiaohongshu styles—each uplifting and positive: "Life feels monotonous—same routine, same commute, same desk. Yet this rhythm is common in modern society, driven by livelihood or career demands." | Xiaohongshu Style 1: Monotony? Nah—it's your canvas. Shift perspective: try something new daily. Challenge yourself. Surprise yourself. Positivity transforms routine into ritual. Xiaohongshu Style 2: Same path? Same pace? That's okay—you own the upgrade. Rise earlier for yoga. Learn coding. Book that weekend getaway. Small shifts spark big joy. Xiaohongshu Style 3: Repetition isn't emptiness—it's fertile ground. Practice gratitude. Savor micro-moments. Lend a hand. Joy blooms where intention meets action. |
| Copy Continuation | Extends input text into longer narratives (e.g., stories, articles). | Productivity Tools, Learning Aids | You're an experienced copywriter. Continue this sci-fi story (≥500 chars) with Qing Dynasty time-travel elements: "Sunday morning—I arrived on Mars." | Sunday morning—I arrived on Mars. Standing on rust-red soil beneath an ochre sky, I felt awe unlike anything Earth had ever offered. Then—a colossal snow-dusted peak loomed ahead. Drawn forward, I began the steep ascent. Hours later, atop the summit, I found a cavern pulsing with eerie blue light. Inside lay a vast laboratory—filled with humming machinery and figures in Qing Dynasty robes, meticulously calibrating instruments. "How…?" I stammered. "We are scholars of the Qing court," replied a man with a queue and spectacles. "Through chronal resonance, we crossed centuries—and worlds—to study Martian life." Stunned, I joined their mission. Together, we scanned canyons, analyzed regolith, decoded atmospheric anomalies. We discovered microbial fossils—ancient, resilient, whispering secrets of cosmic kinship. Our work demanded grit—but also wonder. Every discovery deepened our bond across time and space. And though Earth felt distant, purpose burned brighter than Mars' twin suns. |
| E-commerce Review Generator | Generates authentic, buyer-level product reviews. | E-commerce, Product Promotion | You're an experienced e-commerce buyer. Write 3 glowing 5-star reviews for "Bluetooth Massage Gun", highlighting portability and value-for-money. Each ≥50 chars. | This Bluetooth massage gun is incredibly lightweight and compact—I carry it everywhere: gym bag, suitcase, even my laptop sleeve! Pairing via phone Bluetooth is seamless, and the price? Outstanding value. Truly a game-changer. Hands down the most portable, intuitive massager I've owned. Fits effortlessly in my backpack or car cupholder. At this price point? Unbeatable ROI. My recovery just got smarter—and lighter. The best-value massage tool I've bought. As an avid runner, post-workout soreness used to derail me—until this gem. Super-light, powerful, and priced fairly. Highly recommend! |
Error Codes
If an API call fails and returns an error message, refer to the Error Code Reference for troubleshooting.
Frequently Asked Questions
What's the difference between calling GetPromptTemplate versus hardcoding string concatenation in my app?
Using GetPromptTemplate offers key advantages:
- Separation of Logic & Content: Update and optimize prompts directly in the Bailian console—no code changes or redeployments needed.
- Centralized Management & Collaboration: All prompts live in one place, enabling seamless teamwork (e.g., prompt engineers + developers), version control, and reuse.
- Consistency Assurance: Guarantees identical prompt versions and structures across all application modules or services—eliminating drift caused by manual maintenance.