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

# Connect ChatGPT

> On Connect and Pro, link your ChatGPT account so interviews, style builds and Codex-eligible chat models run on your ChatGPT plan instead of credits.

# Connect ChatGPT

On the **Connect** and **Pro** plans, you can link a ChatGPT account. [Interviews](#interviews),
[style builds](https://docs.headwaters.ai/guides/style.md) and the face's side of a [benchmark](https://docs.headwaters.ai/guides/benchmark.md#price)
then run on your ChatGPT plan where the model allows it, so that work costs you no API credits.
So does a Codex-eligible downstream model on [chat](https://docs.headwaters.ai/guides/chat.md#running-on-a-linked-chatgpt-plan)
at `/v1/responses` (`codex_eligible: true` in [`GET /v1/models`](https://docs.headwaters.ai/guides/models#listing-the-models)).

[Choices](https://docs.headwaters.ai/guides/choices.md), and the steering of [chat](https://docs.headwaters.ai/guides/chat.md) and
[decisions](https://docs.headwaters.ai/guides/decisions.md), are not affected: they are billed from your plan's
[allowance](https://docs.headwaters.ai/guides/billing.md#allowances), then from credits, whether or not ChatGPT is linked.

***

## Link a ChatGPT account

Linking uses a device code: you get a short code, the user enters it at OpenAI in any
browser, and approves. No browser extension and no callback URL are needed.

Linking, listing and unlinking take a [signed-in session](https://docs.headwaters.ai/authentication.md#what-needs-a-signed-in-session):
an API key answers `403`.

### Step 1: start

```bash theme={null}
curl -X POST https://api.faces.sh/v1/oauth/openai/device/start \
  -H "Authorization: Bearer YOUR_JWT"
```

```json theme={null}
{
  "device_auth_id": "uuid",
  "user_code": "QUHO-OSQNW",
  "verification_uri": "https://auth.openai.com/…",
  "interval": 5,
  "expires_at": "2026-05-28T11:13:36.575545Z"
}
```

Show the user `user_code` and `verification_uri`, exactly as returned. Keep `device_auth_id`
for polling. The code expires at `expires_at`, after 15 minutes.

> [!NOTE]
>
> **First-time setup.** ChatGPT requires device codes to be enabled once per account. Ask
> users to open **[chatgpt.com/#settings/Security](https://chatgpt.com/#settings/Security)**
> (the panel can take a few seconds to appear) and turn on **"Enable device code
> authorization for Codex"** before they approve. On Team, Business and Enterprise
> workspaces, a workspace admin must turn it on.

### Step 2: the user approves

The user opens `verification_uri`, enters `user_code`, signs in to ChatGPT, and approves.

### Step 3: poll until complete

```bash theme={null}
curl -X POST https://api.faces.sh/v1/oauth/openai/device/poll \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{"device_auth_id": "uuid"}'
```

```json theme={null}
{
  "status": "pending",
  "retry_after": null,
  "chatgpt_account_id": null,
  "chatgpt_plan_type": null,
  "account_email": null
}
```

Poll every `interval` seconds:

| `status` | Meaning |
| - | - |
| `pending` | Not approved yet. Poll again after `interval` seconds, or after `retry_after` seconds when it is set. |
| `completed` | Linked. `account_email` and `chatgpt_plan_type` are returned, and readable later from `GET /v1/oauth`. Stop polling. |
| `expired` | The code expired, or the id is unknown. Start again from Step 1. |

### Cancel

```bash theme={null}
curl -X POST https://api.faces.sh/v1/oauth/openai/device/cancel \
  -H "Authorization: Bearer YOUR_JWT" \
  -H "Content-Type: application/json" \
  -d '{"device_auth_id": "uuid"}'
```

Returns `204`, even if the code is already gone. Call it when the user gives up.

### Errors on start

| Status | Body | Meaning |
| - | - | - |
| `403` | `{"detail": {"error": "connect_plan_required", "message": "..."}}` | Not on the Connect or Pro plan. |
| `422` | `{"detail": {"error": "device_auth_not_enabled", "message": "...", "settings_url": "...", "settings_steps": [...]}}` | Device codes are not enabled on the ChatGPT account. See the first-time setup above. |
| `503` | `{"detail": "..."}` | Linking could not start or finish just now. The message says which; retry, or start linking again. |

***

## See the linked account

```bash theme={null}
curl https://api.faces.sh/v1/oauth \
  -H "Authorization: Bearer YOUR_JWT"
```

```json theme={null}
[
  {
    "provider": "openai",
    "scope": "openid profile email offline_access",
    "connected_at": "2026-05-28T11:07:06.080492Z",
    "chatgpt_account_id": "acct_...",
    "chatgpt_plan_type": "plus",
    "account_email": "you@example.com"
  }
]
```

Show "Connected as [you@example.com](mailto:you@example.com) (Plus)" from `account_email` and `chatgpt_plan_type`. A
`chatgpt_plan_type` of `null` or `"free"` is a ChatGPT plan that cannot be used this way.

***

## Unlink

```bash theme={null}
curl -X DELETE https://api.faces.sh/v1/oauth/openai \
  -H "Authorization: Bearer YOUR_JWT"
```

Returns `204 No Content`, whether or not an account was linked.

***

## When ChatGPT is unavailable

On Connect and Pro subscriptions, the `api_fallback` preference is `false` by default: if ChatGPT is
unavailable or refuses the request, it fails rather than being paid from credits. Turn it on
to fall back to credits:

```bash theme={null}
curl -X PATCH https://api.faces.sh/v1/user/preferences \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"api_fallback": true}'
```

Per request, `"interviewer_billing_source": "oauth"` on an interview, or `oauth_only` on a
style build, refuses to fall back, whatever the preference says. A request parameter wins
over the stored preference.

On Free there is no ChatGPT route: `api_fallback` is always `true`, and setting it to `false`
is a `422` `oauth_only_unavailable`. Nothing is charged.

### Errors when ChatGPT refuses

When ChatGPT refuses and fallback is off, the error is under `detail`:

```json theme={null}
HTTP 422
{
  "detail": {
    "error": "oauth_rejected",
    "detail": "...",
    "provider_status": 400,
    "fallback_available": true
  }
}
```

| `error` | When | What to do |
| - | - | - |
| `oauth_rejected` | ChatGPT refused the request, or no account is linked | `provider_status` carries OpenAI's status. |
| `model_not_supported` | The model is not available on this ChatGPT plan (`400`) | Pick another model. |
| `oauth_workspace_residency` | The workspace's data-residency setting does not allow this (`401`) | No client-side fix. |
| `oauth_rate_limited` | The ChatGPT plan's usage limit is reached (`429`) | Try later. When OpenAI says when it resets, the body adds `retry_after_seconds` and `resets_at` (unix time) and the response carries `Retry-After`. |
| `oauth_incomplete` | ChatGPT stopped its reply before finishing, twice in a row (`503`) | Retry. Nothing was charged. |

| Field | Description |
| - | - |
| `detail` | A readable explanation. |
| `provider_status` | OpenAI's HTTP status. `null` when the request was refused before reaching OpenAI; absent on `oauth_incomplete`. |
| `fallback_available` | `true` if your credit balance could pay for a retry with `api_fallback` on. |

#### A reply that stops partway

ChatGPT sometimes ends a reply without finishing it. Faces retries once. If the second try
also stops short, `api_fallback` decides:

* **on:** the work is paid from credits, like any other fallback;
* **off:** `503 oauth_incomplete`, and nothing is charged.

A style build with `oauth_only` never falls back: it retries, then fails.

***

## Staying linked

The link renews itself before it expires, so a request after a quiet spell does not fail. If
renewal fails, link the account again.

***

## Interviews

[Interview threads](https://docs.headwaters.ai/guides/compile.md#interview-threads) use the linked ChatGPT plan
automatically on Connect and Pro. The
[`interviewer_billing_source`](https://docs.headwaters.ai/guides/compile#interviewer-billing-source) field in each
response says which was used: `"oauth"` or
`"credits"`.

If the interviewer model is not one ChatGPT serves, an interview on the `oauth` route is a
`422` with `"error": "oauth_rejected"` and `"fallback_available": false`, before anything is
sent. It is never moved to your credits.
An interview with `interviewer_billing_source: "credits"` is not affected.


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