# Codex in ChatGPT Desktop Setup Guide

OpenAI has merged the standalone Codex desktop app into ChatGPT Desktop. This guide covers configuring Codex inside ChatGPT Desktop on macOS and Windows: ChatGPT Desktop retains your ChatGPT OAuth login while sending model inference requests through your Brioi API key.

## Prerequisites

Make sure you have the following ready:

- [ChatGPT Desktop](https://chatgpt.com/download/) installed with access to Codex
- An active ChatGPT account
- An API key created on the [Brioi API Keys page](https://vip.brioi.com/keys) (recommended groups: `GPT | Pro`, `GPT | 特价` (discounted GPT), `GPT | Official`, or `auto`)

## 1. Sign In via ChatGPT OAuth

Open ChatGPT Desktop, follow the prompt to sign in, and complete authorization in your browser. Return to the desktop app and confirm your account menu shows you as signed in.

## 2. Set the API Key Environment Variable

Codex reads your Brioi API key from the `BRIOI_API_KEY` environment variable. Desktop GUI applications only read OS/session-level environment variables—a temporary `export` inside a terminal session will not take effect.

**Windows**: Run the command below in PowerShell, then completely quit and reopen ChatGPT Desktop.

```powershell
setx BRIOI_API_KEY "YOUR_API_KEY"
```

**macOS**: Run the command below in Terminal, then completely quit and reopen ChatGPT Desktop. Note that `launchctl setenv` clears after rebooting macOS—re-run it after a restart, or add a LaunchAgent under `~/Library/LaunchAgents/` to apply it automatically at login.

```bash
launchctl setenv BRIOI_API_KEY "YOUR_API_KEY"
```

## 3. Configure `config.toml`

Configuration is identical on macOS and Windows. In ChatGPT Desktop, open **Settings → Configuration → Open config.toml** and add or merge the following:

```toml
model = "gpt-6-astra"
model_provider = "brioi"

[model_providers.brioi]
name = "Brioi"
base_url = "https://vip.brioi.com/v1"
wire_api = "responses"
env_key = "BRIOI_API_KEY"
supports_websockets = false
```

You can change `model` to any primary GPT model available to your key (such as `gpt-6.2-sol`, `gpt-6.1-sol`, `gpt-6.2-astra`, or `gpt-6-astra`, according to `GET /v1/models`). `base_url` must end with `/v1` (with `/v1` included only once). Save the file, then completely quit and reopen ChatGPT Desktop.

## 4. Verify the Integration

1. Confirm in the desktop app's account menu that ChatGPT OAuth remains signed in.
2. Create a new task and send a minimal test prompt:

```text
Reply with only BRIOI_CODEX_OK
```

3. Check the request logs page in the Brioi console to verify that the request arrived.

## Troubleshooting

### Desktop app returns `401` or `API_KEY_REQUIRED`

- Verify `env_key` is set to `BRIOI_API_KEY`.
- Confirm `BRIOI_API_KEY` was set as a system/session environment variable per Step 2, and that ChatGPT Desktop was completely quit and reopened afterward.
- Confirm `base_url` is exactly `https://vip.brioi.com/v1`.
- Verify that the API key is enabled, has a positive balance, and belongs to a group that includes the target model.
- Remove or disable `requires_openai_auth = true` under `[model_providers.brioi]`.

### OAuth sign-in succeeds, but model requests do not route through Brioi

Check that `model_provider` is set to `brioi` and `env_key` is `BRIOI_API_KEY`. After saving `config.toml`, you must completely quit and reopen the desktop app.

## Security Reminders

- Never share ChatGPT OAuth tokens, API keys, or `auth.json` in group chats, screenshots, repositories, or public logs.
- If you suspect an API key has been exposed, disable and regenerate it immediately on the API key management page.

