Actor Configuration
This page documents the configuration options available when defining a RivetKit actor. The actor configuration is passed to the actor() function.
Basic Example
Configuration Reference
Initial state value for the actor. Cannot be used with createState.
Function to create initial state. Receives context and input. Cannot be used with state.
Initial connection state value. Cannot be used with createConnState.
Function to create connection state. Receives context and connection params. Cannot be used with connState.
Initial ephemeral variables value. Cannot be used with createVars.
Function to create ephemeral variables. Receives context and driver context. Cannot be used with vars.
Database provider instance for the actor.
Called when the actor is first initialized. Use to initialize state.
Called when the actor is destroyed.
Called when the actor wakes up and is ready to receive connections and actions.
Called when the actor is stopping or sleeping. Use to clean up resources.
Called when the actor's state changes. State changes within this hook won't trigger recursion.
Called before a client connects. Throw an error to reject the connection.
Called when a client successfully connects.
Called when a client disconnects.
Called before sending an action response. Use to transform output.
Called for raw HTTP requests to /actors/{name}/http/* endpoints.
Called for raw WebSocket connections to /actors/{name}/websocket/* endpoints.
Map of action name to handler function.
Actor options for timeouts and behavior configuration.
Timeout in ms for createVars handler. Default: 5000
Timeout in ms for createConnState handler. Default: 5000
Timeout in ms for onConnect handler. Default: 5000
Timeout in ms for onSleep handler. Must be less than ACTOR_STOP_THRESHOLD_MS. Default: 5000
Timeout in ms for onDestroy handler. Default: 5000
Interval in ms between automatic state saves. Default: 10000
Timeout in ms for action handlers. Default: 60000
Max time in ms to wait for waitUntil background promises during shutdown. Default: 15000
Timeout in ms for connection liveness checks. Default: 2500
Interval in ms between connection liveness checks. Default: 5000
If true, the actor will never sleep. Default: false
Time in ms of inactivity before the actor sleeps. Default: 30000
Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false
Related
- Registry Configuration: Configure the RivetKit registry
- State: Managing actor state
- Actions: Defining actor actions
- Lifecycle: Actor lifecycle hooks