> ## Documentation Index
> Fetch the complete documentation index at: https://traceroot.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Started

> Set up tracing for your AI agent in minutes

Run this from the root of the repository you want to trace:

```bash theme={null}
npx -y traceroot-cli@latest setup
```

Setup needs Node.js 20.12 or later and a Python or TypeScript/JavaScript application. Prefer to add the SDK yourself? Skip to [Set up manually](#set-up-manually).

## What setup does

Setup checks for uncommitted changes, signs you in through your browser, selects or creates a project, and sets `TRACEROOT_API_KEY` for your application, normally in `.env.local` or `.env`. It then runs your coding agent and waits for a trace, or gives you a task or manual steps to finish yourself.

Setup never reverts your coding agent's edits, so review them with `git diff`. It keeps its progress and a project key for the CLI in `.traceroot/`, which it git-ignores.

In a monorepo, run setup from the service's directory or pass `--service <path>`. For every option, run `npx -y traceroot-cli@latest setup --help`. Your deployed application also needs `TRACEROOT_API_KEY` in its environment, plus `TRACEROOT_HOST_URL` if you self-host.

## Self-hosted traceroot

Pass your API's origin as `--host`, and your web app's origin, where you sign in, as `--auth-host`. For a local deployment with the default ports:

```bash theme={null}
npx -y traceroot-cli@latest setup --host "http://localhost:8000" --auth-host "http://localhost:3000"
```

Use origins only, without `/api/v1`. If both share one origin, `--host` alone is enough. Your deployment's **Traces** page shows this command with its origins filled in. See [Self-Hosting](https://traceroot.ai/docs/developer/self-hosting.md) to run a deployment.

## Set up manually

These are the steps setup automates.

### 1. Get an API key

Create an API key either with [traceroot Cloud](https://app.traceroot.ai) or [Self-Hosting](https://traceroot.ai/docs/developer/self-hosting.md).

### 2. Install the SDK

> [tab] Python
>
> ```bash theme={null}
> pip install traceroot
> ```

> [tab] TypeScript
>
> ```bash theme={null}
> npm install @traceroot-ai/traceroot
> ```

### 3. Set environment variables

![traceroot Tracing page with the Create an API key step highlighted](https://mintcdn.com/tracerootai/TLv21OVXbJzkJk5L/images/tracing_api_key_v1.png?fit=max\&auto=format\&n=TLv21OVXbJzkJk5L\&q=85\&s=230ed774e147fbc2ea58bd028f582e35)

Tracing setup: sidebar, Manual tab, API key field, Generate button

Neither SDK loads `.env` files automatically; both read the process environment. Export the variables in your shell:

```bash theme={null}
export TRACEROOT_API_KEY="your-api-key"
export TRACEROOT_HOST_URL="https://app.traceroot.ai"  # self-hosted: your API's origin, e.g. http://localhost:8000
```

*(If you prefer to use a `.env` file, ensure you load it explicitly in your code as shown in the next step.)*

### 4. Instrument your code

> [tab] Python
>
> Initialize traceroot where your application starts, inside the `if __name__ == "__main__":` block rather than at module scope, so a test that imports the module doesn't send traces.
>
> ```python theme={null}
> import traceroot
> from traceroot import Integration
> from openai import OpenAI
>
> def main():
>     client = OpenAI()
>     # ...your application
>
> if __name__ == "__main__":
>     # from dotenv import load_dotenv; load_dotenv()  # Uncomment if using a .env file (requires: pip install python-dotenv)
>     traceroot.initialize(integrations=[Integration.OPENAI])  # instruments all OpenAI calls
>     main()
> ```
>
> Under a server such as uvicorn or gunicorn that block never runs, so initialize where the framework starts up.

> [tab] TypeScript
>
> Initialize traceroot in the function your entry point calls to start, rather than at module scope, so a test that imports the module doesn't send traces.
>
> ```typescript theme={null}
> // import { config } from 'dotenv';  // Uncomment if using a .env file (requires: npm install dotenv)
> import OpenAI from 'openai';
> import { TraceRoot } from '@traceroot-ai/traceroot';
>
> async function main() {
>   // config();
>   TraceRoot.initialize({ instrumentModules: { openAI: OpenAI } });  // instruments all OpenAI calls
>   const openai = new OpenAI();
>   // ...your application
> }
>
> // Call main() from your entry point.
> ```
>
> If a framework loads your module instead of running it, initialize where the framework starts up instead.

Run your own tests with `TRACEROOT_ENABLED=false` so they don't send traces either. For full SDK details, see the [Python SDK](https://traceroot.ai/docs/tracing/python-sdk.md) or [TypeScript SDK](https://traceroot.ai/docs/tracing/typescript-sdk.md).

### 5. See your first trace

Run your application and exercise the code you instrumented. Open [traceroot Cloud](https://app.traceroot.ai) (or your self-hosted dashboard), navigate to your project, and you'll see the full span hierarchy, token usage, cost, and timing.

Prefer the terminal? The [traceroot CLI](https://traceroot.ai/docs/cli/get-started.md) works with the same traces, plus detector findings and evaluations, from your shell.

## Troubleshoot

### Setup stopped partway

Ask setup what went wrong, then continue from where it stopped:

```bash theme={null}
npx -y traceroot-cli@latest setup doctor
npx -y traceroot-cli@latest setup --resume
```

If you ran setup with `--service <path>`, pass the same option to both. If your coding agent didn't finish, setup keeps its output in `.traceroot/setup-instrument-output.log`. That file can quote your repository's files, secrets included, so check it before you share it.

### No trace arrived

Run your application once and exercise the instrumented code, then run `npx -y traceroot-cli@latest setup --resume`. Neither SDK loads `.env` on its own, so check that your application loads the file setup wrote, or export the variables in your shell.

### Still stuck?

Ask on [Discord](https://discord.gg/TM2m3CtKuC) or [open an issue](https://github.com/traceroot-ai/traceroot-cli/issues).

## Next steps

> [card] [Python SDK](https://traceroot.ai/docs/tracing/python-sdk.md)
>
> Full API reference for the Python SDK.

> [card] [TypeScript SDK](https://traceroot.ai/docs/tracing/typescript-sdk.md)
>
> Full API reference for the TypeScript SDK.

> [card] [Features](https://traceroot.ai/docs/tracing/overview.md)
>
> Attach users, sessions, tags, metadata, and more to your traces.

> [card] [Detectors](https://traceroot.ai/docs/detectors/introduction.md#how-to-create-a-detector)
>
> Create your first detector and start surfacing failures in your traces.

> [card] [traceroot Agent](https://traceroot.ai/docs/ai-agent/overview.md)
>
> Auto-debug failing traces with the traceroot Agent.

> [card] [CLI](https://traceroot.ai/docs/cli/get-started.md)
>
> Work with your traces, findings, and evaluations from the terminal.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.