Templates (SDK)
The Templates module provides methods to browse, deploy, and manage workflow templates. Templates are pre-built DAG workflows for common use cases that can be deployed in a single call.
listTemplates
Browse available templates with optional filtering.
const templates = await client.listTemplates(
options?: ListTemplatesOptions
): Promise<TemplateList>;Parameters
interface ListTemplatesOptions {
/** Filter by industry. */
industry?: 'legal' | 'finance' | 'devops' | 'marketing' | 'custom';
/** Filter by tags. */
tags?: string[];
/** Search by name or description. */
search?: string;
limit?: number;
offset?: number;
}Example
const { templates, total } = await client.listTemplates({
industry: 'legal',
search: 'contract',
});
templates.forEach((t) => {
console.log(`${t.name} (${t.id})`);
console.log(` ${t.description}`);
console.log(` Steps: ${t.steps.length}, Est. cost: $${t.estimatedCost}`);
});getTemplate
Get full details of a specific template.
const template = await client.getTemplate(templateId: string): Promise<Template>;Return Value
interface Template {
id: string;
name: string;
description: string;
version: string;
industry: string;
tags: string[];
author: string;
steps: PlanStep[];
inputSchema: JSONSchema; // Required inputs
outputSchema?: JSONSchema; // Expected output format
estimatedCost: number; // USD estimate per execution
estimatedDurationMs: number;
hitlSteps: string[]; // Steps with HITL enabled
createdAt: string;
updatedAt: string;
}deployTemplate
Deploy a template as an executable plan and run it.
const execution = await client.deployTemplate(
templateId: string,
options: DeployTemplateOptions
): Promise<PlanExecution>;Parameters
interface DeployTemplateOptions {
/** Input data matching the template's inputSchema. */
input: Record<string, unknown>;
/** Override default models for specific steps. */
modelOverrides?: Record<string, string>;
/** Override default queues for specific steps. */
queueOverrides?: Record<string, string>;
/** HITL configuration overrides. */
hitl?: HitlConfig;
/** Whether to wait for completion. Default: false */
wait?: boolean;
/** Timeout when wait=true. Default: 300000 */
timeoutMs?: number;
}Example
const execution = await client.deployTemplate('contract-review-v1', {
input: {
contract: contractText,
jurisdiction: 'New York',
reviewDepth: 'comprehensive',
},
modelOverrides: {
'analyze-risk': 'opus', // Use Opus for the risk step
},
hitl: {
requiredFor: ['analyze-risk'],
confidenceThreshold: 0.90,
},
wait: true,
timeoutMs: 180_000,
});
console.log('Review complete:', execution.status);
console.log('Report:', execution.steps['generate-report'].output);createTemplate
Publish a custom template for reuse.
const template = await client.createTemplate(
options: CreateTemplateOptions
): Promise<Template>;Example
const template = await client.createTemplate({
name: 'Weekly Report Generator',
description: 'Generates a weekly project status report from task data.',
industry: 'custom',
tags: ['reporting', 'project-management'],
inputSchema: {
type: 'object',
properties: {
projectName: { type: 'string' },
tasks: { type: 'array', items: { type: 'object' } },
period: { type: 'string', format: 'date' },
},
required: ['projectName', 'tasks'],
},
steps: [
{
id: 'categorize',
prompt: 'Categorize tasks by status and priority: {{input.tasks}}',
model: 'haiku',
},
{
id: 'summarize',
prompt: 'Write a status summary for {{input.projectName}}: {{categorize.output}}',
model: 'sonnet',
dependsOn: ['categorize'],
},
{
id: 'format',
prompt: 'Format as a professional weekly report with charts data: {{summarize.output}}',
model: 'sonnet',
dependsOn: ['summarize'],
},
],
});
console.log('Template published:', template.id);Custom templates are private to your organization by default. Set visibility: 'public' to share them in the template gallery.
Next Steps
- Template Gallery -- Browse all available templates
- Creating Templates -- Detailed template authoring guide
- Type Reference -- Full TypeScript definitions