# Using OpenAI with Kilo Code | Setup & Models

> Connect the official OpenAI API to Kilo Code. Step-by-step guide to creating an API key and configuring GPT models in VS Code and the CLI.

- 网址：https://funcoding.ai/agents/kilo-code/ai-providers/openai/
- 来源：Kilo Code 官方文档原文（英文），MIT 许可，同步于 2026-10-11
- 官方原文：https://kilo.ai/docs/ai-providers/openai

---
Kilo Code supports accessing models directly through the official OpenAI API.

**Website:** [https://openai.com/](https://openai.com/)

<div class="callout callout-tip">

**Want to use your ChatGPT subscription instead?** Connect **OpenAI (ChatGPT subscription)** on Kilo's BYOK page, or sign in to OpenAI directly in VS Code or the CLI. These are separate from the API-key setup below. See [ChatGPT subscription setup](https://funcoding.ai/agents/kilo-code/ai-providers/openai-chatgpt-plus-pro/) for supported usage, limits, and billing details.

</div>

An OpenAI API key uses your OpenAI Platform billing account, not your ChatGPT subscription. Signing in to Kilo with ChatGPT also does not automatically connect your subscription for model usage.

## Getting an API Key

1.  **Sign Up/Sign In:** Go to the [OpenAI Platform](https://platform.openai.com/). Create an account or sign in.
2.  **Navigate to API Keys:** Go to the [API keys](https://platform.openai.com/api-keys) page.
3.  **Create a Key:** Click "Create new secret key". Give your key a descriptive name (e.g., "Kilo Code").
4.  **Copy the Key:** **Important:** Copy the API key _immediately_. You will not be able to see it again. Store it securely.

## Configuration in Kilo Code

**VSCode**

Open **Settings** (gear icon) and go to the **Providers** tab to add OpenAI and enter your API key.

The extension stores this in your `kilo.json` config file. You can also edit the config file directly — see the **CLI** tab for the file format.

**CLI**

Set the API key as an environment variable or configure it in your `kilo.json` config file:

**Environment variable:**

```bash
export OPENAI_API_KEY="your-api-key"
```

**Config file** (`~/.config/kilo/kilo.json` or `./kilo.json`):

```jsonc
{
  "provider": {
    "openai": {
      "env": ["OPENAI_API_KEY"],
    },
  },
}
```

Then set your default model:

```jsonc
{
  "model": "openai/gpt-4.1",
}
```

## Tips and Notes

- **Pricing:** Refer to the [OpenAI Pricing](https://openai.com/pricing) page for details on model costs.
- **Azure OpenAI Service:** Use Kilo Code's native `azure` provider for Azure OpenAI, especially GPT-5 deployments. Do not configure Azure GPT-5 through a generic [OpenAI-compatible](https://funcoding.ai/agents/kilo-code/ai-providers/openai-compatible/) custom provider.
