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 📝 Blog 🗂 Codex Pricing Start Free Trial →
Connect  ›  Connect Gemini to WhatsApp
AI connection guide

Connect Google Gemini to WhatsApp

Give your WhatsApp chatbot a brain. This guide connects Google's Gemini AI to WA.Expert through the External API Request step, so your bot can answer open questions in its own words.

 Published 21 June 2026  9 min read  Sourced & dated  Bring your own API key

A normal chatbot can only answer what you scripted. Connect it to Gemini and it can handle questions you never anticipated, in natural language, drawing on the model's general knowledge or on context you feed it. You do this with one External API Request step that sends the customer's message to Gemini and brings the answer back into the chat.

This guide gives you the exact values to use. If you have not met the External API Request step before, read the field-by-field foundation guide first; here we assume you know what the fields are and focus on what Gemini specifically needs.

 Gemini is moving quickly right now

Google is mid-way through changes to how Gemini keys work and which model names are current. Because of that, this guide leans on the durable parts, the endpoint shape, the header name, the body structure, and links you to Google's live documentation for the two things that drift: the exact model name and the latest key rules. If a specific name here looks different in your console, trust the console and Google's docs; the method below still applies.

Step 1: Get your Gemini API key

The key is what proves the request is yours. You get it from Google AI Studio, which is the lightweight developer path (as opposed to the heavier enterprise route through Vertex AI).

1

Sign in to Google AI Studio

Go to Google AI Studio at aistudio.google.com and sign in with a Google account. Every key is tied to a Google Cloud project, which AI Studio can create for you.
2

Open the API Keys page and create a key

On the API Keys page, choose to create a new key. Keys created in AI Studio now come restricted by default, which is what Google requires. Copy the key, it is a long string beginning with AIza, and store it somewhere safe like a password manager.
3

Confirm the key is restricted

If you are reusing an older key, make sure it has an API restriction limiting it to the Generative Language API. Unrestricted keys are now rejected. You can add the restriction in AI Studio or in the Google Cloud Console under the project's credentials.

 Official source

For the current key rules, which Google is actively updating through 2026, see Google's own page: Using Gemini API keys. This is the authority for what a valid key needs today.

Step 2: Fill in the External API Request step

Now the request itself. Here is exactly how the step should look, followed by each value.

2. External API Request
×
Select Method
POST
Request URL
https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent
Select Auth Type
API key in header
Header Parameters
x-goog-api-key
YOUR_GEMINI_API_KEY
Content-Type
application/json
Query Parameters
+ Add Query Parameters
Select Body Type
JSON (raw)
Choose Response Type
Default Response
SaveRun and Save

Method

POST. You are sending the model a prompt, so this is a send, not a read.

Request URL

The generateContent endpoint for your chosen model. The shape is fixed; only the model name in the middle changes as Google releases new versions.

Request URL
https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash:generateContent

The endpoint uses v1beta (this is correct, not a typo; most current features land there first). Replace the model name with the current stable model from Google's models documentation if it has changed.

Auth and headers

Gemini takes the key in a header. Add two header parameters:

Header nameValue
x-goog-api-keyYour Gemini API key (the AIza... string)
Content-Typeapplication/json

The x-goog-api-key header is Google's current recommended method. Avoid the older key= URL parameter, which exposes the key in logs.

Body

Set Body Type to JSON and send the contents structure Gemini expects. Put the customer's message where the text is, pulling it from your flow rather than hard-coding it.

JSON body
{
  "contents": [
    {
      "parts": [
        { "text": "{{customer_message}}" }
      ]
    }
  ]
}

Here {{customer_message}} is a placeholder for the value you map in from the conversation. You can also prepend instructions, for example a sentence telling Gemini to answer as your business's support assistant, before the customer's text.

Step 3: Map the reply back into the chat

Gemini answers with a JSON structure. The text you want sits inside the candidates list, in the content's parts. Set Response Type to Default Response and map that field into the next step, a WhatsApp message back to the customer.

Where the answer sits in the response
{
  "candidates": [
    {
      "content": {
        "parts": [
          { "text": "...the model's answer is here..." }
        ]
      }
    }
  ]
}

So the path to the answer is the first candidate, then content, then the first part, then text. Map that into your reply message and the customer receives Gemini's response inside WhatsApp, in the same conversation, with no app-switching.

 Keep the WhatsApp reply inside the free window

