# LangSmith API keys: find, store, rotate, and use them safely with AI agents

Source: https://botpassword.com/keys/langsmith
Last checked: 2026-11-08

LangSmith API keys are created under **Settings** → **API Keys** in LangSmith and set as `LANGSMITH_API_KEY` for the LangSmith SDKs, CLI and MCP server. Personal access tokens (`lsv2_pt_`) act with their creator's permissions, service keys (`lsv2_sk_`) belong to a service account and can be scoped to workspaces, and tracing keys (`lsv2_tr_`) can only submit traces. LangSmith shows a key once and lets you pick an expiry in days or never.

## Key types

| Type | Prefix | Secret | Scope | Expiry |
|---|---|---|---|---|
| Personal access token | `lsv2_pt_` | Yes | The same permissions as the user who created it; requests run in the key's default workspace unless `X-Tenant-Id` is sent | Chosen at creation, a number of days or never |
| Service key | `lsv2_sk_` | Yes | A service account, scoped to one workspace, several workspaces or the whole organization | Chosen at creation, a number of days or never |
| Tracing key | `lsv2_tr_` | Yes | Organization-owned, fixed permission to submit traces and create projects in selected workspaces | — |

## How to create a LangSmith key

1. Sign in to LangSmith and open the **Settings** page.
2. Select the **API Keys** section and create a key.
3. Choose a personal access token, a service key (admins only) or a tracing key.
4. For a service key, choose **Full Organization** or **Specific Workspaces**, and set an expiration.
5. Copy the key straight away; LangSmith displays it only once.

## Limiting what the key can do

Pick the weakest LangSmith key that does the job. An app that only sends traces needs a tracing key (`lsv2_tr_`), which cannot read or change data. A shared service should use a service key scoped to specific workspaces rather than a personal token, which carries all of its creator's rights and is tied to that person. If a key is scoped to more than one workspace, set `LANGSMITH_WORKSPACE_ID` or send `X-Tenant-Id` so requests land in the right workspace. Self-hosted instances and custom regions also need `LANGSMITH_ENDPOINT`, which defaults to `https://api.smith.langchain.com`.

## How to rotate a LangSmith key

1. Create a new LangSmith key of the same type, scope and workspaces, with an expiration.
2. Update `LANGSMITH_API_KEY` in every service, notebook and MCP configuration.
3. Delete the old key in **Settings** → **API Keys** (personal tokens can be deactivated first as a reversible step).

## How to revoke a LangSmith key

1. Open **Settings** → **API Keys** in LangSmith.
2. Deactivate a personal access token to stop it reversibly, or delete it to remove the token and its record permanently.
3. Delete a service key; service keys cannot be deactivated.

## If the key leaked

1. Delete the exposed key in **Settings** → **API Keys**.
2. Create a replacement scoped to only the workspaces it needs, with an expiry.
3. Review the affected workspaces' traces, datasets and prompts for changes you did not make.

## Environment variables

- `LANGSMITH_API_KEY`
- `LANGSMITH_WORKSPACE_ID`
- `LANGSMITH_ENDPOINT`

## Gotchas

- Keys starting with `ls__` are legacy and no longer work; replace them with `lsv2_` keys.
- A personal access token belongs to one person, so automations break when that person loses access; use a service key for shared services.
- The standalone LangSmith MCP server, now deprecated in favour of Remote MCP, takes a `LANGSMITH-API-KEY` header over HTTP, while the hosted Remote MCP uses `X-Api-Key`.

## Using this key with AI agents (BotPassword)

- `run_with`: Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output.
- `http_request`: Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused.

## FAQ

### Where do I find my LangSmith API key?

In LangSmith, open **Settings** → **API Keys** and create one. LangSmith shows a key only once, so a lost key has to be replaced.

### What do lsv2_pt_, lsv2_sk_ and lsv2_tr_ mean?

`lsv2_pt_` is a personal access token, `lsv2_sk_` is a service key for a service account, and `lsv2_tr_` is a tracing key that can only submit traces.

### Should I use LANGSMITH_API_KEY or LANGCHAIN_API_KEY?

LangSmith's current documentation, SDK setup and CLI use `LANGSMITH_API_KEY`, together with `LANGSMITH_WORKSPACE_ID` and `LANGSMITH_ENDPOINT` where needed.

### How do I connect LangSmith to Claude Code or another MCP client?

Use LangSmith's Remote MCP at `https://api.smith.langchain.com/mcp` (or `https://eu.api.smith.langchain.com/mcp`), which signs interactive clients in with OAuth 2.1 and needs no API key. Scripts and backend services can send a key in `X-Api-Key` instead.

### Do LangSmith API keys expire?

You choose when you create the key: after a number of days, or never.

### Can an AI agent use my LangSmith key without seeing it?

Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a `.env` file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with `run_with`, `http_request`, so the agent gets the result and never the value.

## Sources

- https://docs.langchain.com/langsmith/create-account-api-key
- https://docs.langchain.com/langsmith/administration-overview
- https://docs.langchain.com/langsmith/langsmith-cli
- https://docs.langchain.com/langsmith/langsmith-remote-mcp
- https://docs.langchain.com/langsmith/langsmith-mcp-server
