The execution parameters type
The input variables type
The output result type
Creates a new canvas execution instance.
Input variables to be passed to the canvas template.
Execution parameters controlling sync/async/stream behavior.
Zod schema or object schema for validating/parsing output.
HTTP client instance for making API requests.
Gets the unique execution ID assigned by the server.
Note: Streaming executions do not have an ID as they don't create a tracked execution on the server.
The execution ID.
Checks if this execution is configured for asynchronous processing.
True if async mode is enabled.
Checks if this execution is configured for streaming responses.
True if stream mode is enabled.
Checks if this execution is configured for synchronous processing.
True if sync mode is enabled (not async).
Gets the execution parameters configured for this instance.
The execution parameters or undefined.
Gets the raw API response without any processing or validation. Automatically starts execution and waits for completion (including polling for async executions).
For sync executions, returns the complete API response. For async executions, returns the polling response with status and output.
A promise resolving to the raw API result.
Gets the request ID from the x-request-id header of the execution creation request.
This is the request ID from the initial POST /v2/chat/completions request that created the execution. Each API request has its own unique request ID.
For async executions, different request IDs are available:
execution.requestId - ID from the execution creation requestpollResult.requestId - ID from each polling request (in poll events)result.requestId - ID from the final successful polling request (in success events)A promise that resolves to the request ID from the execution creation request.
const execution = await canvas.execute({ query: 'test' })
const requestId = await execution.requestId
console.log('Request ID:', requestId)
const execution = await canvas.execute({ query: 'test' }, { async: true })
// Request ID from execution creation
const creationRequestId = await execution.requestId
// Request IDs from polling
execution.on('poll', (pollResult) => {
console.log('Poll request ID:', pollResult.requestId)
})
// Request ID from final result
execution.on('success', (result) => {
console.log('Final request ID:', result.requestId)
})
execution.poll()
Gets the execution result. For async executions, automatically starts polling. For sync executions, returns the result promise. For streams, returns the generator.
The execution result as a promise or async generator.
Gets the latest known status of the execution.
Status values and transitions:
succeeded (after validation) or failed (on any error)created → running → succeeded or failedstreaming (once started)Important: Status is set to succeeded only after successful validation.
If validation fails, status will be failed even if the API request succeeded.
Use the statusChange event to track status transitions in real-time.
The current status of the execution.
Gets the task associated with this execution if it was created from an application.
The task creation result or undefined.
Cancels the ongoing execution by aborting all active requests and polling operations.
Starts polling for the execution result without waiting for the promise to resolve. This allows users to track execution progress via events rather than awaiting a promise.
The following events will be emitted during polling:
statusChange: Emitted when the execution status changes (e.g., 'created' → 'running' → 'succeeded')poll: Emitted on each polling attempt with the server responsesuccess: Emitted when the execution completes successfully with the final resulterror: Emitted if the execution failsImportant: Events are only emitted while polling is active. You must either call poll() or
await execution.result to start polling. Simply setting up event listeners without starting
polling will not trigger any events.
Note: If the execution has already completed (succeeded or failed) when fetched, the success
and error events will not fire since no polling is needed. Check the status property and
access the result directly for already-completed executions.
const execution = await canvas.getExecution('execution-id')
// Check if already completed
if (execution.status === 'succeeded' || execution.status === 'failed') {
// Access result directly - events won't fire
const result = await execution.result
console.log('Already completed:', result)
} else {
// Still running - set up events and start polling
execution.on('statusChange', (status) => {
console.log('Status:', status)
})
execution.on('success', (result) => {
console.log('Completed:', result)
})
execution.on('error', (error) => {
console.error('Failed:', error)
})
// Start polling without waiting
execution.poll()
}
Starts the execution based on configured parameters. Routes to the appropriate execution method (sync, async, or stream).
A promise or async generator depending on execution mode.
StaticfetchFetches an existing asynchronous execution by its ID.
This method retrieves the current state of an async execution and creates a new CanvasExecution instance with the fetched data. Only async executions can be fetched, as they are the only ones with persistent UUIDs on the server.
The UUID of the async execution to fetch.
Zod schema or object schema for validating/parsing output.
HTTP client instance for making API requests.
Optionaloptions: {Optional configuration for polling behavior.
OptionalisTask?: booleanWhether the execution is a task of a workstation.
OptionalpollingInterval?: string | numberTime in milliseconds between polling attempts (default: 1000).
OptionalpollingTimeout?: string | numberMaximum time in milliseconds to wait for completion (default: 60000).
A promise resolving to a CanvasExecution instance with the fetched state.
Manages the execution lifecycle of a canvas.
Handles synchronous, asynchronous (with polling), and streaming execution modes. Automatically uploads TelaFile instances and validates results based on output schema.
Status Tracking
The execution status can be accessed via the
statusproperty and tracks the lifecycle:succeededorfailed(set after validation completes)created→running→succeededorfailed(updated during polling)streaming(set when stream starts)Status is set to
failedwhen:Status is set to
succeededonly after:Fires
poll - Emitted during async polling with current status and output. Includes
requestIdfrom the polling request. (async executions only)Fires
success - Emitted when execution completes successfully with the final result. Includes
requestIdfrom the final request.Fires
error - Emitted when execution fails (only if error listeners are registered, otherwise throws)
Fires
statusChange - Emitted when execution status transitions to a new state
Example