Platform
Chatbot Builder Bulk Messaging Team Inbox Mini CRM API & Webhooks AI Integration WhatsApp Flows
Industries
E-commerce & D2C Real Estate Education Healthcare Finance & BFSI Logistics Hospitality Retail
Integrations
Learn
Learning Hub Help & Docs Connect Guides Automation Codex Blog Message Templates
Pricing Get Started →
Connect  ›  Connect OpenAI to WhatsApp
AI connection guide

Connect OpenAI to WhatsApp

Add GPT's reasoning to a WhatsApp chatbot. This guide covers every field in the External API Request step, including the bearer token OpenAI uses, the messages array it expects, and where to find the reply in the response.

 Published 21 June 2026  9 min read  Live-researched  Bring your own key

OpenAI's chat completions endpoint is the most widely used AI API in the world, and it connects to WA.Expert through the same External API Request step as every other provider. The main differences from Gemini: auth goes in an Authorization: Bearer header (not a custom header), and the messages array lets you set a system persona alongside the customer's question.

If you have not read the foundation guide on the External API Request step, read that first. This guide assumes you know the seven fields and focuses on what OpenAI specifically needs.

Step 1: Get your OpenAI API key

1

Sign in to OpenAI's platform

Go to platform.openai.com and sign in or create an account. API access is separate from the ChatGPT chat product. You need the platform account to use the API.
2

Create an API key

Under your account menu, open API Keys and click to create a new secret key. Name it something meaningful like wa-expert-chatbot. Copy it immediately; OpenAI only shows it once. The key starts with sk-.
3

Add billing and set a usage limit

Go to the Usage section and add a payment method. Optionally set a monthly spending limit so a runaway loop cannot run up a large bill. The limit does not affect normal use; it is a safety net.

 Official source

For the current model list and rate limits, see OpenAI's official docs: platform.openai.com/docs/models. Model names change over time; check there before pinning a version.

Step 2: Fill in the External API Request step

Here is the complete configuration. Each field is explained below.

External API Request
Method
POST
Request URL
https://api.openai.com/v1/chat/completions
Auth Type
Bearer token
Header Parameters
Authorization
Bearer YOUR_OPENAI_KEY
Content-Type
application/json
Body Type
JSON (raw)
Response Type
Default Response
SaveRun and Save

Method

POST. You are sending a conversation to the model.

Request URL

Request URL
https://api.openai.com/v1/chat/completions

This URL does not change with the model; you specify the model in the request body. That means switching from gpt-4o-mini to gpt-4o only requires changing one word in the body, not the URL.

Auth and headers

Header nameValue
AuthorizationBearer YOUR_KEY (replace with your sk- key)
Content-Typeapplication/json

OpenAI uses standard HTTP Bearer auth. The word Bearer is part of the value, not the header name.

Body

The messages array is the key difference from Gemini. It lets you stack a system instruction before the customer's message, which shapes how the model behaves.

JSON body
{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful support assistant for {{business_name}}. Answer briefly and politely."
    },
    {
      "role": "user",
      "content": "{{customer_message}}"
    }
  ],
  "max_tokens": 300
}

Replace {{business_name}} with a fixed value or map it from your flow. Replace {{customer_message}} with the value from the conversation. max_tokens limits the reply length, which also limits cost.

Step 3: Map the reply into WhatsApp

The model's answer sits inside the choices array. OpenAI always returns at least one choice when the call succeeds, and the text you want is inside the first one.

Where the answer sits in the response
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "...the model's reply is here..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": { "total_tokens": 87 }
}

Map choices[0].message.content into your next WhatsApp message step. Set Response Type to Default Response and the field will be available to reference.

 Keep the WhatsApp reply in the free window

When a customer messages your bot, a 24-hour service window opens. Replies sent inside it are free on the WhatsApp side. So when your bot responds with OpenAI's answer, you pay OpenAI for the tokens but nothing extra on WhatsApp.

Worked example: a returns and refund assistant

A customer messages: 'I got the wrong size, how do I return it?' Your bot does not have a scripted answer for this phrasing. The flow routes it to the OpenAI step with a system message that explains your policy.

Body for a policy-aware assistant
{
  "model": "gpt-4o-mini",
  "messages": [
    {
      "role": "system",
      "content": "You are the support assistant for an online clothing store. Our return policy: items can be returned within 30 days with the original receipt for a full refund. No returns on sale items. Answer customer questions about this policy briefly."
    },
    {
      "role": "user",
      "content": "{{customer_message}}"
    }
  ],
  "max_tokens": 200
}

The model reads the policy from the system message and replies with a coherent, accurate answer in the customer's language. You never scripted that specific question; the AI covered it from the policy context you gave it.

Troubleshooting

SymptomLikely causeFix
401 UnauthorizedAPI key wrong, expired, or missing the Bearer prefixCheck the key in platform.openai.com; confirm the header value starts with Bearer (with a space)
429 Too Many RequestsRate limit or monthly quota hitCheck usage limits in platform.openai.com; raise the limit or add billing
400 Bad RequestMalformed JSON body or missing required fieldValidate the JSON; check that model and messages are both present
Empty or cut-off replymax_tokens too lowRaise max_tokens, or remove the limit for conversational replies
Wrong answerSystem message not specific enoughTighten the system message; add your actual policy or FAQ content directly into it

The response from OpenAI almost always contains an error field with a clear message. Read it before troubleshooting further.

Common questions

Where do I get an OpenAI API key?
+
Sign in or create an account at platform.openai.com, go to API Keys under your account menu, and create a new secret key. Copy it immediately since it is only shown once. Keys start with sk-. You will need to add billing details in the Usage section before the key works on paid tiers.
Which OpenAI model should I use for a WhatsApp chatbot?
+
For most WhatsApp chatbot replies, gpt-4o-mini is the best starting point: fast, cheap, and capable enough for customer-service-style tasks. Use gpt-4o when you need stronger reasoning, document analysis, or multimodal input. Always use a pinned model ID for production so a model update does not change your bot's behaviour unexpectedly.
What does the 'role' field do in the messages array?
+
The messages array lets you give the model context beyond the customer's message. A 'system' role message sets the bot's persona and rules. A 'user' role is the customer. An 'assistant' role shows what the bot said before, which you include for multi-turn conversations. For a simple single-turn reply, you only need one user message.
Is the OpenAI API free?
+
OpenAI has a free trial credit for new accounts, but ongoing usage is billed per token. You set up a payment method at platform.openai.com and set usage limits to cap costs. WA.Expert does not add any markup to OpenAI's charges; you pay OpenAI directly based on the tokens your requests and replies use.
What if the API returns an error?
+
The most common errors are 401 (wrong or missing API key), 429 (rate limit or quota exceeded), and 400 (malformed request body). The response almost always contains a JSON error message that names the exact problem. Check the key, check your usage limits at platform.openai.com, and validate the JSON body you are sending.
Does the WhatsApp reply cost anything on WA.Expert?
+
WA.Expert does not charge for the External API Request step beyond it being a standard automation action. The WhatsApp reply you send back is free if the customer is inside an active 24-hour service window, which is usually the case when someone has just messaged your bot.
Related

Keep building

Put GPT inside every WhatsApp conversation.

Free trial, no credit card required. And if you ever get stuck, we are the only platform in India that answers you live on WhatsApp.

Start Free →Book Demo
1