> 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/integration-guide/readme/ai-and-llm-cost/integrating-with-openai.md).

# Integrating with OpenAI

When you connect [OpenAI](https://openai.com/) to Drivetrain, your organization's projects, members, API keys, completions token usage, and daily cost breakdown sync automatically. You can then track and forecast AI spend next to the rest of your financials.

This guide walks you through creating an OpenAI Admin API key and adding OpenAI as a data source in Drivetrain.

{% hint style="info" %}
The OpenAI connector is **read-only**. Drivetrain only pulls organization, usage, and cost data from OpenAI and never writes anything back.
{% endhint %}

## Prerequisites

To connect OpenAI to Drivetrain, you need:

* An OpenAI API Platform organization at [platform.openai.com](https://platform.openai.com/).
* The **admin** or **owner** role in that organization. Only admins and owners can create Admin API keys. You can check your role in **Organization settings > People**.
* Access to your Drivetrain workspace with permission to add data sources.

{% hint style="info" %}
This connector covers usage and cost on the OpenAI API Platform. It doesn't sync ChatGPT workspace seats or subscriptions (ChatGPT Team or Enterprise).
{% endhint %}

## What Drivetrain syncs from OpenAI

Once connected, Drivetrain pulls the following from your OpenAI organization:

* **Projects**: the projects set up in your organization.
* **Members**: the users in your organization.
* **API keys**: the API keys created in your organization.
* **Completions token usage**: tokens consumed by completions requests.
* **Daily cost breakdown**: what your organization spends each day.

This data lands in Drivetrain as the following tables:

| Table             | What it contains                                    | One row per                           |
| ----------------- | --------------------------------------------------- | ------------------------------------- |
| Costs             | Billed cost in USD                                  | Day, project and line item            |
| Completions Usage | Input, output and cached tokens, and request counts | Day, project, user, API key and model |
| Projects          | Projects in your organization                       | Project                               |
| Users             | Members of your organization and their roles        | User                                  |
| Project Users     | Members of each project                             | Project and user                      |
| Project API Keys  | API keys in each project                            | API key                               |
| Admin API Keys    | Admin keys in your organization                     | Admin key                             |

{% hint style="info" %}
**Costs** matches what OpenAI bills you, so use it for actuals. OpenAI only breaks billed cost down by project and line item, so use **Completions Usage** to analyze usage by model or API key.
{% endhint %}

OpenAI only makes the last 12 months of usage and cost available, so that's the history Drivetrain syncs. Each sync re-reads the last 3 days to pick up late cost adjustments from OpenAI.

## OpenAI Setup: Create an Admin API key

Drivetrain connects with an Admin API key, which starts with `sk-admin-`. A standard project API key (`sk-proj-...`) doesn't have access to organization usage and cost data, so it won't work.

### Step 1: Open Admin keys

1. Sign in to the [OpenAI API Platform](https://platform.openai.com/).
2. Click your profile icon in the bottom-left corner and select **Organization settings**.
3. Click **Admin keys** in the left sidebar.

### Step 2: Create the key

1. Click **+ Create new Admin key**.
2. Enter a descriptive **Name**, such as **Drivetrain Integration**.
3. Choose an **Expiration**. The default is **Never**.
4. Set **Permissions** to **Read only**. Drivetrain only reads data, so it doesn't need broader access.
5. Click **Create admin key**.

{% hint style="info" %}
If you set an expiration, the connection stops syncing when the key expires. Create a new key and update the connection in Drivetrain before then.
{% endhint %}

### Step 3: Copy and store the key

OpenAI shows the key only once and you can't retrieve it later. Copy it right away and store it in a password manager. You'll paste it into Drivetrain in the next section.

{% hint style="warning" %}
Treat the Admin API key like a password. Never share it publicly or commit it to source control, and revoke it from **Organization settings > Admin keys** if it's ever compromised.
{% endhint %}

## Drivetrain Setup: Add OpenAI as a data source

### Step 1: Open Data and add a source

In Drivetrain, go to **Data** in the left navigation, then click the **+** button to add a new data source.

### Step 2: Select the OpenAI connector

In the **Connect a data source** window, search for **OpenAI** and select it under **AI & LLM Cost**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-8f7ad26bd1a66098b67d700b07bf5ed5a912ffb9%2Fai-llm-cost-connect-a-data-source.webp?alt=media" alt="The Connect a data source window with Anthropic and OpenAI listed under AI &#x26; LLM Cost"><figcaption></figcaption></figure>

### Step 3: Enter your Admin API key

On the **Connect your OpenAI account** screen, paste the key you copied into the **Admin API Key** field, then click **Submit**.

<figure><img src="https://4220329029-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmBZR0D9lq6jrI895OuOU%2Fuploads%2Fgit-blob-d475afa7ec3ccf98bb63547e8be24799d8b07c84%2Fopenai-connect-your-account.webp?alt=media" alt="The Connect your OpenAI account screen with the Admin API Key field"><figcaption></figcaption></figure>

### Step 4: Confirm the connection

OpenAI now shows as a connected data source and starts syncing. Your usage and cost data appears in Drivetrain once the first sync finishes.

{% hint style="info" %}
If you have trouble connecting OpenAI or don't see your data after the sync, contact your Drivetrain CSM.
{% endhint %}

## FAQ

**Can I use a regular OpenAI API key instead of an Admin API key?**

No. Only Admin API keys (starting with `sk-admin-`) can read your organization's usage and cost data. Project API keys can't.

**Does this connector include ChatGPT subscription costs?**

No. The connector syncs usage and cost from the OpenAI API Platform. ChatGPT Team and Enterprise seat costs aren't included.

**Can I connect more than one OpenAI organization?**

Yes. Add a separate OpenAI data source for each organization, each with its own Admin API key.


---

# 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/integration-guide/readme/ai-and-llm-cost/integrating-with-openai.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.
