This guide takes you from zero to a working trace in the Mortem dashboard. You’ll create an agent, installDocumentation Index
Fetch the complete documentation index at: https://docs.mortemlabs.com/llms.txt
Use this file to discover all available pages before exploring further.
@mortemlabs/sdk, run a minimal instrumented session, and confirm that the trace appears. By the end, your bot is ready for full instrumentation.
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:
- Name your agent and choose an environment (
devnetormainnet). - Copy your API key and agent ID. The API key is shown in plaintext exactly once — copy it now.
- Copy the verify token. This one-time token proves that you control the agent on the first run. You’ll remove it after verification.
- The wizard stays open and polls until it detects your first trace. Keep this tab open while you complete the steps below.
Install the SDK
Add The onboarding wizard pre-fills the exact environment variable values for your agent. Copy them from the wizard into your
@mortemlabs/sdk to your TypeScript agent project..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.Instrument your agent
Initialize the A few things to note about this pattern:
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
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.runautomatically callssession.complete()on success andsession.fail(error)on an uncaught exception, so you don’t need to call those manually inside the callback.mortem.close()in thefinallyblock 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.
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:
| Method | Wraps |
|---|---|
mortem.wrapOpenAI(client) | OpenAI client |
mortem.wrapAnthropic(client) | Anthropic client |
mortem.wrapOllama(client) | Ollama client |
mortem.wrapLanguageModel(model) | Vercel AI SDK language model |
mortem.wrapTools(tools) | Vercel AI SDK tool definitions |
mortem.wrapConnection(conn) | Solana Connection |
mortem.langchainHandler() | LangChain callback handler |
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.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
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.
- 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.