Lifecycle & Config

Metadata

Metadata provides information about the currently running actor.

Actor ID

Get the unique instance ID of the actor:

const actorId = c.actorId;
TypeScript

Actor Name

Get the actor type name:

const actorName = c.name;
TypeScript

This is useful when you need to know which actor type is running, especially if you have generic utility functions that are shared between different actor implementations.

Actor Key

Get the actor key used to identify this actor instance:

const actorKey = c.key;
TypeScript

The key is used to route requests to the correct actor instance and can include parameters passed when creating the actor.

Learn more about using keys for actor addressing and configuration in the keys documentation.

Region

Region can be accessed from the context object via c.region.

const region = c.region;
TypeScript
c.region is only supported on Rivet at the moment.

Example Usage

import { actor, setup } from "rivetkit";

const chatRoom = actor({
  state: {
    messages: []
  },
  
  actions: {
    // Get actor metadata
    getMetadata: (c) => {
      return {
        actorId: c.actorId,
        name: c.name,
        key: c.key,
        region: c.region
      };
    }
  }
});

export const registry = setup({
  use: { chatRoom }
});

API Reference

Suggest changes to this page