Install the package
Set environment variables
Add these variables to your agent’s environment before starting the process.string
required
Your agent’s API key, available from the dashboard under Agent settings. An empty string disables the SDK entirely without throwing an error.
string
The agent ID shown in the dashboard. Used to associate traces with the correct agent. If you omit it here you can also pass it to
new Mortem({ agentId }) or to startSession({ agentId }).string
A one-time token shown during the onboarding wizard. Include it on the first run so Mortem can verify agent ownership. Remove it from your environment and code once the dashboard shows the agent as verified.
string
The URL of the ingest service. Defaults to
https://ingest.mortem.dev. Override this only when running ingest locally — for example, http://localhost:4001..env for local development:
.env.local
MORTEM_VERIFY_TOKEN is sent only once, on the first flush after the client is initialized. After the onboarding wizard confirms the agent is verified, you can safely delete the variable.Create the client
InstantiateMortem once at the top of your agent entry point and reuse the same instance for every session.
agent.ts
mortem.close() when the process exits to flush any buffered data:
agent.ts
Configuration reference
string
required
Your agent’s API key. Pass an empty string to disable the SDK without crashing — useful for local development where you have not yet created a Mortem agent.
string
Agent identifier. Can also be supplied per-session via
startSession({ agentId }), which overrides the client-level value.string
One-time ownership verification token from the onboarding wizard. Ignored unless
agentId is also set.string
Ingest endpoint. Defaults to
https://ingest.mortem.dev. Override for local development only."devnet" | "mainnet" | "localnet"
Tags every trace with the Solana cluster your bot is targeting. Helps filter traces in the dashboard.
boolean
Set to
false to disable all SDK behavior without removing the code. Defaults to true.MortemLogger
Optional logger that receives SDK warnings. Must implement
warn(message: string, context?): void. SDK errors are never thrown into agent code, but they will be forwarded here if a logger is provided.number
How often the buffer is flushed to the ingest service in milliseconds. Defaults to
250.number
Maximum buffer size in bytes before an early flush is triggered. Defaults to
102400 (100 KB).