> For the complete documentation index, see [llms.txt](https://integrations.drivetrain.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/authentication-and-api-keys.md).

# Authentication and API keys

Get, reset and revoke a Drivetrain API key, and see exactly which of your Drivetrain permissions each API endpoint applies.

Every call to the [Drivetrain API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api.md) carries an API key in the `apikey` request header. The key belongs to one Drivetrain user, and every call runs as that user.

{% hint style="info" %}
**Before you start**

* **Role:** you need the **Admin** role to view or reset an API key, and the key only works while its user has the **Admin** role.
* **Subscription:** your subscription must include Drivetrain API access. Without it, **Settings** doesn't show **API Key** and every call returns `401 Unauthorized`, even with a valid key. Contact Drivetrain support to enable it.
* **Host:** use the host you open Drivetrain on (see [Base URL](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api.md#base-url)). A key only works on its own workspace's host.
  {% endhint %}

## Send the key

Add the `apikey` header to every request. There's no token exchange, session or `Authorization: Bearer` header.

```bash
curl 'https://{your_subdomain}.drivetrain.ai/drive/api/v1/public/versions' \
  --header 'apikey: {your_apikey}'
```

Send the key exactly as copied.

## Get your API key

1. Navigate to **Settings** > **API Key**.
2. Under **Your API key**, the key is masked except for its first and last 4 characters. Click the eye icon (**Show key**) to reveal it, or click **Copy**. The button changes to **Copied**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-5d6ad62a25fd8354f1a4898062e2f018b409df41%2Fdrivetrain-api-01.jpg?alt=media" alt=""><figcaption><p>API key accessible within Settings</p></figcaption></figure>

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-c938a90071c2aebf3100fcafcb686870fe323bbc%2Fdrivetrain-api-02.jpg?alt=media" alt=""><figcaption><p>Click on Copy to copy your API key</p></figcaption></figure>

Drivetrain creates your key the first time you open **Settings** > **API Key**. After that you see the same key every time you open it, until you reset it.

## About keys

|                   |                                                                                                                                                                 |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Format**        | A 32-character string of letters and digits.                                                                                                                    |
| **Keys per user** | One. Each Admin has their own key.                                                                                                                              |
| **Acts as**       | The user who owns it. Calls have that user's Drivetrain access (see [What the API applies from your permissions](#what-the-api-applies-from-your-permissions)). |
| **Scope**         | No scopes or read-only keys. A key can call every endpoint of the API.                                                                                          |
| **Expiry**        | None. A key works until it's reset, its user is deactivated or loses the **Admin** role, or API access leaves your subscription.                                |
| **Workspace**     | A key works only in the workspace it was created in.                                                                                                            |

Treat the key like a password. Anyone who has it can read your data and replace list rows as you.

## Reset (rotate) a key

1. Navigate to **Settings** > **API Key**.
2. Click **Reset Key**.

The new key replaces the old one immediately, with no confirmation step. Every integration still using the old key starts getting `401 Unauthorized`, so update them right after you reset.

Reset only changes your own key. To rotate with no downtime, use a second Admin user's key for the switch-over.

## Revoke access

There's no separate revoke button. Depending on whose key it is:

| To stop...         | Do this                                              | Calls then return                                        |
| ------------------ | ---------------------------------------------------- | -------------------------------------------------------- |
| Your own key       | Click **Reset Key** and don't use the new one.       | `401 Unauthorized`                                       |
| Another user's key | Deactivate the user, or remove their **Admin** role. | `401` (deactivated) or `403 Forbidden` (no longer Admin) |

If a deactivated user is reactivated, their old key works again. Reset it if it may have leaked.

{% hint style="info" %}
Create keys from a dedicated Admin user for long-running integrations, so a person leaving or changing roles doesn't break them.
{% endhint %}

## What the API applies from your permissions

Every endpoint checks that the key's user has the **Admin** role, and returns `403 Forbidden` if not. An Admin has access to every version and scenario. Beyond that, each endpoint applies the user's other Drivetrain access differently:

| Endpoint                                                                                                                                            | What it applies                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [Get metric list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-metric-list-api.md)                                | Admin role only. Returns every metric.                                                                           |
| [Get metrics bulk data API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-metrics-bulk-data-api.md)                    | Admin role only. Returns values for every dimension value, even values the user's roles hide in Drivetrain.      |
| [Get dimension list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-dimension-list-api.md)                          | Admin role only. Lists every dimension.                                                                          |
| [Get dimension values API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-dimension-values-api.md)                      | The user needs full access to the dimension. Otherwise `403`, never a partial list.                              |
| [Get version list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-version-list-api.md)                              | Admin role only. Returns every version.                                                                          |
| [Get scenario list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-scenario-list-api.md)                            | Returns the scenarios the user can access, which for an Admin is every scenario.                                 |
| [Get list API](https://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/get-list-api.md)                                              | The user needs access to the list. Rows the user can't see aren't returned.                                      |
| [Upload list CSV API](https://github.com/DrivetrainAi/gitbook-integrations/tree/main/en/extending-drivetrain/drivetrain-api/upload-list-csv-api.md) | The user needs full access to the list, and no limited access to any dimension that's also a column of the list. |

If someone must not see every value, don't give them the **Admin** role or an Admin's API key.

## FAQ

<details>

<summary>Can a user without the Admin role use the API?</summary>

No. Every endpoint returns `403 Forbidden` for a key whose user doesn't have the **Admin** role, and only Admins can view a key.

</details>

<details>

<summary>Can I create a read-only key, or a key for just one endpoint?</summary>

No. Keys have no scopes. Of the endpoints in this section, only [Upload list CSV API](https://github.com/DrivetrainAi/gitbook-integrations/tree/main/en/extending-drivetrain/drivetrain-api/upload-list-csv-api.md) changes data, and it needs full access to the list.

</details>

<details>

<summary>I reset my key by mistake. Can I get the old one back?</summary>

No. Copy the new key from **Settings** > **API Key** and update every integration that used the old one.

</details>

<details>

<summary>A colleague who set up our integration left. What happens?</summary>

When their user is deactivated, their key stops working and calls return `401 Unauthorized`. Have another Admin copy their own key into the integration.

</details>


---

# 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://integrations.drivetrain.ai/extending-drivetrain/drivetrain-api/authentication-and-api-keys.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.
