Skip to main content
Get one complete, well-shaped trace into Lemma. The SDK sends JSON directly to the Lemma API.
Remember the one rule: one agent execution = one trace. Record model calls, tool calls, retrieval, and app logic inside that trace.

What you are building

support-agent              <- trace root (input, output)
|- draft-reply             <- generation (model, content)
`- search_docs             <- tool call (args, result)

Steps

1

Optional: install the Lemma tracing skill

If you want a coding agent to add tracing for you, install the Lemma skill from the public repo with the Skills CLI:
npx skills add uselemma/lemma --skill "lemma-tracing"
Then prompt your agent to use the Lemma tracing skill to add tracing to your application.
2

Install the SDK

npm install @uselemma/tracing
3

Set environment variables

Find these in Lemma project settings.
export LEMMA_API_KEY="lma_..."
export LEMMA_PROJECT_ID="proj_..."
4

Trace one agent execution

Create a client, open a trace, then record one-off generation and tool events inside the trace callback.
import { Lemma } from "@uselemma/tracing";

const lemma = new Lemma();

const answer = await lemma.trace(
  {
    name: "support-agent",
    input: userMessage,
    threadId: conversationId,
    userId: user.id,
  },
  async (trace) => {
    const docs = await searchDocs(userMessage);
    trace.recordTool({
      name: "search_docs",
      input: { query: userMessage },
      output: docs,
    });

    const response = await callModel(userMessage, docs);
    trace.recordGeneration({
      name: "draft-reply",
      input: response.messages,
      output: response.text,
      model: "gpt-4o",
    });

    return response.text;
  },
);
5

Verify in Lemma

Open the Lemma dashboard -> Traces. Within seconds you should see:
  • One trace for the whole execution.
  • The root trace with input and output.
  • A nested generation with model metadata.
  • A nested tool call with arguments and result.

What’s next

Trace contract

The exact shape Lemma reads.

Concepts

Traces, spans, generations, and threads.

Lemma tracing skill

Install the Lemma skill from the public repo.

Threads & context

Group conversations and attach users.

Instrument an agent

Build up a full trace with generations, tools, spans, and errors.

Vercel AI SDK

Record AI SDK model calls and tool executions.