setup-lw
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSet Up the LangWatch CLI
设置 LangWatch CLI
Get the CLI authenticated and talking to the right LangWatch project, then verify. The troubleshooting table at the end covers the common failure modes.
先让 CLI 完成认证并连接到正确的 LangWatch 项目,然后进行验证。文末的故障排查表涵盖常见故障模式。
Step 1: Credentials
第 1 步:凭据
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.
For CI and agents, configure non-interactively, and never block on a browser. Have the runner inject the key from your secret store into , which is what the CLI reads:
LANGWATCH_API_KEYyaml
undefined**重要:**你需要一个 LangWatch API key。先检查 是否已设置:检查进程环境(CI 会将 key 注入此处);如果其中没有,则检查项目的 文件。直接使用该 key,不要重新索取。也从相同位置读取 ,并且不要从 中读取其他内容:如果设置了 endpoint,说明项目位于 self-hosted 实例上,CLI 将针对该 endpoint 工作,而不是 。
LANGWATCH_API_KEY.envLANGWATCH_ENDPOINT.envapp.langwatch.ai对于 CI 和 Agent,应进行非交互式配置,并且绝不能阻塞等待浏览器。让 runner 从 secret store 将 key 注入 ,CLI 会读取该变量:
LANGWATCH_API_KEYyaml
undefinedGitHub Actions; any secret store works the same way
GitHub Actions; any secret store works the same way
env:
LANGWATCH_API_KEY: ${{ secrets.LANGWATCH_API_KEY }}
LANGWATCH_ENDPOINT: https://lw.acme.internal # self-hosted only; omit for cloud
That variable is the whole of the CI setup: every command resolves the key from the environment, so there is no `login` call to make. Keep the key off the command line: an argument is readable by every other process on the machine, and in a shell it lands in your history file.
Locally, run plain `langwatch login`. It asks where you are logging in (cloud or self-hosted) and how you will use LangWatch (AI tools, project SDK key, or both), then finishes in the browser. No credential is ever typed or pasted into the terminal: you pick the project on the approval page and its key comes back to the CLI over the same channel, so none of it reaches your shell history. A project SDK key lands as `LANGWATCH_API_KEY` in `.env` in the current directory, so keep `.env` out of version control; an AI-tools login lands in `~/.langwatch/config.json`. `langwatch login --device` skips the questions and goes straight to that RFC 8628 device flow via company SSO.
`langwatch login --api-key <key>` writes a key you already hold straight to `.env`, with no browser and no prompts. It is the only non-interactive way to hand `login` a key, and the key travels through the process argument list, so it is not how a runner should supply one: with `LANGWATCH_API_KEY` set the CLI already has the key, and the flag adds nothing but the file. Reach for it when something downstream genuinely needs the key on disk. It rewrites an existing `LANGWATCH_API_KEY` line rather than adding a second one, which is why it beats appending to `.env` from a shell: a second line makes the credential ambiguous, and one re-run of an append is all it takes to get one.
`langwatch login --project <slug>` writes a project's key to `.env` with no key on the command line either, but it authenticates through an existing device login, so it suits a developer machine or a long-lived agent box rather than a fresh CI runner.
`--endpoint https://lw.acme.internal` combines with any of these to pin a self-hosted instance. It pins the CLI; your instrumented app reads `LANGWATCH_ENDPOINT` from the environment, so a self-hosted setup needs both.env:
LANGWATCH_API_KEY: ${{ secrets.LANGWATCH_API_KEY }}
LANGWATCH_ENDPOINT: https://lw.acme.internal # self-hosted only; omit for cloud
该变量就是 CI 配置的全部内容:每条命令都会从环境变量中解析 key,因此无需执行 `login`。不要把 key 放在命令行上:作为参数时,机器上的其他所有进程都能读取到它;在 shell 中,它还会进入历史文件。
在本地,直接运行 `langwatch login`。它会询问登录位置(cloud 或 self-hosted)以及使用 LangWatch 的方式(AI tools、项目 SDK key,或两者兼有),然后在浏览器中完成。整个过程中绝不会在终端中输入或粘贴任何凭据:你只需在授权页面上选择项目,其 key 就会通过同一通道返回 CLI,因此不会进入 shell history。项目 SDK key 会以 `LANGWATCH_API_KEY` 的形式写入当前目录的 `.env`,因此不要将 `.env` 纳入版本控制;AI-tools 登录结果则会写入 `~/.langwatch/config.json`。`langwatch login --device` 会跳过这些问答,直接通过公司 SSO 进入 RFC 8628 device flow。
`langwatch login --api-key <key>` 会将已经持有的 key 直接写入 `.env`,无需浏览器,也不会显示 prompt。这是向 `login` 提供 key 的唯一非交互方式;但 key 会经过进程参数列表,因此 runner 不应以此方式提供:设置 `LANGWATCH_API_KEY` 后,CLI 已经拥有该 key,而该 flag 除了写入文件之外没有任何额外作用。只有当下游确实需要磁盘上存在 key 时,才应使用它。它会重写已有的 `LANGWATCH_API_KEY` 行,而不是再添加一行;这也是它优于从 shell 向 `.env` 追加内容的原因:出现第二行会让凭据产生歧义,而只需重新运行一次追加操作,就会出现重复项。
`langwatch login --project <slug>` 同样无需在命令行中携带 key,即可将项目的 key 写入 `.env`,但它会通过现有的 device login 完成认证,因此适合开发机或长期运行的 Agent 主机,而不适合全新的 CI runner。
`--endpoint https://lw.acme.internal` 可与上述任何方式结合使用,以固定 self-hosted 实例。它固定的是 CLI;经过 instrumentation 的应用会从环境变量中读取 `LANGWATCH_ENDPOINT`,因此 self-hosted 配置需要同时设置两者。Step 2: Endpoint and Project
第 2 步:Endpoint 与项目
- Cloud (app.langwatch.ai) needs no endpoint configuration.
- Self-hosted: the endpoint resolves flag > env > config > default. Persist it with , or export
langwatch config set endpoint https://lw.acme.internalper shell.LANGWATCH_ENDPOINT - Project: the API key determines the project. Check you're in the right one:
bash
langwatch projects list -o jsonA personal access token (PAT) instead of a project key also needs set.
LANGWATCH_PROJECT_ID- Cloud()无需配置 endpoint。
app.langwatch.ai - Self-hosted:endpoint 的解析顺序为 flag > env > config > default。可使用 持久保存,或针对每个 shell 进行导出。
langwatch config set endpoint https://lw.acme.internal - 项目:API key 决定项目。检查是否处于正确的项目:
bash
langwatch projects list -o json如果使用个人访问令牌(PAT)而不是项目 key,还必须设置 。
LANGWATCH_PROJECT_IDStep 3: Verify
第 3 步:验证
bash
langwatch whoami # device-session identity (governance plane)
langwatch status # resource counts: proves auth + endpoint + project in one shotlangwatch statusbash
langwatch whoami # device-session identity (governance plane)
langwatch status # resource counts: proves auth + endpoint + project in one shotlangwatch statusStep 4: Discover What You Can Do
第 4 步:发现可用功能
Use to read documentation as Markdown. Some useful entry points:
langwatch docs <path>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 indexDiscover commands with and . List and get commands accept for machine-readable output. Every list command takes to cap the rows and to read part of the answer. A paginated list answers with an envelope, so count its rows through the row array (), and read how many there are in all at . Bare counts the fields of the envelope, not the rows. Read the docs first instead of guessing SDK APIs or CLI flags.
langwatch --helplangwatch <subcommand> --help--format json--limit <n>--jq <expr>--jq '.traces | length'.pagination.total--jq lengthIf no shell is available, fetch the same Markdown over plain HTTP. Append 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
.mdIf 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 with a and (or ) to send it to the LangWatch team, and it directly shapes what gets fixed. No login or API key needed. Nothing is sent without , and 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 . With , always run first and let the user read the payload, because a transcript carries content they never reviewed. explains the options.
npx --yes langwatch report --user-approved--title--summary--session <transcript.jsonl>--user-approved--dry-run--email--session--dry-runnpx --yes langwatch report --help使用 以 Markdown 格式阅读文档。以下是一些实用入口:
langwatch docs <path>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使用 和 发现命令。list 和 get 命令接受 以获得机器可读输出。每个 list 命令都接受 来限制行数,并接受 读取结果的一部分。分页 list 会返回一个 envelope,因此应通过 row array 统计行数(),并通过 查看总数。单独使用 统计的是 envelope 的字段数,而不是行数。请先阅读文档,不要猜测 SDK API 或 CLI flag。
langwatch --helplangwatch <subcommand> --help--format json--limit <n>--jq <expr>--jq '.traces | length'.pagination.total--jq length如果环境中没有 shell,可通过普通 HTTP 获取相同的 Markdown。给任意 docs path 追加 (例如 https://langwatch.ai/docs/integration/python/guide.md)。索引:https://langwatch.ai/docs/llms.txt。Scenario 索引:https://langwatch.ai/scenario/llms.txt
.md如果在执行此 skill 时遇到任何失败或令人困惑的情况(命令失效、文档与实际情况不符,或者你不得不绕过错误),请征得用户许可,然后运行 ,并提供 和 (或 ),将其发送给 LangWatch 团队;这些反馈会直接影响后续修复。无需 login 或 API key。如果没有 ,不会发送任何内容; 会打印将要发送的确切 payload,但不会发送。title、summary 和 transcript 会先在本地按模式进行脱敏:包括 secrets、API keys,以及电子邮件地址、电话号码、银行卡号和 public IPv4 地址。任何未被模式匹配的内容都会按原样发送,包括通过 传入的联系地址。使用 时,务必先运行 并让用户阅读 payload,因为 transcript 可能包含他们从未审阅过的内容。 会说明各个选项。
npx --yes langwatch report --user-approved--title--summary--session <transcript.jsonl>--user-approved--dry-run--email--session--dry-runnpx --yes langwatch report --helpTroubleshooting
故障排查
| Symptom | Likely cause | Fix |
|---|---|---|
| Wrong, revoked, or missing API key | Re-run |
| Missing project id | |
| Connection refused / DNS errors | Self-hosted endpoint wrong or unreachable | Check |
| Right credentials, wrong data | Talking to the wrong project or instance | |
Old shell ignores new | Env vars already exported | Start a new shell, or |
| A command hangs waiting for input | Interactive prompt in a non-interactive context | No flag answers prompts globally. Set |
| 症状 | 可能原因 | 修复方式 |
|---|---|---|
每个命令都出现 | API key 错误、已吊销或缺失 | 重新运行 |
使用 PAT 时出现 | 缺少 project id | |
| Connection refused / DNS errors | self-hosted endpoint 错误或无法访问 | 检查 |
| 凭据正确,但数据错误 | 正在连接错误的项目或实例 | |
旧 shell 忽略新的 | 环境变量已经被导出 | 启动新 shell,或执行 |
| 命令挂起并等待输入 | 在非交互上下文中出现交互式 prompt | 没有任何 flag 能在全局范围内自动回答 prompt。先设置 |