Sign In
Lifecycle & Config

Metadata

Metadata provides information about the currently running actor.

Actor ID

Get the unique instance ID of the actor:

TypeScript
const actorId = c.actorId;

Actor Name

Get the actor type name:

TypeScript
const actorName = c.name;

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:

TypeScript
const actorKey = c.key;

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.

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

Example Usage

import { actor, setup } from "@rivetkit/actor";

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 }
});
Suggest changes to this page