---
url: https://api-doc.aive.com/getting-started/authentication.md
description: OAuth2 client credentials flow to authenticate API-to-API
---

# Authentication

The Aive API uses the **OAuth2 Client Credentials Flow** to authenticate API-to-API communication.

This authentication method is available for the **public GraphQL API**.

For more information about the OAuth2 Client Credentials Flow, see the [official OAuth 2.0 specification](https://www.rfc-editor.org/rfc/rfc6749#section-4.4).

Only users with the `Manage API Credentials` permission in a workspace can create OAuth2 clients and generate API credentials.

## Create an OAuth2 client

To create an OAuth2 client:

1. Sign in to [app.aive.com](https://app.aive.com) using your account credentials.
2. Go to **Profile → Manage API clients**.
3. Click **New API client**.
4. Fill in the required information and create the client.

The generated client provides:

* `client_id`: the identifier of your OAuth2 client.
* `client_secret`: the secret used to authenticate your client.

You can also configure the **access token validity duration**. This defines how long generated access tokens remain valid.

Since access tokens are sent over the network with each API request, we recommend setting a short expiration time (for example, **10 minutes**) to reduce security risks.

## Generate an access token

To authenticate API requests, you must first generate an access token using your `client_id` and `client_secret`.

Request an access token:

```bash
curl --request POST \
  --url https://hydra.aive.com/oauth2/token \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data client_id=<client_id> \
  --data client_secret=<client_secret> \
  --data grant_type=client_credentials
```

The response contains your access token:

```json
{
  "access_token": "<access_token>",
  "token_type": "bearer",
  "expires_in": 1800
}
```

## Use the access token

All requests to the public GraphQL API are `POST` requests to a single endpoint:

```text
https://graphql.aive.com/graphql
```

Include the access token in the `Authorization` header for every API request:

```http
Authorization: Bearer <access_token>
```

Example GraphQL request:

```bash
curl --request POST \
  --url https://graphql.aive.com/graphql \
  --header "Authorization: Bearer <access_token>" \
  --header "Content-Type: application/json" \
  --data '{"query":"query { viewer { id } }"}'
```

## Refresh an access token

OAuth2 Client Credentials Flow does not use refresh tokens.

When an access token expires, generate a new one by repeating the access token generation request using your `client_id` and `client_secret`.

For security reasons, avoid storing access tokens permanently. Generate them when needed and replace expired tokens.

## Next steps

* [Upload a container](/guides/upload-container) to start integrating media into Aive.
* [Event handling](/getting-started/event-handling) explains how to track asynchronous operations.
* [Error handling](/getting-started/error-handling) explains how mutations report failures.
