compose()
Create and execute media generation pipelines
compose()
Creates a pipeline from media operations and executes them on the Synthome backend.
function compose(...nodes: VideoNode[]): Pipeline;Parameters
| Parameter | Type | Description |
|---|---|---|
nodes | VideoNode[] | Operations to include in the pipeline |
VideoNode can be any of:
generateVideo()- Video generation operationgenerateImage()- Image generation operationgenerateAudio()- Audio generation operationmerge()- Merge multiple media itemslayers()- Composite media with layeringcaptions()- Add subtitles- Another
Pipeline- Nested pipelines
Returns
Returns a Pipeline object with the following methods:
execute(options?)
Executes the pipeline and returns a PipelineExecution.
const execution = await compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A sunset",
}),
).execute();toJSON()
Returns the ExecutionPlan JSON representation. Useful for storing plans or using with executeFromPlan().
const plan = compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A sunset",
}),
).toJSON();
// plan is an ExecutionPlan objectonProgress(callback)
Registers a callback for progress updates. Returns the pipeline for chaining.
compose(generateVideo({ ... }))
.onProgress((progress) => {
console.log(`Job ${progress.completedJobs}/${progress.totalJobs}`);
})
.execute();onError(callback)
Registers a callback for error handling. Returns the pipeline for chaining.
compose(generateVideo({ ... }))
.onError((error) => {
console.error("Pipeline failed:", error.message);
})
.execute();ExecuteOptions
Options passed to execute():
interface ExecuteOptions {
apiKey?: string; // SYNTHOME_API_KEY (defaults to env var)
apiUrl?: string; // API endpoint URL
webhook?: string; // Webhook URL for async completion
webhookSecret?: string; // HMAC secret for webhook verification
baseExecutionId?: string; // Reference to parent execution
providerApiKeys?: {
// Provider API keys (auto-read from env)
replicate?: string;
fal?: string;
};
}Basic Usage
import { compose, generateVideo, videoModel } from "@anthropic/synthome-sdk";
const execution = await compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A cat playing piano",
}),
).execute();
console.log(execution.result?.url);Multi-Step Pipelines
Chain multiple operations:
import {
compose,
generateVideo,
merge,
videoModel,
} from "@anthropic/synthome-sdk";
const execution = await compose(
merge([
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "Scene 1: A sunrise",
}),
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "Scene 2: Birds flying",
}),
]),
).execute();Async with Webhooks
For long-running pipelines, use webhooks instead of blocking:
const execution = await compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A sunset",
}),
).execute({
webhook: "https://your-server.com/webhook",
webhookSecret: "your-secret",
});
// Returns immediately with execution.id
// Your webhook receives the result when completeError Handling
const execution = await compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A sunset",
}),
)
.onError((error) => {
// Handle errors
console.error("Failed:", error.message);
})
.execute();Getting the Execution Plan
Use toJSON() to get the execution plan without executing:
const pipeline = compose(
generateVideo({
model: videoModel("minimax", "replicate"),
prompt: "A sunset",
}),
);
const plan = pipeline.toJSON();
// {
// jobs: [
// {
// id: "job1",
// type: "generate",
// params: { modelId: "minimax/video-01", prompt: "A sunset" },
// output: "$job1"
// }
// ]
// }
// Execute later with executeFromPlan()
const execution = await executeFromPlan(plan);How is this guide?