> For the complete documentation index, see [llms.txt](https://docs.contextual.io/documentation-and-resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contextual.io/documentation-and-resources/tenants/tenant-apis/authentication-and-permissions.md). Agents can also search and read this documentation through its [MCP server](https://docs.contextual.io/documentation-and-resources/~gitbook/mcp).

# Authentication and Permissions

To use a Tenant API, you must authenticate as a user or application with permission to perform the requested operation in your tenant. Each API guide explains which credentials and token audiences it accepts, how to identify the tenant in a request, and which permissions you need.

## Choose credentials

Use a credential type that the API guide supports:

* **API Key**: For an application or unattended integration, use a tenant API Key if the API guide says the API supports API Keys. See [Set up API Key access](#set-up-api-key-access).
* **Other schemes**: Some operations use another scheme, such as short-lived file-transfer tokens. Follow the API guide for those operations.

## Identify the tenant

Wherever `<tenant-id>` appears in this documentation, replace it with the tenant identifier from your Tenant Workspace URL. For example, the tenant ID in `https://app.example.my.contextual.io` is `example`, the label immediately before `.my.contextual.io`.

Some APIs call the tenant ID the organization ID. An operation may use the hostname, require `x-org-id: <tenant-id>`, or take the tenant ID in its path. The API guide says which is required. When both the hostname and a header identify the tenant, their values must agree.

## Permissions for managing API Keys

You manage API Keys in the new Admin Console at `https://next.<tenant-id>.my.contextual.io`. In the navigation menu, under **Admin**, select **API Keys**, then select a key to open its **Settings** and **Permissions** tabs.

### Your Role and the key's permissions

Two separate sets of permissions apply:

* **Your Role permissions** control what you can do with keys in the Admin Console, such as create a key or copy its Client Secret. An administrator assigns Roles to people.
* **The key's permissions** control what an application can do with the key's access tokens. You set them on the key's **Permissions** tab. See [Assign permissions](#assign-permissions).

A key doesn't inherit the access of the person who creates it. A new key has no permissions until someone saves them on its **Permissions** tab.

Give **Client grants** permissions only to people you trust, because these permissions control what applications can do with each key.

### Tenant API permissions

On a Role's **Permissions** tab, the **Tenant API** section controls API Key work. Each row has **Read**, **Create**, **Update**, and **Delete** actions.

| Row                  | What it covers                                                                                                                                                                                                             |
| -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Clients**          | The API Keys themselves: their name, description, status, and Client ID.                                                                                                                                                   |
| **Client secrets**   | Each key's Client Secret. **Read** lets you reveal or copy it, and **Update** lets you rotate it. The secret is created with the key and removed with it, so API Key tasks don't use **Create** or **Delete** in this row. |
| **Client grants**    | Each key's permissions. A grant connects a key to an API and lists what the key can do there.                                                                                                                              |
| **Resource servers** | API registrations. Each one has the API Identifier that you use as the token `audience`, and the permissions that the API offers. API Key tasks only read them.                                                            |

### Permissions for each task

Your Role needs these permissions for each API Key task. Permissions are in the **Tenant API** section unless the table names another section. To open a key, you also need **Clients** → **Read**.

| Task                                                       | Role permissions                                                                                                                       |
| ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| See the list of keys and open a key                        | **Clients** → **Read**                                                                                                                 |
| Create a key                                               | **Clients** → **Create**                                                                                                               |
| Save a new key's first permissions                         | **Client grants** → **Read** and **Create**, **Resource servers** → **Read**, and **Service components** → **Object Types** → **Read** |
| Change a key's permissions                                 | **Client grants** → **Read** and **Update**, **Resource servers** → **Read**, and **Service components** → **Object Types** → **Read** |
| See the key's API Identifier                               | **Client grants** → **Read**, **Resource servers** → **Read**, and **Service components** → **Object Types** → **Read**                |
| Reveal or copy the Client Secret                           | **Client secrets** → **Read**                                                                                                          |
| Rotate the Client Secret                                   | **Client secrets** → **Update**                                                                                                        |
| Change the name or description, or enable or disable a key | **Clients** → **Update**                                                                                                               |
| Delete a key                                               | **Clients** → **Delete** and **Client grants** → **Delete**                                                                            |

The key's **Permissions** tab lists the tenant's Object Types. It needs **Service components** → **Object Types** → **Read**, even if you don't give the key access to Object Types. If the tab shows **Couldn't load resource servers**, **Couldn't load grants**, or **Couldn't load Object Types**, check the matching permission.

The Console can show a control even when your Role doesn't allow the action. The service checks your permissions when you use the control.

### Get a Role for API Key work

If your Role lacks a permission that you need, ask an administrator to add it to your Role or to assign you another Role. An administrator can create a Role for API Key work:

1. In the navigation menu, under **Admin**, select **Roles**, then click **New role**.
2. Enter a **Name** and, optionally, a **Description**. Click **Create role**. The Role's **Permissions** tab opens.
3. Select the permissions for the tasks that the person needs. For example, to let someone create keys, set and change their permissions, and copy their Client Secrets, select:
   * **Tenant API** → **Clients** → **Read** and **Create**
   * **Tenant API** → **Client secrets** → **Read**
   * **Tenant API** → **Client grants** → **Read**, **Create**, and **Update**
   * **Tenant API** → **Resource servers** → **Read**
   * **Service components** → **Object Types** → **Read**
4. Click **Save permissions**.
5. Under **Admin**, select **Users**. In the person's row, click **Edit**. Under **Roles**, select the Role, then click **Save changes**.

You can't change the permissions of a system Role that the platform manages. To give different access, create a Role.

For these steps, the administrator's Role needs these permissions:

* **Tenant security** → **Roles** → **Read**, **Create**, and **Update**
* **Tenant security** → **Team members** → **Read** and **Update**
* **Service components** → **Object Types** → **Read**, because a Role's **Permissions** tab also lists the tenant's Object Types

## Set up API Key access

Each API Key has a Client ID and Client Secret, which an application exchanges for an access token. To set up access, create a key, assign its permissions, and get a token. To create a key and assign its permissions, your Role must have the [permissions for each task](#permissions-for-each-task).

### Create an API Key

1. In the Admin Console's navigation menu, under **Admin**, select **API Keys**.
2. Click **New API key**.
3. Enter a **Name** that identifies the key in lists.
4. Optionally, enter a **Description** of the key's purpose.
5. Click **Create API key**.

The Console opens the new key's **Permissions** tab. The key has no permissions until you save them there. You can change the name and description later.

### Assign permissions

The key's **Permissions** tab sets what the key's access tokens can do. These permissions belong to the key, not to your Role. Grant only the permissions that your application's operations need. Each API guide lists the permissions its operations use. The [generated Native Object API reference](https://docs.contextual.io/documentation-and-resources/tenants/tenant-apis/native-object-api.md#generated-reference-and-openapi) lists the scopes that each Native Object operation needs.

The tab sets the key's permissions for the Native Object API and shows its **API identifier**. Set permissions in these sections:

* **Service components**: Manage definitions and components, such as Object Types, AI Search Profiles, and Agents.
* **Object data & action execution**: Access Records and execute Actions for Object Types. Each row offers **Read**, **Create**, **Update**, **Delete**, **Execute**, and **Reveal**. For how **Reveal** affects secret values in Records, see [Secrets](https://docs.contextual.io/documentation-and-resources/components-and-data/object-types/object-type-details/data-schema/secret.md#single-record-get-responses). Use the **All Object Types** row for all current and future Object Types in the tenant, or the row for a specific Object Type.

When a wildcard row grants an action, the tab shows the cells it covers as checked and locked.

The two sections are separate. Permission to read an Object Type's Records does not by itself grant permission to change its definition. Administration and platform operations have their own caller and permission requirements.

After you select the permissions, click **Save permissions**. The first save creates the key's grant, and later saves update it. Permission changes can take up to about five minutes to apply in services that cache access checks.

To inspect a token's granted permissions, see the Auth Administration API's [caller requirements](https://docs.contextual.io/documentation-and-resources/tenants/tenant-apis/auth-administration-api.md#authentication-and-permissions) and [example request](https://docs.contextual.io/documentation-and-resources/tenants/tenant-apis/auth-administration-api.md#example-request). That API must accept the token. The result does not establish access to another API.

### Get and use an access token

Your application needs three values from the key.

* **Client ID** and **Client Secret**: On the **Settings** tab, under **Client details**, click the copy icon next to each value. The Client Secret is hidden by default; click the lock icon to reveal it in the browser.
* **API Identifier**: Shown as **API identifier** on the **Permissions** tab. Use it as the token request's `audience`.

Keep the Client Secret in trusted server-side code, and protect access tokens.

Send a `POST` request to `https://auth.<tenant-id>.my.contextual.io/oauth/token` with the `Content-Type: application/json` header. Replace `<tenant-id>` with your [tenant ID](#identify-the-tenant). In the following JSON body, replace `yourClientId` and `yourClientSecret` with the key's values. Replace the example `audience`, `https://contextual/no-api`, with the key's API Identifier.

```json
{
    "grant_type": "client_credentials",
    "client_id": "yourClientId",
    "client_secret": "yourClientSecret",
    "audience": "https://contextual/no-api"
}
```

A successful request returns an access token and its lifetime in seconds, as in this example response:

```json
{
    "expires_in": 86400,
    "access_token": "accessToken"
}
```

Send the token in the `Authorization: Bearer <access-token>` header. Use the returned `expires_in` value to request a new token before the current one expires.

The default tenant setup uses a shared API Identifier. You can reuse a token with APIs that support API Key tokens and accept that audience, with the required tenant context and permissions. Check each API guide before reusing a token.

## Manage an API Key

To manage a key, select it under **API Keys** and open its **Settings** tab. Each task needs the Role permissions in [Permissions for each task](#permissions-for-each-task).

### Edit details

Under **General**, change the **Name** or **Description**, then click **Save changes**. **Client details** shows the Client ID and Client Secret. To copy them, see [Get and use an access token](#get-and-use-an-access-token).

### Disable or delete a key

To disable or enable the key without deleting it, set **Status** under **General** to **Disabled** or **Enabled**, then click **Save changes**. The **API Keys** list shows an enabled key's status as **Active**. Disabling prevents new access tokens. Some services cache access checks for existing tokens for up to five minutes. Re-enabling allows unexpired tokens to be used again.

To remove the key and its permissions permanently, under **Danger zone**, click **Delete** next to **Delete API key**. Type the key's Client ID to confirm, then click **Delete API key**. You can't undo a deletion.

### Rotate the Client Secret

To replace the key's Client Secret, under **Danger zone**, click **Rotate** next to **Rotate client secret**. Type `rotate` to confirm, then click **Rotate secret**. Consider rotating the secret periodically. The old Client Secret stops working immediately, and you can't undo the rotation. Update applications and Client Grant Connections that use the key with the new Client Secret.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.contextual.io/documentation-and-resources/tenants/tenant-apis/authentication-and-permissions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
