Create Prompt Sets
In this tutorial you will create a prompt template in the Prompt Lab, test it with sample input, and publish it for use by your agents and workflows.
Prerequisites
- A Chainabit account with a valid access token
curlavailable in your terminal- An existing workspace (see Workspaces API)
Set your environment variables:
bash
export TOKEN="your-access-token"
export WORKSPACE_ID="ws_01HQ..."Prompt Lab Flow
Step 1: Create a Prompt Template
Define a reusable prompt template with variable placeholders:
bash
curl -s -X POST "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/prompt-lab/templates" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Weekly Report Generator",
"description": "Generates a weekly activity report from completion data",
"template": "You are a productivity analyst. Given the following activity data for the week of {{weekOf}}:\n\n{{activityData}}\n\nGenerate a concise weekly report that includes:\n1. Overall completion rate\n2. Longest streaks\n3. Areas for improvement\n4. One motivational insight",
"variables": ["weekOf", "activityData"],
"modelId": "model_01HQ..."
}'javascript
const res = await fetch(
`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/prompt-lab/templates`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Weekly Report Generator',
description:
'Generates a weekly activity report from completion data',
template:
'You are a productivity analyst. Given the following activity data for the week of {{weekOf}}:\n\n{{activityData}}\n\nGenerate a concise weekly report that includes:\n1. Overall completion rate\n2. Longest streaks\n3. Areas for improvement\n4. One motivational insight',
variables: ['weekOf', 'activityData'],
modelId: 'model_01HQ...',
}),
},
);
const data = await res.json();
console.log(data);python
import requests
res = requests.post(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/prompt-lab/templates",
headers={
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
},
json={
"name": "Weekly Report Generator",
"description": "Generates a weekly activity report from completion data",
"template": "You are a productivity analyst. Given the following activity data for the week of {{weekOf}}:\n\n{{activityData}}\n\nGenerate a concise weekly report that includes:\n1. Overall completion rate\n2. Longest streaks\n3. Areas for improvement\n4. One motivational insight",
"variables": ["weekOf", "activityData"],
"modelId": "model_01HQ...",
},
)
print(res.json())Response:
json
{
"data": {
"id": "tmpl_01HQA...",
"name": "Weekly Report Generator",
"status": "draft",
"variables": ["weekOf", "activityData"],
"createdAt": "2026-03-17T10:00:00.000Z"
}
}Save the template ID:
bash
export TEMPLATE_ID="tmpl_01HQA..."Step 2: Test the Template
Run the template with sample variable values to preview the output:
bash
curl -s -X POST "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/prompt-lab/templates/$TEMPLATE_ID/test" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"variables": {
"weekOf": "March 10, 2026",
"activityData": "Push-ups: 5/7 days, Running: 7/7 days, Meal Prep: 4/7 days, Stretching: 6/7 days"
}
}'javascript
const res = await fetch(
`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/prompt-lab/templates/${TEMPLATE_ID}/test`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
variables: {
weekOf: 'March 10, 2026',
activityData:
'Push-ups: 5/7 days, Running: 7/7 days, Meal Prep: 4/7 days, Stretching: 6/7 days',
},
}),
},
);
const data = await res.json();
console.log(data);python
res = requests.post(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/prompt-lab/templates/{TEMPLATE_ID}/test",
headers={
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
},
json={
"variables": {
"weekOf": "March 10, 2026",
"activityData": "Push-ups: 5/7 days, Running: 7/7 days, Meal Prep: 4/7 days, Stretching: 6/7 days",
},
},
)
print(res.json())Response:
json
{
"data": {
"output": "## Weekly Report: March 10, 2026\n\n**Overall Completion Rate:** 79% (22/28 activities)\n\n**Longest Streak:** Running at 7 consecutive days.\n\n**Areas for Improvement:** Meal Prep had the lowest completion at 57%. Consider batch-cooking on Sundays.\n\n**Insight:** Your running consistency is remarkable. Apply that same discipline to meal prep by pairing it with an existing habit.",
"tokensUsed": 198,
"latencyMs": 1240
}
}Step 3: Publish the Template
Once you are satisfied with the output, publish the template to make it available:
bash
curl -s -X PATCH "https://api.chainabit.com/api/v1/workspaces/$WORKSPACE_ID/ai/prompt-lab/templates/$TEMPLATE_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"status": "published"
}'javascript
const res = await fetch(
`https://api.chainabit.com/api/v1/workspaces/${WORKSPACE_ID}/ai/prompt-lab/templates/${TEMPLATE_ID}`,
{
method: 'PATCH',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ status: 'published' }),
},
);
const data = await res.json();
console.log(data);python
res = requests.patch(
f"{BASE}/workspaces/{WORKSPACE_ID}/ai/prompt-lab/templates/{TEMPLATE_ID}",
headers={
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
},
json={"status": "published"},
)
print(res.json())Response:
json
{
"data": {
"id": "tmpl_01HQA...",
"name": "Weekly Report Generator",
"status": "published",
"updatedAt": "2026-03-17T10:03:00.000Z"
}
}Summary
In this tutorial you:
- Created a prompt template with variable placeholders
- Tested the template with sample input data
- Published the template for production use
Next Steps
- Chain Triggers to run chains (workflows) that use prompt templates
- Create an AI Agent to attach templates to agents
- Prompt Lab API Reference for all available endpoints