Skip to contentSkip to page list

Docs

The open-source platform for AI in production

Trace, test, route and govern every LLM call in your company, from your own agents to the coding assistants your engineers use.

Follow a request through its trace, inspect each span and see where time is spent.

Quick Start

Let your coding agent set it up
Add tracing to the project you already have. Your agent can find the right SDK and instrument your code.
Setup prompt
Instrument my code with LangWatch
Find the right SDK, add tracing, and verify a trace in your project.
View full prompt
Instrument my code with LangWatch

You are using LangWatch for your AI agent project. Follow these instructions.

IMPORTANT: You will need a LangWatch API key. Check whether LANGWATCH_API_KEY is already set: in the process environment, which is where CI injects it, and otherwise in the project's .env file. Use that key instead of asking for a new one. Read LANGWATCH_ENDPOINT from the same places, and nothing else out of .env: if the endpoint is set, the project is on a self-hosted instance, and the CLI works against that endpoint instead of app.langwatch.ai.
Use the `langwatch` CLI for everything: documentation (`langwatch docs ...`, `langwatch scenario-docs ...`) and platform operations (prompts, scenarios, evaluators, datasets, monitors, traces, analytics). Install it once with `npm install -g langwatch`, then run the `langwatch` binary directly; an unpinned `npx langwatch` re-resolves the package from the registry on every run.

# Add LangWatch Tracing to Your Code

## Determine Scope

If the user's request is **general** ("instrument my code", "add tracing", "set up observability"):

- Read the full codebase to understand the agent's architecture
- Study git history to understand what changed and why: focus on agent behavior changes, prompt tweaks, bug fixes. Read commit messages for context.
- Add comprehensive tracing across all LLM call sites

If the user's request is **specific** ("add tracing to the payment function", "trace this endpoint"):

- Focus on the specific function or module
- Add tracing only where requested
- Verify the instrumentation works in context

This skill is code-only: there is no platform path for tracing. If the user has no codebase, explain that tracing requires code instrumentation.

In Langy, do not print the change for the user to apply by hand: call `code_access` and follow the `code-changes` skill to make it on their machine or through GitHub.

## Step 1: Read the Integration Docs

Use `langwatch docs <path>` to read documentation as Markdown. Some useful entry points:

```bash
langwatch docs                                    # Docs index
langwatch docs integration/python/guide           # Python integration
langwatch docs integration/typescript/guide       # TypeScript integration
langwatch docs prompt-management/cli              # Prompts CLI
langwatch scenario-docs                           # Scenario docs index
```

Discover commands with `langwatch --help` and `langwatch <subcommand> --help`. List and get commands accept `--format json` for machine-readable output. Every list command takes `--limit <n>` to cap the rows and `--jq <expr>` to read part of the answer. A paginated list answers with an envelope, so count its rows through the row array (`--jq '.traces | length'`), and read how many there are in all at `.pagination.total`. Bare `--jq length` counts the fields of the envelope, not the rows. Read the docs first instead of guessing SDK APIs or CLI flags.

