> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costory.io/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Billing Setup

> Connect OpenAI organization costs to Costory with a read-only Admin API key. Import Platform API usage into Explorer next to AWS, GCP, and Azure.

OpenAI Platform spend sits on a separate bill from AWS, GCP, and Azure. Connect with a **read-only Admin API key** so organization costs land in Explorer (Costory's main interface for exploring cloud costs across all connected providers.) with your other [billing datasources](https://docs.costory.io/setup/billing).

This connector imports **OpenAI Platform (API usage)** organization costs from the [Costs API](https://developers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/costs). Costory stores them as a billing datasource, the same as other SaaS billing sources.

> [!NOTE]
>
> Azure OpenAI (Cognitive Services) is billed through Azure. Use the [Azure billing connector](https://docs.costory.io/setup/billing/azure.md) for that spend. ChatGPT Enterprise and Codex are not on this connector.

> [tab] Manual setup
>
> **1. Create an Admin API key**
>
> In [OpenAI Platform > Settings > Admin keys](https://platform.openai.com/settings/organization/admin-keys), create an **Admin API key** (`sk-admin-...`). You must be an organization **admin**. A project inference key (`sk-...` or `sk-proj-...`) will not work. Copy the key immediately. It is shown once.
>
> **2. Grant read-only scopes**
>
> Grant **read-only** scopes only. Do not grant write.
>
> | Scope | API id | Required |
> | - | - | - |
> | **Usage** | `api.usage.read` | Yes. Costory cannot ingest spend without it. |
> | **API keys + Projects** | `api.management.read` | Recommended. Without it, spend still lands, but key, user, and project names stay as raw ids. |
>
> **3. Connect in Costory**
>
> Go to [Integrations](https://app.costory.io/integration), click **+ Add integration**, then choose **OpenAI** under **Billing**. The connect URL is `/integration/new/openai/billing`.&#x20;
>
> **4. Enter connection details**
>
> Fill **Connection name** (default **OpenAI**) and **Admin API key**. **Start date** is optional. Leave it empty to use Costory's default lookback.
>
> **5. Validate, then save**
>
> Click **Validate**. Costory calls `GET /v1/organization/costs` with `Authorization: Bearer`. **Save** stays disabled until the Admin key can read organization costs. If this is the only billing source and it is demo data, Costory asks you to confirm before replacing it.
>
> On first sync, Costory backfills up to **12 months** of organization costs, depending on what OpenAI retains. New data then follows the usual [data refresh](https://docs.costory.io/docs/data-refresh.md) cadence. SaaS sources typically appear in about **10 minutes**.

> [tab] Terraform
>
> To install and authenticate the provider, see [Terraform setup](https://docs.costory.io/setup/terraform.md).
>
> ```hcl theme={null}
> terraform {
>   required_providers {
>     costory = {
>       source  = "costory-io/costory"
>       version = ">= 0.1.0"
>     }
>   }
> }
>
> variable "costory_api_token" {
>   type        = string
>   description = "Costory API token."
>   sensitive   = true
> }
>
> variable "openai_admin_api_key" {
>   type        = string
>   description = "OpenAI admin API key used to fetch billing data."
>   sensitive   = true
> }
>
> provider "costory" {
>   token = var.costory_api_token
> }
>
> resource "costory_billing_datasource_openai" "main" {
>   name          = "OpenAI Billing"
>   admin_api_key = var.openai_admin_api_key
> }
> ```

## Field reference

| Field | Required | Description |
| - | - | - |
| **Connection name** | Yes | Label in **Integrations**. |
| **Admin API key** | Yes | Organization Admin key (`sk-admin-...`) with **Usage** read. Stored in Costory's secret manager. |
| **Start date** | No | Optional start of the first sync. Leave empty for the default lookback. |

## What Costory includes

Costory pulls organization costs from OpenAI's Costs API and maps them into Standard Columns (Costory's unified billing schema: the same dimensions everywhere (Provider, Billing account id, Service name, SKU ID, Region, Category, and more). In SQL and exports, column names use a cos\_ prefix (for example cos\_service\_name).).

Typical lines include billed Platform usage for that organization (models, line items, and the project or API key OpenAI returns on the Costs API).

**How to analyze OpenAI costs**

* Spend by project: one OpenAI **project** (and project key) per team is the split the Costs API exposes. Map those projects onto a [virtual dimension](https://docs.costory.io/features/tagging/dimensions.md) for showback. See [Allocate LLM cost per team](https://docs.costory.io/use-cases/llm-ai-cost.md).
* Spend by model or line item: group by **Service name** or **SKU**
* Spend by API key or user: names appear when the key has **API keys + Projects** read. Otherwise you see raw ids.

**What Costory does not include**

* Azure OpenAI charges (use the [Azure connector](https://docs.costory.io/setup/billing/azure.md))
* ChatGPT Enterprise or Codex billing
* Taxes, credits, or invoice adjustments outside the Costs API
* Per-request application metadata (feature, route, customer). OpenAI's export does not carry those labels.

> [!NOTE]
>
> Rotate the Admin API key from **Integrations** when you need a new credential. Keep **Usage** read on the replacement key.

## Troubleshooting

| Issue | What to check |
| - | - |
| Failed to authenticate | Confirm you pasted an **Admin API key** (`sk-admin-...`), not a project inference key. Recreate it in [Admin keys](https://platform.openai.com/settings/organization/admin-keys). |
| Access denied | Grant **Usage** (`api.usage.read`) on a **read-only** Admin key. |
| Costs API endpoint not found | Confirm the Admin API is enabled for this organization and that you are an organization admin. |
| Spend lands, names are raw ids | Add **API keys + Projects** (`api.management.read`). Costory does not block save when this scope is missing. |
| Validation succeeds but Explorer is empty | Wait for the first sync (about 10 minutes). Check the datasource date range on [Integrations](https://app.costory.io/integration). |

## Related pages

> [card] [Billing Data](https://docs.costory.io/setup/billing)
>
> All billing providers and shared setup notes.

> [card] [Anthropic billing](https://docs.costory.io/setup/billing/anthropic.md)
>
> Connect Anthropic Claude Console and claude.ai costs.

> [card] [OpenRouter billing](https://docs.costory.io/setup/billing/openrouter.md)
>
> Import OpenRouter organization costs with a Management API key.

> [card] [ElevenLabs billing](https://docs.costory.io/setup/billing/elevenlabs.md)
>
> Connect ElevenLabs workspace usage.

> [card] [Allocate LLM cost per team](https://docs.costory.io/use-cases/llm-ai-cost.md)
>
> Split OpenAI, Anthropic, and cloud LLM spend by team.

> [card] [Explorer](https://docs.costory.io/features/cost-explorer.md)
>
> Filter and group OpenAI spend with the rest of your stack.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.