Developer tools

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

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.

LangSmith key types

TypePrefixSecret?ScopeExpiry
Personal access token
Can be deactivated or deleted. Organization Viewer and Organization Restricted roles cannot create one.
lsv2_pt_YesThe same permissions as the user who created it; requests run in the key's default workspace unless `X-Tenant-Id` is sentChosen at creation, a number of days or never
Service key
Only admins can create service keys, and they can only be deleted, not deactivated. Organization-scoped keys must send X-Tenant-Id for workspace resources or get a 403.
lsv2_sk_YesA service account, scoped to one workspace, several workspaces or the whole organizationChosen at creation, a number of days or never
Tracing key
Used as LANGSMITH_API_KEY in the SDK like the other key types. Legacy ls__ keys stopped working on October 22, 2024.
lsv2_tr_YesOrganization-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).

LangSmith has no in-place regenerate, so rotation means create, deploy, delete. Setting an expiry in days makes a forgotten key stop working on its own.

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 your LangSmith 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 and CLI

LangSmith's SDKs and docs read the key from LANGSMITH_API_KEY, LANGSMITH_WORKSPACE_ID or LANGSMITH_ENDPOINT.

LangSmith CLI (langsmith): langsmith auth login runs a browser OAuth flow and stores tokens in ~/.langsmith/config.json; LANGSMITH_API_KEY or --api-key works instead

Things that catch people out

  • 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.

Common LangSmith authentication errors

403 Forbidden

An organization-scoped service key called a workspace resource without the X-Tenant-Id header.

Using your LangSmith key with AI agents

A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.

BotPassword works this way. For a LangSmith key, these intents fit:

IntentWhat BotPassword does
run_withRuns 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_requestMakes 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.

LangSmith also publishes its own MCP server. Whatever server the agent uses, keep the credential it authenticates with out of the agent's context.

Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents

Frequently asked questions

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.

Stop pasting LangSmith keys into agents

BotPassword is in early access. Request an invite and we'll email you when your spot opens.