Building a Bilingual Clinic FAQ Chatbot with the OpenAI API
25 April 2026 · by Yunmin Shin
Why Add OpenAI to a Bangkok Business Website?
The OpenAI API gives your web application access to large language models capable of generating text, answering questions, and extracting structured data. For Bangkok businesses, the practical use cases are concrete: a clinic wants a chatbot that answers "how long does filler swelling last?" in Thai or English without a staff member typing the same answer for the fiftieth time, a restaurant wants menu descriptions generated in both languages, an e-commerce store wants product Q&A automated.
We'll use a clinic FAQ chatbot — patients asking about treatments, aftercare, and pricing ranges, in either Thai or English — as the running example, since it's a real pattern across the aesthetic clinic sites we build and operate ourselves.
How Do You Set Up the OpenAI Client?
Install the official SDK:
npm install openai
Store your API key in an environment variable — never in client-side code:
OPENAI_API_KEY=sk-...
Create a singleton client in lib/openai.ts:
import OpenAI from "openai";
export const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
Only import this file from server components, API routes, or server actions. The key must never reach client-side JavaScript.
How Do You Ground the Chatbot in Real Clinic Information?
A generic language model will confidently answer questions about treatments it knows nothing specific about — wrong pricing, wrong aftercare instructions, wrong contraindications. For anything touching medical or health information, that's not just embarrassing, it's a liability problem. The fix is to give the model your clinic's actual content as context rather than letting it answer from general training knowledge: pull the relevant treatment description, pricing range, and aftercare notes from your database and include them in the system prompt for that conversation, then instruct the model explicitly to answer only from the provided context and to say "please contact the clinic directly" for anything outside it — dosage specifics, medical suitability, anything that should come from a practitioner, not a chatbot.
const systemPrompt = `You are a helpful assistant for [Clinic Name] in Bangkok.
Answer only using the treatment information below. If the question is
about medical suitability, dosage, or anything requiring a practitioner's
judgment, say so and suggest booking a consultation. Respond in the same
language the user asks in (Thai or English).
Treatment info: ${treatmentContext}`;
How Do You Stream Responses?
Streaming displays the model's response token by token rather than waiting for the full response, which matters more than usual here — a lot of clinic traffic is mobile, on 4G connections that aren't always fast, and a chatbot that appears to hang for five seconds before answering feels broken. In a Next.js Route Handler, use the OpenAI SDK's streaming mode and return a ReadableStream. On the client, the Vercel AI SDK's useChat hook handles the request lifecycle, streaming state, and message history automatically.
npm install ai
This is the recommended pattern for any chat-style interface, and it works the same whether the chat widget lives on the clinic's website or is proxied through a LINE OA — LINE's Messaging API doesn't support token-by-token streaming to the chat window itself, so for a LINE-based bot you'd stream server-side into a buffer and send the completed message, while a website widget can stream directly to the user.
How Do You Control Costs?
OpenAI charges per token, input and output separately, and costs grow quickly without guardrails:
- Set
max_tokenson every completion request. Without a cap, a runaway prompt can generate thousands of tokens on a question that needed three sentences. - Cache responses for identical or near-identical questions. Clinic FAQs cluster heavily — "does it hurt," "how long is recovery," "how much does it cost" get asked constantly in slightly different phrasing. Caching common Q&A pairs in Redis (or even a simple database table keyed on a normalized question) cuts API calls significantly for a small-business budget.
- Use smaller models where sufficient. GPT-4o mini is significantly cheaper than GPT-4o and handles FAQ-style question answering adequately when it's grounded in provided context rather than reasoning from scratch.
- Log token usage per request and alert when daily spend crosses a threshold. Set OpenAI's dashboard hard spending limits immediately — this is a five-minute task that prevents a very bad surprise bill.
What Rate Limits and Abuse Protection Should You Plan For?
New OpenAI accounts start with low rate limits on requests and tokens per minute. For a production chatbot serving real users, request a rate limit increase through OpenAI's console, and implement exponential backoff retry logic for 429 errors so a burst of traffic degrades gracefully instead of erroring out.
Separately, rate-limit at your own application layer per user (per LINE user ID, or per session/IP for a website widget) — without this, nothing stops one visitor from sending fifty rapid messages and burning through your daily budget alone. A simple sliding-window limit of a few messages per minute per user is enough for an FAQ bot and won't be noticed by legitimate use.
At Bluewich, we build OpenAI integrations for Bangkok businesses with streaming UI, response caching, grounded context, and per-user rate limiting baked in from the start. A well-integrated AI feature should feel instant, answer accurately from real business content, and cost predictably — not become a surprise line item.
Ready to Build Something Fast?
Get a free quote. We reply within 24 hours.
Ready to build something fast and scalable?
Get a free project quote. We reply within 24 hours.
Get a Free Quote →