# Analytics API

> **Note:**
> This feature is currently in preview and available for all organizations participating in the [Early Access Program (EAP)](ai-settings.html#eap). It may change and become a paid feature later. For more information, see [Plans and pricing](plans-and-pricing.html).

The Analytics API provides programmatic access to the AI usage data for your organization. Use it to retrieve metrics on AI adoption, activity, credits consumption, and other metrics that may be relevant across your teams and tools.

The API comes in two different versions:

* [API v2 (version 2)](analytics-api-v2.html). The latest version of the API with the most up-to-date endpoints and functionalities.

* [API v1 (version 1)](analytics-api-v1.html). The original version of the Analytics API, available for compatibility. Note that this API version will be officially deprecated in the future.

## API URL

### Base URL

The base URL for all Analytics API requests is:

```
https://api.jetbrains.cloud/metrics/
```

### Endpoints

All API requests are made to Analytics API endpoints, such as:

```
https://api.jetbrains.cloud/metrics/api/v2/adoption/limit-hits/group-by/date
```

The endpoint structure consists of the following elements:

| Element | Value | Description |
| --- | --- | --- |
| Base URL | `https://api.jetbrains.cloud/metrics` | The base URL for all Analytics API requests. |
| API version | `/api/v2` | The current API version prefix for all endpoints. |
| Endpoint path | `/adoption/limit-hits/group-by/date` | The specific resource within the Analytics API. |

## Authentication

Requests to the Analytics API require an access token passed as a bearer token within the `Authorization` header. To get an access token, make sure to complete the following steps:

Procedure:

1. [Create a service account](service-accounts.html#add-service-account) to use for the Analytics API. Service accounts let application and service integrations and automations use account credentials that are not tied to a specific user but are specifically created for integration with an application or service. Each service account includes a client ID and client secret.

> **Note:**
> To access the Analytics API, make sure that at least one role assigned to the service account you are using to access the API includes the [View AI analytics](roles.html#permissions_view_ai_analytics) permission. The data returned by the API is limited to the scope of the role: an organization-wide role returns data for the whole organization, while a group-scoped role returns data only for members of the groups that the role provides permissions for, including their subgroups.
>
>
>
> For more information on how permissions affect the returned data, see [Data visibility](ai-analytics.html#data-visibility). Note that the [View AI analytics (self)](roles.html#permissions_view_ai_analytics_self) and [Manage organization](roles.html#permissions_manage_org) permissions don't apply to service accounts and are thus not relevant for Analytics API access.

2. Follow the instructions on how client ID and [client secret are exchanged for an
access token](exchange-client-id-and-secret-for-an-access-token.html). An access token is valid for 60 minutes, so this process needs to be repeated when the token expires.

