# OpenAI

Learn how to connect Buddy with OpenAI and run the Codex CLI action in your CI/CD pipelines.

## What is OpenAI?

OpenAI is the AI company behind **GPT**, a family of large language models, and **Codex**, an agentic coding assistant that can read, write, and refactor code from natural-language prompts.

By integrating Buddy with OpenAI you can add the **Codex CLI** action to your [pipelines](/docs/ai-agents/pipelines.md) and let Codex review code, generate changes, or automate routine engineering tasks on every push, on a schedule, or on demand.

## Setting up OpenAI integration

1. Go to the <u>Integrations</u> tab and click **New integration**.

2. Look up and click **OpenAI**.

![OpenAI on the list of available integrations](/docs/integrations/openai/openai-new-integration.png 1400x905)

3. A configuration window will show up. Here you provide:

- **Name** and **ID** of the integration
- **Scope** - whether the integration is available across the whole <u>Workspace</u>, a single <u>Project</u>, or a specific <u>Environment</u>
- **API key** - your OpenAI secret key (see below)

<Hint type="info">

You can adjust who can use the integration and where in the <u>Permissions</u> tab.

</Hint>

4. Once done, click **Add a new integration** to finish configuration.

![OpenAI integration configuration with API key authorization](/docs/integrations/openai/openai-api-key.png 1400x667)

## Authorization

Authorize with an OpenAI secret key. The value always starts with `sk-`.

To obtain the key:

1. Go to [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys "seo-nf") (also linked as **Get API key** in the form) and click **Create new secret key**.

![API keys section in the OpenAI platform](/docs/integrations/openai/platform-api-keys.png 1400x649)

2. Name the key, pick the project it belongs to, and set its permissions.

![Creating a new secret key in the OpenAI platform](/docs/integrations/openai/platform-create-key.png 900x928)

3. Copy the generated key - the platform shows it only once.

![Save your key window in the OpenAI platform](/docs/integrations/openai/platform-save-key.png 940x820)

4. Paste it into the **API KEY** field in Buddy and click **Add a new integration**. The key is stored as an encrypted secret and passed to the pipeline as a secure environment variable, never saved in plain text in your repository.

### Scoping key permissions

Codex needs to call the model endpoints, so an **All** or **Read only** key will not always be enough on its own. If you prefer to narrow down what the key can do, switch <u>Permissions</u> to **Restricted** and grant only the resources the agent actually uses - **Model capabilities** is the minimum for running prompts.

![Restricted permissions for an OpenAI secret key](/docs/integrations/openai/platform-key-permissions.png 700x1358)

<Hint type="warning">

A key with **All** permissions can read and write every resource in the selected project, including files and fine-tuning jobs. Create a dedicated key per integration so you can revoke it without breaking anything else.

</Hint>

Once the integration is added, you can use the **Codex CLI** action in your pipeline and reference the integration by its ID.

<Hint type="info">

Read how to configure [Codex CLI with YAML](/docs/yaml/yaml-actions/codex-cli.md) and [Codex CLI POST parameters](/docs/api/actions/add/codex-cli.md).

</Hint>


---
Original source: https://buddy.works/docs/integrations/openai