npx skills add ...
npx skills add rivet-dev/skills --skill rivetkit-client-rust
RivetKit Rust client guidance. Use for Rust clients and backends that connect to Rivet Actors with rivetkit::client, create typed actor handles, call actions, or manage connections.
npx skills add rivet-dev/skills --skill rivetkit-client-rust
Use this skill when building Rust clients that connect to Rivet Actors with rivetkit::client.
RivetKit version: 2.3.7
Client::new(ClientConfig::new(endpoint)) and call typed actions with get_or_create_typed_default::<A>(...).anyhow::Result with ?.match arms unless absolutely needed.Rust support is in beta. The supported public Rust API is rivetkit and rivetkit::client; lower-level crates are internal implementation details and do not carry a stability guarantee. See the full API reference on docs.rs/rivetkit, or the runnable hello-world-rust example.
See the Rust quickstart guide for getting started.
Add the rivetkit crate and its companions:
The Rust client is strongly typed. It shares the same action and event types as your actor, so define your actor in src/lib.rs and import those types from both your server and your client. There is no need to redefine the actor on the client. See Define Your Actor in the quickstart for the actor definition this page builds on.
counter here is your crate name (the package name in Cargo.toml, with dashes as underscores). Counter and Increment are the types you defined alongside your actor.
A stateless call on the handle opens a short-lived request per action. A connection keeps a WebSocket open so you can receive events and reuse it across calls.
get_typed_default / get_or_create_typed_default use default options. The non-default variants (get_typed / get_or_create_typed) take GetOptions / GetOrCreateOptions for connection parameters, input, and region. Set pool_name on GetOrCreateOptions or CreateOptions to override the client's configured pool for a single actor.
Pass connection parameters through the handle options. They are delivered to the actor's create_conn_state callback:
on registers a typed callback for an event and returns once the subscription is registered:
Event callbacks are synchronous and run for every matching event. The actor's emitted event type (here NewCount) is decoded into the typed value for you.
The lower-level connection exposes lifecycle callbacks and the current status. Reach it with connection.inner():
ConnectionStatus is one of Idle, Connecting, Connected, or Disconnected. Connections reconnect automatically with backoff until you call disconnect.
For actors that implement on_request or on_websocket, call them directly on the untyped handle (handle.inner()). fetch returns a reqwest::Response, and web_socket returns a tokio_tungstenite stream. This example also needs a few extra crates:
The client is a normal Tokio type, so you can hold it in your backend (Axum, Actix, etc.) and call actors from request handlers. The client is Clone and cheap to share:
Action and connection calls return anyhow::Result. Actor-side errors surface as an anyhow::Error carrying the error group, code, message, and metadata:
Keys uniquely identify actor instances. Use compound keys (arrays) for hierarchical addressing:
Keys accept arrays of &str or String (["org-acme", "general"]). Don't build keys with string interpolation like format!("org:{user_id}") when user_id contains user data. Use arrays instead to prevent key injection attacks.
ClientConfig::new(endpoint) is a builder. The endpoint is always required; there is no default. Common options:
namespace - target namespace (defaults to the engine's configured namespace).token - authentication token for the engine.pool_name - runner pool to target.header / headers - extra HTTP headers sent with each request.max_input_size - cap on encoded action input size.For serverless deployments, set the endpoint to your app's /api/rivet URL. See Endpoints for details.
See the full client API documentation on docs.rs/rivetkit-client.
If you need more about Rivet Actors, registries, or server-side RivetKit, add the main skill:
Then use the rivetkit skill for backend guidance.