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.
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.
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.
Here is the complete configuration. Each field is explained below.
POST. You are sending a conversation to the model.
https://api.openai.com/v1/chat/completionsThis 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.
| Header name | Value |
|---|---|
| Authorization | Bearer YOUR_KEY (replace with your sk- key) |
| Content-Type | application/json |
OpenAI uses standard HTTP Bearer auth. The word Bearer is part of the value, not the header name.
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.
{
"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.
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.
{
"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.
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.
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.
{
"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.
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 Unauthorized | API key wrong, expired, or missing the Bearer prefix | Check the key in platform.openai.com; confirm the header value starts with Bearer (with a space) |
| 429 Too Many Requests | Rate limit or monthly quota hit | Check usage limits in platform.openai.com; raise the limit or add billing |
| 400 Bad Request | Malformed JSON body or missing required field | Validate the JSON; check that model and messages are both present |
| Empty or cut-off reply | max_tokens too low | Raise max_tokens, or remove the limit for conversational replies |
| Wrong answer | System message not specific enough | Tighten 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.
Every field explained, the foundation for all connection guides.
Read foundation guide →Google's AI, free tier, different auth pattern from OpenAI.
Read guide →A different auth pattern: x-api-key plus a required version header.
Read guide →Every service you can wire into WhatsApp.
Browse all →What the built-in AI step offers vs bring-your-own key.
Read more →Endpoint, token, bearer, defined.
Open glossary →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.