# OpenAI

![OpenAI_logo.jpg|400](https://assets.relyanceuat.xyz/images/docs/42514909149581/ext-0640763886.jpg)

#### **Overview**

Relyance AI connects to the OpenAI API platform (platform.openai.com). The connection uses these keys:

- **Project API key (required).** A restricted project key with Read access. Relyance uses this key to find your models, files, fine-tuning jobs, and vector stores.
- **Admin key (optional).** An organization Admin key with Read only access. Relyance uses this key to read model usage. Models that are in use then show in **AI Models**.

If you do not add the Admin key, Relyance finds your models but does not show them as in use.

You also give your Project ID and Organization ID. The keys give read access only. Relyance cannot create, change, or delete resources in your OpenAI organization.

#### **Step 1: Locate Organization and Project IDs**

Before creating the key, please retrieve the following identifiers required for API authentication:

1. **Organization ID:** Navigate to **Settings > Organization > General**. Copy the string labeled "Organization ID" (starts with org- ).
2. **Project ID:** Navigate to **Settings > Project > General**. Copy the string labeled "Project ID" (starts with proj- ).

#### **Step 2: Initialize API Key Creation**

1. Log in to the **OpenAI Developer Dashboard**.
2. **Select Project:** Confirm you are in the correct Project context via the dashboard selector in the top-left navigation.
3. **Navigate to API Keys:** Select the "API Keys" section from the primary navigation menu.
4. **Create Key:** Click "Create new secret key."
5. **Labeling:** Assign a descriptive name to the key for auditing purposes (**e.g.,** Relyance_Key).
6. **Set Scope:** Change the permission setting from "All" to **"Restricted."**

#### **Step 3: Define Restricted Permissions**

In the permissions grid, locate the following endpoints and adjust the access levels to **Read** only. Ensure that no "Write," "Modify," or "Delete" permissions are enabled.

| **Resource Endpoint**| **Description**| **Required Permission** |
| --- | --- | --- |
| **Files** | Metadata for uploaded datasets | Read |
| **Fine-tuning** | Fine-tuning job history and status | Read |
| **Models** | List of available base and custom models | Read |
| **Vector Stores** | Metadata for embedding stores | Read |

*Note: For endpoints that provide a binary choice between "None" and "Read," ensure "Read" is selected to allow the application to view the necessary metadata.*

#### **Step 4: Create an Admin key (optional, for model usage)**

Do this step if you want Relyance to show which models are in use. Only an organization **Owner** can create an Admin key.

1. Log in to the OpenAI platform at https://platform.openai.com.
2. Go to **Settings > Organization > Admin keys**.
3. Select **Create new admin key**.
4. Enter a name for the key (for example, Relyance_Usage).
5. Set **Expiration** as your security policy requires.
6. Select **Read only**.
7. Create the key, then copy it.

OpenAI shows the key one time only. The key starts with `sk-admin-`. Keep it in a safe location until you enter it in Relyance AI.

> **Note.** The Admin key cannot read models. You must also give the project API key from Steps 2 and 3.

#### **Step 5: Initialize Integration in Relyance AI**

![Screenshot](https://assets.relyanceuat.xyz/images/docs/42514909149581/42514849042701.png)
1. Navigate to the **Integrations** page within the Relyance application.
2. Select the **OpenAI** integration card.
3. Review the integration overview and click **Next**.

    The **Authentication** step asks for:

    - **API Key**: Your OpenAI API key from https://platform.openai.com/api-keys; required; held as a secret.
    - **Project ID**: OpenAI project ID (required for organization accounts); required; held as a secret.
    - **Organization ID**: OpenAI organization ID (optional, for organization accounts); optional; held as a secret.
    - **Admin API Key (for model usage)**: The OpenAI Admin key from Step 4. Relyance uses it to read model usage; optional; held as a secret.

#### **Step 6: Configure Scan Parameters**

![Screenshot](https://assets.relyanceuat.xyz/images/docs/42514909149581/42514849043085.png)
1. Define the desired **Scan Interval** (the frequency at which the application will check for data updates).
2. **Recommendation:** Utilize the default settings provided to ensure optimal performance and data currency.
3. Click **Next** to proceed to authentication.

#### **Step 7: Authenticate and Finalize**

1. **Input Credentials:** Enter the **Restricted API Key**, **Organization ID**, and **Project ID** from the previous steps. If you created an Admin key in Step 4, enter it in **Admin API Key (for model usage)**.
2. **Verify Connection:** Click **Authenticate** to establish the connection.
3. **Completion:** Once the authentication is successful, the integration will begin its initial metadata scan.

![Screenshot](https://assets.relyanceuat.xyz/images/docs/42514909149581/42514849048077.png)

#### **Troubleshooting: models do not show as in use**

If your models do not show as in use in **AI Models**, do these steps:

1. Make sure that the connection has an Admin key in **Admin API Key (for model usage)**.
2. Make sure that the Admin key has **Read only** access and is not expired.
3. Run a new scan.

Relyance shows model usage for the last 7 days of activity.

<!-- terraform-examples:begin (generated from the integration catalog; do not hand-edit) -->

## Manage this integration with Terraform

Connections for this integration can be managed as code with the [Relyance Terraform provider](https://registry.terraform.io/providers/Relyance/relyance/latest). Non-secret fields go in `auth.params`; secret fields go in `auth.secrets_wo`, which is write-only — never stored in Terraform state. Rotate secrets by bumping `auth.secrets_wo_version`.

```hcl
resource "relyance_integration_connection" "openai" {
  vendor = "openai"
  name   = "<your connection name>"

  auth = {
    method = "api-key"
    params = {
      data_storage_location = "us"
    }
    # Secret fields are write-only: sent to Relyance, never stored in state.
    secrets_wo = {
      api_key = var.openai_api_key
      project_id = var.openai_project_id
      organization_id = var.openai_organization_id
    }
    secrets_wo_version = 1
  }

  scans = { "data-inspection" = { enabled = true } }
}
```

<!-- terraform-examples:end -->
