Wrapper methods instrument your existing provider clients without requiring you to emit events manually. Pass a client to the appropriate wrapper, use the returned client in place of the original, and Mortem records every LLM call, tool invocation, and Solana transaction as a typed event inside the active session. All wrappers use structural typing — the SDK does not import or hard-depend on any provider package. Your bundle size is unaffected if a provider is not installed, and wrappers work across provider versions as long as the underlying API shape matches.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.
Wrappers only emit events when called inside an active
session.run() context. If a wrapped client is called outside a session, the original method runs unchanged with no instrumentation overhead.OpenAI
Wrap your OpenAI client once at startup and use it everywhere in your agent. The wrapper instrumentschat.completions.create for both streaming and non-streaming responses.
Anthropic
Wrap your Anthropic client in the same way. The wrapper instrumentsmessages.create and captures streaming content deltas, tool use blocks, and token usage.
Ollama
Wrap the Ollama client to captureollama.chat calls, including JSON-mode requests and streamed responses. Ollama costs are billed externally through ollama.com, so the dashboard shows usage as tracked externally rather than as a USD estimate.
Vercel AI SDK
UsewrapTools and wrapLanguageModel together to instrument Vercel AI SDK agent loops. wrapTools patches each tool’s execute function to emit tool_call events. wrapLanguageModel patches doGenerate and doStream to emit llm_call events.
LangChain
Usemortem.langchainHandler() to get a callback handler and add it to your LangChain chains or agents. The handler captures LLM start/end/error and tool start/end/error events without a hard dependency on @langchain/core.
BaseCallbackHandler for compatibility with stricter LangChain type checks, use the async factory instead:
createLangChainHandlerAsync dynamically imports @langchain/core/callbacks/base at runtime and returns a proper subclass when it is available, falling back to the structural handler if LangChain is not installed.
Solana web3.js Connection
Wrap your SolanaConnection to record sendRawTransaction and sendTransaction calls as solana_tx events. The wrapper also polls for confirmation in the background and updates the event with the confirmation status.
mainnet, devnet, or localnet) and records instruction names from sendTransaction calls where the transaction object exposes them.
Wrapper method reference
| Method | Patches | Event type emitted |
|---|---|---|
mortem.wrapOpenAI(client) | client.chat.completions.create | llm_call |
mortem.wrapAnthropic(client) | client.messages.create | llm_call |
mortem.wrapOllama(client) | client.chat | llm_call |
mortem.wrapTools(tools) | Each tool’s execute function | tool_call |
mortem.wrapLanguageModel(model) | model.doGenerate, model.doStream | llm_call |
mortem.langchainHandler() | LangChain callback lifecycle | llm_call, tool_call |
mortem.wrapConnection(conn) | conn.sendRawTransaction, conn.sendTransaction | solana_tx |