import requests
url = "https://app.langwatch.ai/api/gateway/v1/virtual-keys"
payload = { "name": "<string>" }
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>'})
};
fetch('https://app.langwatch.ai/api/gateway/v1/virtual-keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/gateway/v1/virtual-keys \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>"
}
'{
"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": true,
"external_id": "<string>",
"metadata": {},
"scopes": [
{
"scope_type": "organization",
"scope_id": "<string>"
}
],
"routing_policy_id": "<string>",
"routing_mode": "none",
"revision": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"last_used_at": "2023-11-07T05:31:56Z",
"revoked_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"config": "<unknown>"
},
"secret": "<string>"
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}Create virtual key
Mints a new virtual key and returns the secret exactly once. The caller MUST persist the secret value, because LangWatch stores only a hash. scopes defaults to the caller’s project; org- and team-scoped keys require a scoped API key holding virtualKeys:manage at each requested scope. An org- or team-scoped key also needs a place for its traces and spend to land, and must say where: pass trace_project_id (needs virtualKeys:manage on that project). Without it, and without exactly one project scope to take it from, creation refuses with gateway_trace_project_ambiguous, because the spend would be attributed to the organization’s hidden governance project and counted by no budget on the project you had in mind. An organization whose only project is the governance one is exempt, since there is nothing else to name; one with no governance project either refuses with trace_project_required. Send Idempotency-Key to make a retry safe: a replay returns the original response including its secret, which is the only way to recover a secret whose response was lost in transit.
import requests
url = "https://app.langwatch.ai/api/gateway/v1/virtual-keys"
payload = { "name": "<string>" }
headers = {
"X-Auth-Token": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Auth-Token': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({name: '<string>'})
};
fetch('https://app.langwatch.ai/api/gateway/v1/virtual-keys', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url https://app.langwatch.ai/api/gateway/v1/virtual-keys \
--header 'Content-Type: application/json' \
--header 'X-Auth-Token: <api-key>' \
--data '
{
"name": "<string>"
}
'{
"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": true,
"external_id": "<string>",
"metadata": {},
"scopes": [
{
"scope_type": "organization",
"scope_id": "<string>"
}
],
"routing_policy_id": "<string>",
"routing_mode": "none",
"revision": "<string>",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z",
"last_used_at": "2023-11-07T05:31:56Z",
"revoked_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"config": "<unknown>"
},
"secret": "<string>"
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}{
"error": {
"type": "<string>",
"code": "<string>",
"message": "<string>",
"meta": {},
"trace_id": "<string>",
"span_id": "<string>"
}
}Authorizations
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
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.
8 - 255Body
1 - 1281Show child attributes
Show child attributes
none, fallback_all, policy When the key stops serving. Omit it and the key never expires. A date that has already passed is refused with virtual_key_expiry_in_past, rather than writing a key that is dead on arrival.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
1 - 128Show child attributes
Show child attributes
"user"Was this page helpful?