All posts
Build a WhatsApp bot with TokenRex in 20 lines
Tutorials 10 min read· Jul 12, 2026· By Guides

Build a WhatsApp bot with TokenRex in 20 lines

Wire a business WhatsApp number to GPT-5 in under 15 minutes with Twilio + TokenRex.

You need three things: a Twilio WhatsApp sandbox, a TokenRex key, and a tiny webhook. The whole app fits on your laptop screen.

The webhook#

python
from fastapi import FastAPI, Form
from openai import OpenAI

app = FastAPI()
ai = OpenAI(api_key="YOUR_TOKENREX_API_KEY", base_url="https://tokenrex.ai/api/public/v1")

@app.post("/wa")
def wa(Body: str = Form(...)):
    r = ai.chat.completions.create(
        model="gpt-5.4-mini",
        messages=[{"role": "user", "content": Body}],
    )
    return {"reply": r.choices[0].message.content}

Point Twilio's inbound webhook at /wa. Every message from your customers now round-trips through GPT-5.4 Mini.

Adding memory#

Store the last N turns per WhatsApp number in a small Redis or SQLite. See multi-turn memory patterns.

Cost: about $0.50 per 100 messages on Gemini 3 Flash, or $2.00 on GPT-5.4 Mini.

Models in this article

Review current prices, specifications and source-linked benchmarks.

Build this with TokenRex

TokenRex is an LLM marketplace by Asirex Labs. Choose an enabled model, create a private API key and use the supported endpoint shown in Docs. Check live prices before your first request.