When a customer messages your bot, a 24-hour service window is open, so the reply carrying Gemini's answer is free on the WhatsApp side. You only pay Google for the Gemini usage. Sending AI replies as part of an ongoing customer conversation is therefore cheap: free WhatsApp delivery, plus Google's per-token charge for the AI itself.

A worked example: an AI FAQ assistant

A customer messages your store asking something your scripted bot does not cover, say, whether a fabric is machine washable. Your flow catches the unmatched question and routes it to the Gemini step. You prepend a short instruction so the model stays on-brand, then send the customer's question.

Body with a system-style instruction
{
  "contents": [
    {
      "parts": [
        { "text": "You are the support assistant for a clothing store. Answer briefly and politely. Customer question: {{customer_message}}" }
      ]
    }
  ]
}

Gemini replies with a short, polite answer, your flow maps it into a WhatsApp message, and the customer gets a useful response in seconds. For anything the model should not handle, an order change, a refund, you route to a human instead. The AI covers the long tail of open questions; people handle the decisions that matter.

Troubleshooting

SymptomLikely causeFix
403 or authentication errorKey is unrestricted, or wrong header nameRestrict the key to the Generative Language API, or create a new key; check the header is exactly x-goog-api-key
404 not foundModel name in the URL is wrong or retiredCheck Google's models docs for the current model name and update the URL
400 bad requestBody JSON is malformed or the text field is emptyValidate the JSON; confirm {{customer_message}} is being mapped in and is not blank
429 too many requestsFree-tier rate limit hitSlow the requests, or enable billing on the Google Cloud project for higher limits
Empty replyMapped the wrong path in the responseMap from candidates, then content, then parts, then text, in that order

The response the step returns almost always contains Google's own error message, which names the exact problem. Read it first.

 Why a 404 is the one to expect over time

Of all these, the 404 from a retired model name is the most likely to hit you months from now, because Google retires older model versions on a schedule. If your working bot suddenly returns 404s, the model name in your URL has almost certainly been deprecated. Swap in the current stable model from Google's docs and it works again, nothing else needs to change.

Common questions

Is the Gemini API free?
+
Google offers a free tier through Google AI Studio with limited rates, enough for testing and light use. The newest models are paid-tier only, and free-tier limits have tightened over time. For anything beyond low volume you enable billing on your Google Cloud project. Always check your AI Studio dashboard for the current limits, as Google changes them.
Which Gemini model should I use?
+
For a WhatsApp chatbot reply, a fast Flash-class model is the sensible default: it is quick and inexpensive, which matters when a customer is waiting. The exact current model name changes as Google releases new versions, so check Google's models documentation for the latest stable name and put that in your endpoint URL. The setup does not change when the model name does; only the URL does.
Where does the API key go, header or URL?
+
Use the header. Google's current guidance is to send the key in an x-goog-api-key header rather than as a key= value in the URL. The older URL method still works for backward compatibility, but the header form is more secure because the key does not appear in logs or browser history, and it is what Google's docs now show.
Why did my Gemini key suddenly stop working?
+
Google now requires API keys to have restrictions applied; unrestricted keys are rejected. If a previously working key stopped, it is most likely unrestricted. In Google AI Studio or the Google Cloud Console, add an API restriction limiting the key to the Generative Language API, or create a new key, which is restricted by default. Google has also announced that older Standard keys must move to newer auth keys.
How do I keep my Gemini API key safe?
+
Restrict it to the Generative Language API only, set a billing budget alert so a runaway loop cannot quietly run up a large bill, and never put the key anywhere public. Leaked Gemini keys have been used to run up very large charges within hours, so treat the key like a password and rotate it periodically.
Does this cost anything on WA.Expert?
+
WA.Expert does not charge for the External API Request step beyond it being a normal automation action. Google bills you for the Gemini usage directly, based on the tokens your requests and replies use. The WhatsApp side follows normal WhatsApp pricing: the reply you send back to the customer is free if it is inside the open service window.
Related

Keep building

The External API Request step

The foundation guide every connection builds on.

Read guide →

Connect hub

Every service you can wire into WhatsApp.

Browse all →

AI chatbot for WhatsApp

What an AI-powered bot can and cannot do well.

Read more →

Build a chatbot

Create the flow that calls Gemini.

Read guide →

Click-to-WhatsApp ads in 2026

Feed AI-answered leads from ads.

Read article →

WhatsApp API glossary

Endpoint, token, header, defined.

Open glossary →

Give your chatbot a brain, in minutes.

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