Skip to main content
mirrorkit on npm is the TypeScript sibling of the Python package. Point it at your AI SDK / Anthropic / OpenAI / LangChain.js calls and your agent’s traces stream to Mirrors with negligible overhead: non-blocking, background-batched, and it never throws into your app.

How do I install the TypeScript collector?

Run npm install mirrorkit. It requires Node ≥ 18 (it uses the built-in fetch) and has zero runtime dependencies of its own.
The LLM SDKs are optional peers, instrumented only if present.

How do I start collecting traces from a Node agent?

Call init() with your workspace key and project name, then wrap each SDK client once with instrument(). That is the whole integration: two lines plus one wrap per client, and no change to how you call the model.
init() also best-effort auto-instruments importable SDKs, so in many setups the instrument() call is optional. We recommend instrument() anyway: it is immune to the ESM/CJS dual-instance and version-drift issues that make global patching unreliable in JS.

Options

How do I trace the Vercel AI SDK?

Wrap the model, not the call. Every AI SDK entry point (generateText, streamText, ToolLoopAgent, your useChat route) runs through the model you hand it, so one instrument() covers all of them, including the whole tool loop:
Each model call becomes one trace: the cumulative message history (with tool calls and their results paired by toolCallId) plus the model’s reply. A multi-step agent run therefore arrives as a sequence of traces whose history grows, the same shape our Anthropic and OpenAI instrumentations produce. Streaming is captured here (streamText included): the parts are observed as they pass through and assembled at the end, so your stream is untouched.
instrument() is the seam because ai’s exports are a frozen ES module namespace with no prototype to patch, so auto-install at init() cannot reach them. Wrap the model once, where you construct it.
Already persisting chats (useChat messages via onFinish, or a generateText result)? Upload them as-is; Mirrors flattens AI SDK UIMessage parts, ModelMessage content blocks, and steps results server-side. See the collect API reference.

How do I trace LangChain.js?

LangChain.js has no global handler hook, so attach the handler explicitly, either per call or by wrapping the runnable:
LangChain.js support is best-effort. Validate against your pinned @langchain/core version. Anthropic and OpenAI are the fully-solid path.

How do I log a trace manually?

Call mirrorkit.logTrace() with an OpenAI-style message array. This is the path for anything not auto-instrumented:

Can I trace a framework that isn’t supported out of the box?

Yes. Providers are pluggable: register your own to trace a framework that isn’t covered out of the box:
register() works before or after init().

How do I make sure traces are sent before my process exits?

The collector drains on Node’s beforeExit. For deterministic delivery in serverless or short-lived processes, flush explicitly:

API

Known limitations

  • Streaming is captured for the AI SDK, but Anthropic/OpenAI stream: true calls are still passed through untraced. Non-streaming calls are fully captured everywhere.
  • Auto-instrumentation can miss if your app loads a different copy of an SDK than init() resolves (ESM/CJS duplication). instrument() is unaffected.
  • LangChain.js is best-effort (see above).