Web designers and template builders are being asked for AI features more often: a chat widget on a landing page, automatic product descriptions, a smarter site search, or alt-text generation for a media library. Adding them is straightforward. Adding them in a way that does not become a maintenance problem a year later takes some planning.
The main risk is lock-in. If every integration is written against one provider’s SDK and one specific model, then a price change, a deprecation or a better model elsewhere means touching every site you have built. This article describes a simple structure that avoids that.
Keep the AI call behind your own endpoint
Never call a model API directly from browser code. The API key would be visible to anyone who opens developer tools. Instead, send requests from the site to a small server-side function, such as a serverless function or a route in your site’s backend, and let that function talk to the model. This gives you one place to hold the key, add rate limiting, validate input, and log usage.
It also gives you a single seam to change. The page calls your endpoint, and your endpoint decides which model answers.
Choose an interface that is widely supported
The OpenAI chat completions format has become a common interface that many providers and gateways accept. Writing against that format means switching providers is often a matter of changing a base URL, an API key and a model name rather than rewriting request code.
A unified LLM API takes this idea further by putting many models behind one key and one format. ZenMux is one example. Its quickstart says you point the OpenAI SDK at its endpoint with your key, then name the model in a provider/model format. The same documentation lists support for four API protocols: OpenAI Chat Completions, OpenAI Responses, Anthropic Messages and Google Gemini. A single account also means one place to review usage and billing, which is convenient for an agency managing several client sites.
There are trade-offs. A hosted gateway adds another service between your site and the model provider, and teams that must run everything on their own infrastructure should look at a self-hosted gateway instead. For many small and mid-sized sites, though, the simplicity is worth it.
The three common ways to connect a site to language models differ mainly in who carries the integration work:
| Approach | Keys and formats | Switching models | Infrastructure to run | Main trade-off |
| Direct provider SDKs | One key and one SDK per provider | Usually needs code changes when the provider changes | None beyond your own endpoint | Most code to maintain across providers |
| Unified OpenAI-compatible API | One key and one request format for many models | Often a change to the model name, base URL and key | None; the gateway is hosted | Another hosted service sits in the request path |
| Self-hosted gateway | One format that you configure yourself | Often a configuration change | You deploy and maintain it | Most control, plus the operating work |
Prices and specs as listed on official pages in November 2026; check the live pages before deciding.
Match the model to the feature
Not every feature needs the most capable model. A practical split looks like this:
- Short, repetitive tasks such as generating meta descriptions, tagging images or rewriting button text suit small, fast, low-priced models.
- Customer-facing chat on a template demo or storefront benefits from a model that handles longer conversations and follows instructions closely.
- Occasional heavy tasks, such as drafting a long page from a brief, can use a stronger model because the volume is low.
Because the model name is just a string, you can store it in configuration per feature and change it without redeploying the site.
Plan for failures and for cost
Third-party services fail, and a website feature that shows an error is worse than one that is absent. Build in sensible defaults: a short timeout, a graceful message for the visitor, and a backup model. ZenMux documents a fallback setting that can be configured globally in the console or per request, and a provider routing layer that switches between providers for the same model when one is unavailable. If you use a different gateway or your own code, the same pattern applies.
For cost, keep requests small. Send only the text the model needs, set a maximum output length, and put any long, unchanging instructions at the start of the prompt so that providers with prompt caching can reuse them. ZenMux’s documentation says cache reads typically cost roughly 10% to 25% of the normal input price for models that support it.
If you are building something for a client, check the plan terms before launch. ZenMux’s quickstart states that its subscription plan is for personal development and learning and that live commercial projects should use its pay-as-you-go plan. Other providers have similar distinctions, and it is easier to read them before launch than after.
Log what happened
Once a feature is live, you will want to know which requests were slow, which were expensive and which failed. Record the model name, token counts, latency and outcome for every call. Gateways often provide this; ZenMux’s request logs show model, token usage, cost, latency, throughput and finish reason, and can be filtered by API key, which makes it easier to separate one client’s usage from another’s. If you build your own logging, store the same fields.
A simple checklist
- API keys live on the server, never in page code.
- The site calls your endpoint, not a provider directly.
- The request format is a widely supported one.
- Model names are configuration, not hard-coded.
- There is a timeout, a fallback and a visitor-friendly error message.
- Every call is logged with model, tokens, latency and cost.
Frequently Asked Questions
How to integrate an AI chatbot into a website?
Send chat requests from the page to a small server-side endpoint that holds the API key and calls the model, rather than calling a provider from browser code. That endpoint can also validate input, apply rate limits and log usage, while the page only displays the responses it receives.
What does an AI gateway do?
An AI gateway sits between your application and model providers. It typically offers one request format and one key for several models, and may add routing, fallbacks and usage logs. The trade-off is another service in the request path, which you either rely on as a hosted product or run yourself.
What are the different options for AI gateways?
Broadly there are three: call each provider directly with its own SDK, use a hosted unified API that accepts a common format, or run a gateway on your own infrastructure. Hosted options are quicker to set up, while self-hosted ones give more control but need ongoing maintenance.
Which API is best for chatbots?
It depends on conversation length, response speed, budget and how closely the model follows instructions. Rather than hard-coding one choice, keep the model name in configuration, test candidates on real visitor questions, and change the setting when a better option appears.
Conclusion
AI features can be added to websites and templates without tying each project to a single vendor. Put your own endpoint in front of the model, use a common request format, treat model names as settings, and prepare for failures and costs from the beginning. The result is a site that can adopt better models later with a configuration change instead of a rebuild.

