Skip to contentSkip to page list

Docs

Create virtual key

Mints a new virtual key and returns the secret exactly once. With reveal_once the response withholds the secret and carries reveal_id and preview instead: the secret is parked for 24 hours and served once, to the person the key is for, through the LangWatch app. scopes defaults to the project the caller names; an API key that names no project must send scopes. Org- and team-scoped keys require virtualKeys:manage at each requested scope.

POST/api/gateway/v1/virtual-keys
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/gateway/v1/virtual-keys"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "X-Auth-Token": 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

{  "virtual_key": {    "id": "string",    "organization_id": "string",    "name": "string",    "description": "string",    "status": "active",    "purpose": "user",    "display_prefix": "string",    "principal_user_id": "string",    "trace_project_id": "string",    "trace_project_archived": false,    "external_id": "string",    "metadata": {},    "scopes": [      {        "scope_type": "organization",        "scope_id": "string"      }    ],    "routing_policy_id": "string",    "routing_mode": "none",    "config": null,    "revision": "string",    "created_at": "2026-01-01T00:00:00Z",    "updated_at": "2026-01-01T00:00:00Z",    "last_used_at": "2026-01-01T00:00:00Z",    "revoked_at": "2026-01-01T00:00:00Z",    "expires_at": "2026-01-01T00:00:00Z"  },  "secret": "string",  "reveal_id": "string",  "preview": "string"}
api-reference/gateway-virtual-keys/create-virtual-key

Authorization

X-Auth-Tokenstringheaderrequired

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

Headers

Idempotency-Keystring

A caller-chosen key, 8 to 255 characters, that makes this create safe to retry. The first request to use a key runs normally and its response is stored for 24 hours. A later request with the same key and the same body is not executed again: it returns the stored response, marked with X-Idempotent-Replay: true. The same key with a different body is refused 409 idempotency_error, as is a retry sent while the original is still running. Only successful responses are stored, so a create that failed can simply be retried with the same key.

At least 8 charactersUp to 255 characters

Request body

application/json · Required

namestringrequired
At least 1 characterUp to 128 characters
descriptionstring
principal_user_idstring | null
reveal_onceboolean
scopesobject[]
scope_typestringrequired
One of"organization""team""project"
scope_idstringrequired
At least 1 character
trace_project_idstring | null
routing_policy_idstring | null
routing_modestring
One of"none""fallback_all""policy"
expires_atstring (date-time)
budgetobject | null
Option 1object
limit_usdnumber | stringrequired
windowstringrequired
One of"day""week""month"
on_breachstring
One of"block""warn"
namestring
At least 1 characterUp to 128 characters
Option 2null
configobject
modelsAllowedstring[] | null
providersAllowedstring[] | null
cacheobject
fallbackobject
guardrailAttachmentsobject[]
rateLimitsobject
realtimeobject
metadataobject
external_idstring | null
Option 1string
Option 2null
metadataobject
purposestring
Always"user"

Responses

201

Success

application/json

virtual_keyobjectrequired
idstringrequired
organization_idstringrequired
namestringrequired
descriptionstring | nullrequired
statusstringrequired
One of"active""disabled""revoked"
purposestringrequired
One of"user""langy"
display_prefixstringrequired
principal_user_idstring | nullrequired
trace_project_idstring | nullrequired

The project this key's traces and costs land in. Not a scope: it grants no access to the key. Null only on a key created before this was stored.

trace_project_archivedbooleanrequired

True when the project in trace_project_id has been deleted. The key goes on sending its traces there.

external_idstring | nullrequired
metadataobjectrequired
scopesobject[]required
routing_policy_idstring | nullrequired
routing_modestringrequired
One of"none""fallback_all""policy"
configanyrequired
revisionstringrequired
created_atstring (date-time)required
Pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
updated_atstring (date-time)required
Pattern ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
last_used_atstring (date-time) | nullrequired
revoked_atstring (date-time) | nullrequired
expires_atstring (date-time) | nullrequired

When the key stops serving, or null for a key that never expires. status stays active past the date on purpose.

secretstring

The secret, absent when reveal_once was set.

reveal_idstring

With reveal_once: the id that serves the secret once, through the app.

previewstring

With reveal_once: the key's display prefix, safe to show in place of the secret.

400

Bad Request

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
401

Unauthorized

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
403

Forbidden

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
409

Conflict

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
500

Internal Server Error

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]

Documentation