> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Authenticate with the Box Agents API

> Authenticate Box Agents API requests with OAuth 2.0, JWT, or Client Credentials Grant, and act on behalf of a managed user.

Every Agents API request needs an access token in the `Authorization` header. The flow you use to get the token determines whose Box permissions the agent uses.

| Flow | Use when | The agent acts as |
| - | - | - |
| OAuth 2.0 | A person signs in to your app | The signed-in user |
| JWT | You build a headless or backend integration with a public and private keypair | The app's service account, or a managed user |
| Client Credentials Grant (CCG) | You build a headless or backend integration with a client ID and client secret | The app's service account, or a managed user |

The agent can reach only content that this identity can already access, regardless of what you reference in the request. If you pass a file ID the caller can't see, the agent behaves as if the content doesn't exist.

Before you start, [set up a platform app](https://developer.box.com/ai/agents-api/index.md#set-up-a-platform-app) with the required scopes.

## OAuth 2.0

Follow the [OAuth 2.0 guide](https://developer.box.com/guides/authentication/oauth2/index) to get an access token, then pass it in the `Authorization` header. The token is tied to the user who authorized your app, so the agent's access matches that user's access.

Create a **User** platform app in the [Developer Console](https://app.box.com/developers/console), configure at least one redirect URI, and enable the scopes listed in [Set up a platform app](https://developer.box.com/ai/agents-api/index.md#set-up-a-platform-app). To get the token, see [OAuth 2.0 with SDKs](https://developer.box.com/guides/authentication/oauth2/with-sdk.md) or [OAuth 2.0 without SDKs](https://developer.box.com/guides/authentication/oauth2/without-sdk.md).

For an example request with an OAuth 2.0 token, see [Send your first request](https://developer.box.com/ai/agents-api/index.md#send-your-first-request).

## JWT

Create a **Server** app, [set up JWT](https://developer.box.com/guides/authentication/jwt/jwt-setup.md), and have an admin authorize the app. New Server apps preselect Client Credentials Grant, so select **JWT** when you create the app. By default, the token belongs to the app's service account. The agent sees only content that the service account owns or is collaborated on.

To get a service account token, see [JWT with SDKs](https://developer.box.com/guides/authentication/jwt/with-sdk.md) or [JWT without SDKs](https://developer.box.com/guides/authentication/jwt/without-sdk.md).

Call the API with the service account token or developer token:

```bash cURL theme={null}
curl -sS -X POST "https://api.box.com/a2a/message:send" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "A2A-Version: 1.0" \
  -H "Content-Type: application/json" \
  -d '{"message":{"messageId":"m-1","role":"ROLE_USER",
       "parts":[{"text":"Summarize the contracts filed this quarter."}]}}'
```

### Act on behalf of a managed user

To have the agent use a specific user's permissions instead of the service account's, add the `as-user` header with that user's ID. Before you do, configure your app:

* Set **App Access Level** to **App + Enterprise Access** in the Developer Console.
* In **Configuration** > **Additional Configuration**, enable **Make API calls using the as-user header**.

```bash cURL theme={null}
curl -sS -X POST "https://api.box.com/a2a/message:send" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "as-user: 12345678" \
  -H "A2A-Version: 1.0" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "messageId": "'"$(uuidgen)"'",
      "role": "ROLE_USER",
      "parts": [
        { "text": "Summarize the attached contract." },
        {
          "data": { "id": "1728901234567", "type": "file" },
          "mediaType": "application/vnd.box.source-reference+json"
        }
      ]
    }
  }'
```

When you use `as-user`:

* The authenticated identity must be an Admin or Co-Admin.
* You can't pass the service account's own user ID.
* You can reach only content that the enterprise owns or controls.
* Passing the authenticated user's own ID returns `403 Forbidden`.

To get a user identity without the `as-user` header, generate a [user access token](https://developer.box.com/guides/authentication/jwt/user-access-tokens.md) and use it like a service account token.

## Client Credentials Grant

Create a **Server** app with [Client Credentials Grant](https://developer.box.com/guides/authentication/client-credentials/index), and have an admin authorize the app. Your app exchanges its client ID and client secret for an access token, and the subject you request the token for determines whose permissions the agent uses:

| Act as | `box_subject_type` | `box_subject_id` | Also required |
| - | - | - | - |
| The app's service account | `enterprise` | Your enterprise ID | Nothing beyond app authorization |
| An App User | `user` | The App User's ID | **Generate User Access Tokens** |
| A managed user or an admin | `user` | The user's ID | **App + Enterprise Access** and **Generate User Access Tokens** |

To set up the app and request a token, see [Set up an app with Client Credentials Grant](https://developer.box.com/guides/authentication/client-credentials/client-credentials-setup.md). Send the token in the `Authorization` header, as in the [JWT example](#jwt). CCG tokens expire after 60 minutes and don't come with a refresh token, so request a new token when the current one expires.

**RELATED GUIDES**
