The Mortem SDK is the single package your agent needs to start sending traces. Install it, set your credentials, and create a client — that is everything required before you start recording sessions and events.Documentation Index
Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
Use this file to discover all available pages before exploring further.
Install the package
Set environment variables
Add these variables to your agent’s environment before starting the process.Your agent’s API key, available from the dashboard under Agent settings. An empty string disables the SDK entirely without throwing an error.
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 }).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.
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
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.
Agent identifier. Can also be supplied per-session via
startSession({ agentId }), which overrides the client-level value.One-time ownership verification token from the onboarding wizard. Ignored unless
agentId is also set.Ingest endpoint. Defaults to
https://ingest.mortem.dev. Override for local development only.Tags every trace with the Solana cluster your bot is targeting. Helps filter traces in the dashboard.
Set to
false to disable all SDK behavior without removing the code. Defaults to true.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.How often the buffer is flushed to the ingest service in milliseconds. Defaults to
250.Maximum buffer size in bytes before an early flush is triggered. Defaults to
102400 (100 KB).