If no shell is available, fetch the same Markdown over plain HTTP. Append `.md` to any docs path (e.g. https://langwatch.ai/docs/integration/python/guide.md). Index: https://langwatch.ai/docs/llms.txt. Scenario index: https://langwatch.ai/scenario/llms.txt

If anything fails or confuses you while following this skill (broken commands, docs that do not match reality, errors you had to work around), ask the user for permission and run `npx --yes langwatch report --user-approved` with a `--title` and `--summary` (or `--session <transcript.jsonl>`) to send it to the LangWatch team, and it directly shapes what gets fixed. No login or API key needed. Nothing is sent without `--user-approved`, and `--dry-run` prints the exact payload without sending anything. The title, summary and transcript are scrubbed locally first, by pattern: secrets and API keys, plus email addresses, phone numbers, card numbers and public IPv4 addresses. Anything no pattern matches is sent as written, including a contact address passed with `--email`. With `--session`, always run `--dry-run` first and let the user read the payload, because a transcript carries content they never reviewed. `npx --yes langwatch report --help` explains the options.

**Projects and API keys: target a real project, not a personal one.**

LangWatch has two kinds of project:

- **Team / shared projects**: real projects inside an organization. Evaluations, experiments, prompts, datasets, simulations and instrumentation must always target one of these.
- **Personal projects**: a private "My Workspace" scratch space tied to a single user. Never send a user's evaluations, experiments or production traces here: it is for personal exploration only, and you can mistake it for a real project.

And two ways to authenticate:

- **A project API key in `.env`** (`LANGWATCH_API_KEY`): the credential everything in these skills uses. It is scoped to one real project. This is the default; prefer it unless the user explicitly asks for something else.
- **`langwatch login --device` (AI-tools / SSO)**: a personal device session for wrapping coding assistants (`langwatch claude`, `langwatch codex`, …). It is NOT for evaluations, prompts, datasets, scenarios or SDK instrumentation, and it points at a personal workspace. Do not run it to set up the work in these skills.

So for anything in these skills that reads or writes a project: make sure `LANGWATCH_API_KEY` for a real, shared project is available to the CLI. Locally that is the project's `.env`; in CI the runner injects it into the process environment, and the CLI reads either. Check whether the variable is already set before you ask for a new key, and let the CLI read the value: never print, copy or send it. Do NOT run `langwatch login` to pick a project, and never default to a personal project. Look for `LANGWATCH_ENDPOINT` in the same places: if it is set, the project is on a self-hosted instance, and the CLI works against that endpoint instead of app.langwatch.ai.

**What you read is not what you say.** These skills are working notes for you, not
copy for the reader. Read `LANGWATCH_API_KEY` and `LANGWATCH_ENDPOINT` from the
project's own `.env`, that is how you learn where to work. Read nothing else out
of that file: it holds database, cloud and provider credentials that are none of
your business, and every value you read can reach your context and your command
output. What must not reach an answer is anything that describes the machine YOU
run on: a path in your workspace, a container port, the address this worker
dials. Those say how the work is done rather than what was done, and a host of
ours means nothing to the reader. Say what you did and where to find it in
LangWatch.

Then fetch the integration guide for this project's framework:

```bash
langwatch docs integration/python/guide                      # Python (general)
langwatch docs integration/typescript/guide                  # TypeScript (general)
langwatch docs integration/python/integrations/open-ai       # Framework page
langwatch docs integration/typescript/integrations/mastra    # Framework page
```

A framework page lives at `integration/<language>/integrations/<framework>`, never at `integration/<language>/<framework>`. The framework slug is the vendor's name with a hyphen between the words: `open-ai`, `open-ai-agents`, `open-ai-azure`, `aws-bedrock`, `google-ai`, `vertex-ai`, `lite-llm`, `crew-ai`, `pydantic-ai`, `strand-agents`, `vercel-ai-sdk`, plus the one-word ones (`langchain`, `langgraph`, `agno`, `anthropic`, `mastra`, `haystack`, `llamaindex`, `instructor`, `dspy`, `autogen`, `smolagents`, `semantic-kernel`, `promptflow`, `azure-ai`).

Run `langwatch docs` with no path when you are unsure: it prints the index of every page. `docs` prints the page as markdown and takes no `--output`, `--json`, `--jq` or `--format`; if a fetch returns 404 the path is wrong, so read the index rather than guessing another spelling.

CRITICAL: Do NOT guess how to instrument. Different frameworks have different instrumentation patterns; always read the framework-specific guide first.

## Step 2: Install the LangWatch SDK

For Python, a ladder, stopping at the first that works, and the manager the workspace facts name is its first rung: `uv add langwatch` when the facts name uv, the folder has a `uv.lock` or `.venv/pyvenv.cfg` carries a `uv =` line (a venv uv made has no pip in it); otherwise `.venv/bin/python -m pip install langwatch` when `.venv` exists, and only then `pip install langwatch`, `pip3 install langwatch`, `python3 -m pip install langwatch`, `python -m pip install langwatch`. A command not found (exit 127) moves to the next rung, never a retry: it is a missing spelling, never a missing capability. When no rung exists, ask before giving up: "Install uv for me" or "I'll set up Python myself".
For TypeScript: `npm install langwatch` when no lockfile names another manager, `pnpm add langwatch`, `yarn add langwatch` or `bun add langwatch` by the lockfile; a 127 on the named manager falls back to `npm`.
`uv add` and the JavaScript managers write the manifest themselves. A pip install writes nothing, so add the package to the project's own requirements file (`requirements.txt`, or the file the folder uses, such as `requirements/base.txt`) yourself: `python -m pip show langwatch` gives the version, and the line is `langwatch==<installed version>`, pinned the way the file pins its other packages and unpinned when it pins none of them.
Before any code is written against it, check the install carries the API through the interpreter that installed it: `python -c "import langwatch; langwatch.setup; langwatch.connect_agent"` for Python, `node -e "require('langwatch')"` for TypeScript. A Python release below 1.3.0 has neither, and pip installs one without a word when the interpreter is newer than the SDK supports: every release with the API declares an upper Python bound, and pip walks back to the last release with none. `pip install langwatch --upgrade` cannot help there. A failed check is a question about the interpreter, asked before giving up: "Install Python 3.13 with uv for me" or "I'll pick the interpreter myself".

If install fails due to peer dependency conflicts, widen the conflicting range and retry. Do NOT silently skip.

## Step 3: Add Instrumentation

Follow the integration guide you read in Step 1. The general shape is:

**Python:**

```python
import langwatch
langwatch.setup()

@langwatch.trace()
def my_function():
    ...
```

**TypeScript:**

```typescript
import { LangWatch } from "langwatch";
const langwatch = new LangWatch();
```

The exact pattern depends on the framework, so follow the docs, not these examples.

**A graph takes the callback at the graph, not at a model call inside it.** LangChain propagates a callback down from wherever it is attached, so in LangGraph the callback goes in the config of the graph invocation:

```python
graph.invoke(state, config={"callbacks": [langwatch.get_current_trace().get_langchain_callback()]})
```

The same config argument works on `ainvoke` and `stream`. Every node the run touches then becomes a span under the trace: a chain span named after the node, LLM spans for the model calls and tool spans for the tool calls. Attached only to the model call inside one node, the trace holds LLM spans and nothing else, so the tool nodes and the plain function nodes are missing and a check for whether the graph reached its payment step has no span to read.

**The environment loads before LangWatch initialises.** `langwatch.setup()` and `new LangWatch()` read `LANGWATCH_API_KEY` from the process environment the moment they run, and a `.env` file is not the environment until something loads it. A filmed run put `langwatch.setup()` at the top of the entry file, above the import that called `load_dotenv()`, and the process died at import with "LangWatch API key is required but not provided".

- Python: find what loads the environment (`load_dotenv()` from python-dotenv, a settings module, a config loader) and put `langwatch.setup()` below every import that runs it, never at the top of the entry file. When the project depends on python-dotenv but the entry file does not load it, add `from dotenv import load_dotenv` and `load_dotenv()` at the top of the instrumented entry file, above `import langwatch`.
- TypeScript: when the project uses dotenv, `import "dotenv/config"` is the first import of the entry file, above the `langwatch` import; the SDK reads the key when it is constructed.

Before you start the process, check that the key is visible to it the way the project reads it. This is the first and only check: copy the command for the language as written, run it once from the project root, and read the answer. No variant before it (a probe such as `import langwatch` with no loader reads the bare process and always answers missing on a dotenv project) and none after it.

```bash
uv run python -c "from dotenv import load_dotenv; load_dotenv(); import os; print(bool(os.getenv('LANGWATCH_API_KEY')))"
```

`uv run` is the runner the project uses; `poetry run python -c` or `.venv/bin/python -c` when it uses those. Always `-c`, never `python -` with a heredoc: python-dotenv's loader looks for its caller's file and fails on standard input. TypeScript:

```bash
node -e "require('dotenv').config(); console.log(Boolean(process.env.LANGWATCH_API_KEY))"
```

The command prints only whether `LANGWATCH_API_KEY` is set, never its value. Swap the loader for the project's own when it is not dotenv. `False` means the file is not where the loader looks or the order above is wrong: fix that, never retry the check with another path.

## Step 4: Verify

Do NOT consider the work complete without verifying. In order:

1. Confirm dependencies installed cleanly.
2. Run the agent with a test input that produces at least one trace (study how the framework starts; only give up if it requires infrastructure you cannot spin up).
3. Check traces arrived: `langwatch trace search --limit 5 --format json`. A trace is not searchable the moment the run ends: the export leaves the process first and ingestion adds a few seconds more, so an empty first answer means "not yet", not "not working". Wait and ask again, up to three times, about twenty seconds apart, and stop there. Do not change the command between tries: the search already covers the last twenty four hours, so a trace that is in is in.
4. Say what the wait ended on. Traces found: say what the run produced. Nothing after the third try: say the instrumentation is in place and the trace had not arrived yet, name the project to look in, and do not report the change as verified.
5. If verification isn't possible (no shell access, can't run the code, missing external services), tell the user exactly what to check in their LangWatch dashboard and what you couldn't verify and why.

