# OpenAI --- The OpenAI provider authenticates the **Codex agent** — and the **opencode agent** when it runs OpenAI models — with an OpenAI API key from your own OpenAI account. Usage is billed by OpenAI directly. If you're new to configuring providers, start with the [LLM Providers](/docs/ai-providers/llm-providers/) overview — it covers where the settings live, how keys are stored, and how rotation works for every provider. ## Adding an OpenAI key 1. Create a key at platform.openai.com/api-keys. 2. In the dashboard, go to **Organization Settings → Agents → LLM Providers**. 3. On the **OpenAI Direct** card, paste the key into the **API key** field. It starts with `sk-`. 4. Click **Save**. You'll get an "OpenAI Direct saved" confirmation, and the field collapses to a masked display. ## Rotating Click **Replace** next to the masked key, paste the new one, and save. The existing key stays active until the new one is saved — see [Rotating a key](/docs/ai-providers/llm-providers/#rotating-a-key). **Remove** deletes the credential entirely. ## Troubleshooting - **"API key looks too short"** — you probably copied a partial value. Re-copy the whole key from the OpenAI console. - **A Task fails with an authentication error** — the saved key may have been revoked or may have hit a spend limit. Check the key's status in the OpenAI console, then rotate it using **Replace**. - **Runs fail after switching agents** — the OpenAI key serves the Codex agent, and opencode on OpenAI models. If you've switched to the Claude Code agent or an Anthropic model, configure [Anthropic](/docs/ai-providers/anthropic/) as well; agents never fall back to another provider's key. --- Source: https://deployment.io/docs/ai-providers/openai/