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}.
Grant a role
Grant a role to a user, group or API key on the organization, a team or a project. roleId is admin, member, viewer or a custom role's id. Grants are never unique: each create is a new grant with its own id, up to the organization's limit (409 grant_limit_reached). Pass expiresAt to time-box the access. Send Idempotency-Key to make a retry safe. A grant never confers a permission the caller does not hold at that scope: 403 grant_exceeds_caller_permissions names the missing permissions.
Try this endpoint
app.langwatch.ai
API key · Authorization
Kept in this tab. Cleared when you reload.
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.
In UTC.
This sends a live request to app.langwatch.ai.
Request and response examples
import osimport requestsorigin = "https://app.langwatch.ai"path = "/api/v1/grants"api_key = os.environ["LANGWATCH_API_KEY"]headers = { "Authorization": "Bearer " + api_key, "Content-Type": "application/json",}payload = { "principal": {}, "scope": {},}response = requests.post( origin + path, headers=headers, json=payload,)print(response.json())const url = "https://app.langwatch.ai/api/v1/grants";const response = await fetch(url, { method: "POST", headers: { "Authorization": "Bearer " + process.env.LANGWATCH_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ "principal": {}, "scope": {} }),});const data = await response.json();curl --request POST \ --url 'https://app.langwatch.ai/api/v1/grants' \ --header "Authorization: Bearer $LANGWATCH_API_KEY" \ --header 'Content-Type: application/json' \ --data '{"principal":{},"scope":{}}'Call the LangWatch API from this project: Grant a role.Request: POST https://app.langwatch.ai/api/v1/grantsReference: https://langwatch.ai/docs/api-reference/grants/grant-a-role.mdAuthentication: send the Authorization header as a Bearer token, read from the LANGWATCH_API_KEY environment variable. Never hard-code the key.Body (application/json):```json{ "principal": {}, "scope": {}}```Use the HTTP client this project already uses, handle non-2xx responses, and show me the parsed result.Success
application/json · Generated from schema
{ "id": "string", "principal": { "type": "user", "id": "string", "name": "string" }, "role": { "id": "string", "name": "string", "builtIn": false }, "scope": { "type": "organization", "id": "string", "name": "string" }, "status": "active", "expiresAt": "2026-01-01T00:00:00Z", "createdAt": "2026-01-01T00:00:00Z"}Headers
Idempotency-KeystringA 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.
Request body
application/json · Required
principalobjectrequiredroleIdstringrequiredscopeobjectrequiredexpiresAtstring (date-time)Responses
201Success
application/json
idstringrequiredprincipalobjectrequiredroleobjectrequiredscopeobjectrequiredstatusstringrequired"active""expired"expiresAtstring (date-time) | nullrequiredcreatedAtstring (date-time)required