Skip to contentSkip to page list

Docs

Create API key

Create a new API key. For service keys, pass keyType:"service". Optionally scope to specific projects via projectIds (ADMIN on each). Omit projectIds for full org access. Pass assignedToUserId to mint the key for another member, and permissionMode:"restricted" with a permissions list to grant exactly those permissions. Minting a service key or a key for another member requires organization admin rights, held by both the key making the request and its member. A key can grant at most what the key making the request holds. The plaintext token is returned once — store it securely.

POST/api/v1/api-keys
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/v1/api-keys"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "Authorization": "Bearer " + api_key,    "Content-Type": "application/json",}payload = {}​response = requests.post(    origin + path,    headers=headers,    json=payload,)print(response.json())

Success

application/json · Generated from schema

{  "token": "string",  "apiKey": {    "id": "string",    "name": "string",    "createdAt": "2026-01-01T00:00:00Z"  }}
api-reference/api-keys/create-api-key

Authorization

Authorizationstringheaderrequired

Admin API key for organization-level operations (managing projects, API keys). Create one in Settings > API Keys or via POST /api/api-keys. Format: sk-lw-{id}_{secret}.

Request body

application/json · Required

keyTypestring

A personal key acts as the user who created it and needs explicit bindings. A service key is not tied to a user.

One of"personal""service"
Default: "personal"
namestringrequired

Human-readable name for this key

At least 1 characterUp to 100 characters
descriptionstring
Up to 500 characters
expiresAtstring (date-time)

ISO 8601 timestamp after which the key stops working

assignedToUserIdstring

Organization admins only: the member who owns the key and whose access caps it. Defaults to the caller.

At least 1 character
permissionModestring

'all' and 'readonly' take their meaning from the bindings alone; 'restricted' additionally requires an explicit permissions list.

One of"all""readonly""restricted"
Default: "all"
permissionsstring[]

Restricted mode only: the exact resource:action permissions the key's CUSTOM bindings grant.

bindingsobject[]

What this key may do, and where. Required for a personal key.

rolestringrequired

CUSTOM grants exactly the listed permissions and requires permissionMode 'restricted'.

One of"ADMIN""MEMBER""VIEWER""CUSTOM"
scopeTypestringrequired
One of"ORGANIZATION""TEAM""PROJECT"
scopeIdstringrequired
At least 1 character
projectIdsstring[]

Service keys only: restricts the key to these projects

Responses

201

Success

application/json

tokenstringrequired
At least 1 character
apiKeyobjectrequired
idstringrequired
At least 1 character
namestringrequired
createdAtstring (date-time)required
401

Invalid or missing API key token

403

Requested binding exceeds what the key making the request holds, or the scope does not belong to this organization (api_key_scope_violation); a service key or a key for another member was requested without organization admin rights (api_key_admin_required)

422

Validation error, for example a missing name or empty bindings (validation_error), or a name LangWatch reserves for its own keys (api_key_reserved_name)

Documentation