> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/cloud-cost-management/integrations/ai-providers/openai.md).

# OpenAI

Connect OpenAI to bring your large language model (LLM) spend into Cloud & AI Cost Management alongside your cloud costs.

Connecting OpenAI brings your OpenAI spend into Harness Cloud & AI Cost Management alongside your cloud costs. The connector uses an Admin API key with read-only access to pull usage and cost data from your OpenAI account. You can analyze AI spend in Cost Explorer, attribute it with Views and Cost Categories, and govern it with budgets and anomaly detection, the same way you manage cloud costs.

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

**OpenAI Admin API key:** An Admin API key with read-only access from your OpenAI account. The key enables Harness to ingest billing and usage data. Go to the [OpenAI Admin API keys reference](https://developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/admin_api_keys/methods/create) to create one.

## Create the OpenAI Admin API key <a href="#create-the-openai-admin-api-key" id="create-the-openai-admin-api-key"></a>

1. Sign in to the OpenAI platform at [platform.openai.com](https://platform.openai.com) as an organization **Owner**. Only organization Owners can create Admin API keys.
2. Go to **Settings** > **Organization** > **Admin keys**, or open [platform.openai.com/settings/organization/admin-keys](https://platform.openai.com/settings/organization/admin-keys) directly.
3. Click **Create new Admin key** and give it a descriptive name, for example, `Harness CCM Integration`.
4. Under **Permissions**, click **Read only** to grant read access to all scopes at once, or click **Restricted** and set **Organization Administration** and **Usage API Scope** to **Read**.
5. Click **Create Admin key**.
6. Copy the key and store it securely. OpenAI does not display the key again after creation.

## Set up the OpenAI connector <a href="#set-up-the-openai-connector" id="set-up-the-openai-connector"></a>

To connect OpenAI, go to **Cloud & AI Cost Management** > **Account Settings** > **AI Providers**, click **AI Provider**, then select **OpenAI**.

### Step 1: Name the connector <a href="#step-1-name-the-connector" id="step-1-name-the-connector"></a>

1. On the **Overview** panel, enter a **Name** for the connector.
2. Optionally, add a **Description** and **Tags** to organize and filter connectors.

<figure><img src="https://1217180450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2HVWkYMptNUG08jo8hr%2Fuploads%2Fgit-blob-543a44cb8bd93b2fc75d00c9ffb937a5d57cee12%2Fopenai-one.png?alt=media" alt="OpenAI connector Overview panel"><figcaption><p>Click to view full size image</p></figcaption></figure>

3. Click **Continue**.

### Step 2: Add the connector details <a href="#step-2-add-the-connector-details" id="step-2-add-the-connector-details"></a>

On the **Connector Details** panel, confirm the API endpoint and provide the OpenAI Admin API key you created in [Create the OpenAI Admin API key](#create-the-openai-admin-api-key) as a Harness secret. Do the following:

1. In the **URL** field, do not change the default `https://api.openai.com/v1` unless you have a custom endpoint.

   <figure><img src="https://1217180450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2HVWkYMptNUG08jo8hr%2Fuploads%2Fgit-blob-a6750dac51b0de743f91ed29dda8366e4c31142b%2Fopenai-two.png?alt=media" alt="OpenAI connector URL field"><figcaption><p>Click to view full size image</p></figcaption></figure>
2. In the **API Key** field, click **Create or Select a Secret**.
   * To use an existing secret that contains your OpenAI Admin API key, select it from the list, then click **Apply Selected**.
   * To add a new secret, click **New Secret Text**, enter a **Secret Name**, and provide the OpenAI Admin API key you created as the **Secret Value**.

     <figure><img src="https://1217180450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2HVWkYMptNUG08jo8hr%2Fuploads%2Fgit-blob-58b7ae2b64a3b6c37f2336fbd6410271c7c952b1%2Fopenai-three.png?alt=media" alt="New Secret Text panel for an OpenAI API key"><figcaption><p>Click to view full size image</p></figcaption></figure>

     Go to [Add and reference text secrets](https://developer.harness.io/harness-ai/use-harness-platform/secrets/add-use-text-secrets) to review all secret creation options.
3. Click **Continue**.

### Step 3: Verify the connection <a href="#step-3-verify-the-connection" id="step-3-verify-the-connection"></a>

On the **Connection Test** panel, Harness validates the API key against your OpenAI account. Once the verification is successful, click **Finish** to create the connector.

<figure><img src="https://1217180450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FO2HVWkYMptNUG08jo8hr%2Fuploads%2Fgit-blob-11d7e71e08c7cbc2340d7e00647dece88b3400a0%2Fopenai-five.png?alt=media" alt="OpenAI connector Connection Test panel"><figcaption><p>Click to view full size image</p></figcaption></figure>

{% @harness-feedback/feedback %}