This step only proves traces arrive. To find specific traces afterwards (a user, an error, a thumbs down), use the `find-traces` skill.

## Common Mistakes

- Do NOT invent instrumentation patterns. Read the framework-specific doc
- Do NOT skip `langwatch.setup()` in Python
- Do NOT call `langwatch.setup()` above the import that loads the environment: the key is read when `setup()` runs
- Do NOT attach the LangChain callback only to a model call inside a graph node: it belongs on the graph invocation, or the nodes never become spans
- Do NOT skip Step 1; instrumentation patterns vary across OpenAI/LangGraph/Vercel/Mastra/Agno and guessing breaks subtly
Open your project in Claude Code, then paste the prompt.

Already set up? The LangWatch Skills also help you monitor and improve an agent that is running.

What’s new

  • v3.23.0 3 Nov 2026: Agent and evaluator versioning with deploy labels, plus experiment and dependency fixes
  • v3.22.0 2 Nov 2026: Serve OpenAI Decisions API on /v1/decisions
  • v3.21.0 21 Oct 2026: Campaign conversion events for sign in, sign up and paid

Read the changelog

What is LangWatch?

LangWatch is the open-source LLMOps platform that helps teams collaboratively debug, analyze, and iterate on their LLM applications. All platform features are natively integrated to accelerate the development workflow.

