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
import { actor, setup } from "rivetkit";
const myActor = actor({
state: { count: 0 },
actions: {
increment: (c) => {
c.state.count++;
return c.state.count;
},
},
options: {
actionTimeout: 15_000,
}
});
const registry = setup({
use: { myActor },
});
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 on every actor start after persisted state loads and before onWake. Use for repeatable schema migrations.
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 after actor starts. Does not block startup. Use for background tasks like queue processing or tick loops. If it exits, the actor follows the normal idle sleep timeout once idle. If it throws, the actor logs the error and then follows the normal idle sleep timeout once idle.
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. Defaults to an empty object.
Optional schema map for validating action argument tuples in native runtimes.
Optional schema for validating connection params in native runtimes.
Map of event names to schemas.
Map of queue names to schemas.
Actor options for timeouts and behavior configuration.
Display name for the actor in the Inspector UI.
Icon for the actor in the Inspector UI. Can be an emoji (e.g., '🚀') or FontAwesome icon name (e.g., 'rocket').
Timeout in ms for createVars handler. Default: 5000
Timeout in ms for createConnState handler. Default: 5000
Timeout in ms for onMigrate handler. Default: 30000
Timeout in ms for onBeforeConnect handler. Default: 5000
Timeout in ms for onConnect handler. Default: 5000
Max time in ms for the graceful sleep window. Covers lifecycle hooks, waitUntil, async raw WebSocket handlers, disconnect callbacks, and waiting for preventSleep to clear after shutdown starts. Default: 15000.
Graceful destroy shutdown window in ms. Default: 15000
Interval in ms between automatic state saves. Default: 1000
Timeout in ms for action handlers. Default: 60000
Deprecated. Legacy timeout in ms for waitUntil when sleepGracePeriod is not set. Default: 15000
Timeout in ms for connection liveness checks. Default: 2500
Interval in ms between connection liveness checks. Default: 5000
Deprecated. If true, the actor will never sleep. Use c.setPreventSleep(true) for bounded idle sleep delays instead. Default: false
Time in ms of inactivity before the actor sleeps. Default: 30000
Maximum number of queue messages before rejecting new messages. Default: 1000
Maximum size of each queue message in bytes. Default: 65536
Whether WebSockets using onWebSocket can be hibernated. WebSockets using actions/events are hibernatable by default. Default: false
Override RivetKit's workflow preload budget for this actor. Set to 0 to disable workflow preloading.
Override RivetKit's connections preload budget for this actor. Set to 0 to disable connections preloading.
Related
- Registry Configuration: Configure the RivetKit registry
- State: Managing actor state
- Actions: Defining actor actions
- Lifecycle: Actor lifecycle hooks