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. The pending connection is not visible in c.conns until this succeeds. 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. The pending connection is not visible in c.conns while this runs.
Called when a client successfully connects. The connection is visible in c.conns before this runs.
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').
Enables the experimental Actor Runtime Socket for this actor. Default: false
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 shutdown window. Covers lifecycle hooks (onSleep, onDestroy), the run handler wait, async raw WebSocket handlers, disconnect callbacks, and final state serialization. Default: 15000.
Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0.
Deprecated. Folded into sleepGracePeriod, which now bounds the entire graceful shutdown window for both sleep and destroy. Will be removed in 2.2.0.
Interval in ms between automatic state saves. Default: 1000
Timeout in ms for action handlers. Default: 60000
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.keepAwake(promise) to scope keep-awake to a specific operation 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
Related
- Registry Configuration: Configure the RivetKit registry
- State: Managing actor state
- Actions: Defining actor actions
- Lifecycle: Actor lifecycle hooks