[
    {
        "role": "user",
        "content": "I%27ve%20installed%20OpenAI%27s%20Codex%2C%20desktop%20client%20for%20Windows.%20Is%20there%20a%20way%20to%20add%20a%20API%20Key%20to%20it%20that%20I%27ve%20used%2C%20to%20pull%20from%20that%20paid%20account."
    },
    {
        "role": "assistant",
        "content": "Yes \u2014 you *can* use an API key with OpenAI\u2019s Codex (CLI or app) on Windows if you want your usage billed against your paid OpenAI API account instead of using your ChatGPT/subscription plan. Here\u2019s how to do that, plus what to watch out for:\n\n---\n\n## What the official docs say\n\n- **Codex CLI** supports multiple authentication methods including using an *API key*. You can provide the key either via environment variables or piping it into `codex login --with-api-key`. ([mintlify.com](https://www.mintlify.com/openai/codex/cli/login?utm_source=openai))  \n- **Codex app (desktop client)** is primarily intended to be used by signing in with your **ChatGPT account** (Plus, Pro, Business, etc.). That gives you features included in your plan. However, the documentation mentions that if you used an API key before, you can use `codex logout` then log in again to shift between plan-based authentication vs API-key usage. ([help.openai.com](https://help.openai.com/en/articles/11369540/?utm_source=openai))\n\n---\n\n## How to set it up on Windows\n\nIf you want to use your API key, here's a general step-by-step:\n\n1. **Create an API Key**  \n   Go to [platform.openai.com \u2192 API Keys](https://platform.openai.com/api-keys) and generate a new key if you don\u2019t already have one.  \n\n2. **Install Codex CLI or open the Codex app**, if you haven\u2019t already.  \n   If you're using the app, note: some features or flows will still encourage signing in with ChatGPT. With the CLI, API key usage is more straightforward. ([help.openai.com](https://help.openai.com/en/articles/11369540-codex-in-chatgpt?utm_source=openai))\n\n3. **Set the environment variable**  \n   In PowerShell, temporarily (for the current session), run:  \n   ```\n   $env:OPENAI_API_KEY = \"sk-\u2026\"\n   ```\n   To make it persistent across sessions, add to your PowerShell profile:  \n   ```\n   Add-Content -Path $PROFILE -Value '$env:OPENAI_API_KEY = \"sk-\u2026\"'\n   ```\n\n4. **Login using the API key** (for CLI)  \n   Use:  \n   ```\n   codex login --with-api-key\n   ```\n   And pipe in the key, e.g.:\n   ```\n   echo \"sk-\u2026\" | codex login --with-api-key\n   ```\n   Then verify with:\n   ```\n   codex login status\n   ```\n   ([mintlify.com](https://www.mintlify.com/openai/codex/cli/login?utm_source=openai))\n\n5. **Edit config file if necessary**  \n   There\u2019s a config file (look in `%USERPROFILE%\\.codex\\config.toml`) where you can set things like default model, approval mode, sandbox settings, etc. If you want behavior to persist (e.g. a particular model), you can set those here. ([lineserve.net](https://www.lineserve.net/guides/windows-installation-guide-for-codex-cli?utm_source=openai))\n\n6. **Using the App**  \n   If you're using the Codex desktop app, setting the API key might not always be directly supported via UI. The app tends to prefer authentication via ChatGPT sign-in. However, having the environment variable set and/or using the config file might allow it to pick up the API key. Some users report that when an `OPENAI_API_KEY` env var is present, the app changes behavior (potentially using API-quota). ([reddit.com](https://www.reddit.com/r/ChatGPT/comments/1sknhuj/codex_may_switch_itself_to_api_usage_from/?utm_source=openai))\n\n---\n\n## Things to watch out for & trade-offs\n\n- **Billing separation**: If you use an API key, usage is billed through the OpenAI API (separate from your ChatGPT plan limits), so costs can add up depending on how much Codex makes API calls. Using your plan via ChatGPT OAuth usually uses plan-included usage. ([help.openai.com](https://help.openai.com/en/articles/11369540/?utm_source=openai))  \n- **Feature differences**: Some features might only work when signed in with a ChatGPT account rather than via API key. Sometimes newer models, or plan-specific features, are gated behind subscriptions.  \n- **Credential storage**: On Windows, API keys or login tokens are stored securely (e.g. in Windows Credential Manager or your config directory). If switching between auth methods, clean up old credentials to avoid conflicts. ([mintlify.com](https://www.mintlify.com/openai/codex/cli/login?utm_source=openai))\n\n---\n\nIf you tell me whether you're using **Codex CLI** or the **desktop app**, and what your Windows version is, I can give you the exact commands for your setup."
    }
]