Skip to main content
This guide takes you from zero to a working trace in the Mortem dashboard. You’ll create an agent, install @mortemlabs/sdk, run a minimal instrumented session, and confirm that the trace appears. By the end, your bot is ready for full instrumentation.
1

Create an agent in the dashboard

Open the Mortem dashboard and sign in. Click Add agent to open the onboarding wizard.The wizard walks you through four steps:
  1. Name your agent and choose an environment (devnet or mainnet).
  2. Copy your API key and agent ID. The API key is shown in plaintext exactly once — copy it now.
  3. Copy the verify token. This one-time token proves that you control the agent on the first run. You’ll remove it after verification.
  4. The wizard stays open and polls until it detects your first trace. Keep this tab open while you complete the steps below.
The API key and verify token are displayed once and cannot be retrieved again. If you lose them before verifying, rotate the API key from Agent settings.
2

Install the SDK

Add @mortemlabs/sdk to your TypeScript agent project.
The onboarding wizard pre-fills the exact environment variable values for your agent. Copy them from the wizard into your .env file:
.env
Do not set MORTEM_INGEST_URL for cloud usage. The SDK defaults to https://ingest.mortem.dev. Only override this variable when running against a self-hosted stack.
3

Instrument your agent

Initialize the Mortem client and wrap your agent logic in a session. The following snippet is the minimal recommended pattern — copy it into your entry point and replace the placeholder comment with your agent’s logic.
agent.ts
A few things to note about this pattern:
  • session.run(...) keeps Mortem’s async trace context active while your agent performs work. Without it, child LLM, tool, and Solana events won’t be associated with the trace.
  • session.run automatically calls session.complete() on success and session.fail(error) on an uncaught exception, so you don’t need to call those manually inside the callback.
  • mortem.close() in the finally block flushes any buffered events before the process exits. Always call it.
  • session.traceId (or equivalently, session.id) gives you the trace ID if you want to construct a direct dashboard link.
Set inputSummary to a human-readable description of what this agent run is attempting to do. It appears in the trace list and makes it much easier to identify specific runs when debugging.
4

Wrap your LLM clients and Solana connection

Pass your existing LLM client and Solana connection through Mortem’s wrappers so that every call is automatically captured as an event on the active trace. The wrappers are drop-in replacements — your agent code doesn’t change.
The full set of available wrappers is:
5

Run your agent

Run your agent once with the verify token present:
The SDK sends a batch to the ingest service containing the session start event. Because MORTEM_VERIFY_TOKEN is set, the ingest service marks your agent as verified on this first flush.Switch back to the onboarding wizard in the dashboard. Within a few seconds it will show your agent as connected and verified.
6

Remove the verify token

Once the wizard confirms verification, remove MORTEM_VERIFY_TOKEN from your environment and code. It is a one-time credential and has no effect after the first successful trace.
.env
Leave MORTEM_VERIFY_TOKEN set on the second run and the ingest service will silently ignore it — but it’s good hygiene to remove one-time credentials from your environment promptly.
7

View your trace in the dashboard

Open Agents in the dashboard and click your agent. You’ll see:
  • The live stream panel, which shows incoming trace batches in real time as your agent runs.
  • The trace list, which shows every completed run with its status, duration, token count, and cost.
Click any trace to open the trace detail view. There you can:
  • Step through the full event chronology in order
  • Inspect the payload of each LLM call, tool call, or Solana transaction
  • Read the AI-generated autopsy once analysis completes (usually within a few seconds of trace completion)
  • Share the trace via a public link for team review

What’s next

Core concepts

Understand sessions, events, and autopsies in depth before adding more instrumentation.

SDK sessions

Learn all session methods, event builders, and how trace context propagation works.

Integration guides

Full walkthroughs for Vercel AI SDK, OpenAI, Anthropic, LangChain, and Solana.

SDK events

Record custom events and understand all six built-in event types.