Steps are the fundamental building blocks in Motia. Each step represents a unit of work that can be triggered by various events, execute business logic, and interact with other steps through queues.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/motiadev/motia/llms.txt
Use this file to discover all available pages before exploring further.
What is a step?
A step consists of two parts:- Configuration: Defines the step’s name, triggers, and output queues
- Handler: The async function that executes when the step is triggered
Creating a step
Motia provides two syntaxes for defining steps:- TypeScript
- JavaScript
- Python
Step configuration
The step configuration object defines the step’s behavior and connections:Required fields
Unique identifier for the step
Array of triggers that can invoke this step. See Triggers for details.
Optional fields
Human-readable description of what the step does
Queue topics this step can publish to. Use with
ctx.enqueue()Flow names this step belongs to, for logical grouping
Additional files to bundle with the step deployment
Configure handler resources and queue behavior:
handler.ram: Memory in MB (default: 128)handler.cpu: CPU units (optional)handler.timeout: Timeout in seconds (default: 30)queue.type: “fifo” or “standard” (default: “standard”)queue.maxRetries: Retry attempts (default: 3)queue.visibilityTimeout: Visibility timeout in seconds (default: 30)
Step handler signature
Handlers receive two parameters:- TypeScript
- Python
Input parameter
The input type depends on the trigger:- HTTP triggers:
MotiaHttpArgswith request/response objects - Queue triggers: The queue message data
- Cron triggers:
undefined(no input) - State triggers:
StateTriggerInputwith old/new values - Stream triggers:
StreamTriggerInputwith event data
Context parameter
Thectx parameter provides access to Motia’s runtime features. See FlowContext for full details.
Multi-trigger steps
Steps can respond to multiple trigger types:- TypeScript
- Python
Type inference
Motia automatically infers types from your configuration:- TypeScript
Step lifecycle
- Trigger fires: HTTP request, queue message, cron schedule, state change, or stream event
- Input validation: Schema validation if defined in trigger config
- Handler execution: Your async handler function runs
- Response handling:
- HTTP: Return
ApiResponseobject - Queue/Cron: Return nothing or throw error for retry
- State/Stream: Return any value
- HTTP: Return
- Error handling: Errors trigger retries based on infrastructure config
Best practices
Single responsibility
Keep each step focused on one task. Use multiple steps connected by queues for complex workflows.
Idempotency
Design handlers to be safely retryable. Use idempotency keys for external API calls.
Type safety
Define schemas for inputs and outputs to catch errors at build time.
Error handling
Let transient errors throw for automatic retry. Handle permanent failures explicitly.
Next steps
Triggers
Learn about the five trigger types
Context API
Explore FlowContext capabilities
Handlers
Handler patterns and best practices
State management
Working with persistent state