Skip to contentSkip to page list

Docs

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.

POST/api/v1/grants
Request and response examples
request.py
import osimport requests​origin = "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())

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"}
api-reference/grants/grant-a-role

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

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

principalobjectrequired
typestringrequired
One of"user""group""apiKey"
idstringrequired
At least 1 characterUp to 128 characters
roleIdstringrequired
At least 1 characterUp to 128 characters
scopeobjectrequired
typestringrequired
One of"organization""team""project"
idstringrequired
At least 1 characterUp to 128 characters
expiresAtstring (date-time)

Responses

201

Success

application/json

idstringrequired
principalobjectrequired
typestringrequired
One of"user""group""apiKey"
idstringrequired
namestring | nullrequired
roleobjectrequired
idstringrequired
namestring | nullrequired
builtInbooleanrequired
scopeobjectrequired
typestringrequired
One of"organization""team""project"
idstringrequired
namestring | nullrequired
statusstringrequired
One of"active""expired"
expiresAtstring (date-time) | nullrequired
Option 1string (date-time)
Option 2null
createdAtstring (date-time)required

Documentation