> ## Documentation Index
> Fetch the complete documentation index at: /help/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

> Call OpenAI's API from a campaign step with your own key and prompt, and use the answer in the next message.

> [!NOTE]
>
> **Pro plan.** OpenAI works through a connection and HTTP steps, which are part of Pro and Agency (and the free trial). Anything you already have keeps working on every plan. See [Plans and billing](/help/account/billing.md).

A **Webhook / HTTP** step sends the contact's headline, title and company to OpenAI with your prompt and your model. The answer is available to the next message.

Kerux also has its own AI (the **Ask AI** step, reply types, writing help), paid with Kerux's AI credits. This guide is for teams that want their own OpenAI account, model and prompts.

> [!NOTE]
>
> **How it connects:** OpenAI's API with your key as a bearer token. See OpenAI's [Chat Completions](https://platform.openai.com/docs/api-reference/chat/create) reference. The answer below follows OpenAI's docs; the model id is yours to choose.

## Before you start

* **OpenAI billing:** the API is billed per token on your OpenAI account, separately from ChatGPT plans.
* **An API key:** create a project key in the OpenAI platform.
* **Data:** only the fields you put in the prompt go to OpenAI, under your agreement with OpenAI.

## 1. Connect OpenAI

In Kerux, open **Integrations > Connections**, click **Connect** on **Custom API** (under **Developers**):

* **How it signs in:** **Bearer token**, paste the key.
* **Base URL:** `https://api.openai.com`

Click **Save**, then **Test connection**.

## 2. Ask for the line

Add a **Webhook / HTTP** step named `openai`, pick the connection:

```json theme={null}
{
  "method": "POST",
  "url": "/v1/chat/completions",
  "bodyType": "json",
  "body": {
    "model": "YOUR_MODEL_ID",
    "messages": [
      { "role": "system", "content": "Write one friendly opening line for a LinkedIn message. No greeting, no emojis, under 25 words." },
      { "role": "user", "content": "Title: {{contact.title}}. Headline: {{contact.headline}}. Company: {{contact.company}}." }
    ]
  }
}
```

OpenAI answers (trimmed):

```json theme={null}
{ "choices": [{ "message": { "role": "assistant", "content": "Saw Northwind is opening a Berlin office, congrats." } }] }
```

In the next message: `{{steps.openai.response.body.choices.0.message.content}}`, followed by your own text.

## 3. Keep it safe

* Test on a few contacts before launching, and read the lines.
* If the call fails, the contact stops in **Needs attention** with OpenAI's message; nothing odd goes out.

## Test with one contact

In the **Builder**, click **Test** to open **Test on one contact**. The journey shows the prompt that was sent and OpenAI's answer.

## Common errors

> [accordion] 401 invalid\_api\_key
>
> The key is wrong or was revoked. Create a new one and edit the connection.

> [accordion] 404 model\_not\_found
>
> The model id is wrong or your project can't use it. Check the model in OpenAI's docs and your project's limits.

> [accordion] 429 rate limit or insufficient\_quota
>
> Too many calls, or no credit left on the account. Kerux retries rate limits later; add credit for quota errors.

Related: [Webhook steps](/help/integrations/webhook-steps.md), [Claude (Anthropic API)](/help/integration-guides/anthropic-claude.md), [Variables reference](/help/campaigns/variables-reference.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.