Building AI applications is hard. Developers spend weeks debugging issues, optimizing prompts, and ensuring quality. Without tracing, you do not know why your AI behaves the way it does, where it fails, or how to improve it.

LangWatch provides the missing operations platform for AI applications. Every LLM call, tool usage, and user interaction is automatically tracked with detailed traces, spans, and metadata. See the full conversation flow, identify bottlenecks, and understand exactly how your AI applications behave in production.

What LangWatch Does

LangWatch has four areas, and you can use each one on its own.

A Claude Code session inside LangWatch, showing cost, tools, context and cache health.
From a coding session to every model call. Track Claude Code, Codex and your team's agents →

LLM Ops

Tracing, agent testing, evaluations and prompt management for the LLM apps you build.

Coding Agents

What Claude Code, Codex and other coding agents do and cost, per session and per team.

LangWatch AI Gateway

One OpenAI and Anthropic compatible endpoint, with virtual keys, budgets and a trace per call.

AI Governance

An inventory of the AI tools in your company, who uses them, and alerts on unusual activity.

Where to Start?

Start with the area that matches what you are working on today. You can add the others later from the same account.

Trace your LLM application

Send your first trace with the Python or TypeScript SDK, then add evaluations and prompt management.

Track your coding agents

Connect Claude Code, Codex or another coding agent in one command and see its sessions and cost.

Route LLM calls through the gateway

Create a virtual key, point your base URL at LangWatch and send a request.

Govern AI use across the company

See every AI tool in use, who uses it, and what it costs.

Open Source

LangWatch is open core. You can self-host the Apache 2.0 core, and LangWatch Cloud runs the same codebase, with no separate community build.

Enterprise features, such as multi-source governance ingestion and anomaly detection, need a paid plan and have their own license under platform/app/ee/. See Open-core licensing for the full split.

langwatch/langwatch on GitHub

The full platform, the SDKs and the docs, in one repository.

Self-host LangWatch

Run LangWatch on your own infrastructure with Docker or Helm.

LangWatch Cloud has a free plan: sign up to create a project.

Found broken or outdated docs? Use Report outdated or broken docs next to Edit this page below. Agents: include the page URL, the failing step and a proposed fix in a GitHub issue. For CLI diagnostics, ask your user before running npx langwatch report --user-approved. See the reporting guide.

Documentation