Chat widget code and cost control: models, response caps and daily limits
A public chat widget should never produce a surprise bill. These are the controls that cap what your chat widget code can spend, and how to combine them.
Published:
A chat widget is public by design: anyone who opens your page can type into it. That is the point, but it also means the cost has to be capped by limits that only you control. api14 gives you several, and they work together.
1. Choose the model with the price in view
The model picker in the widget editor shows each model's price. For a support assistant, a small fast model is often enough, and it costs a fraction of a frontier model. Because the model is stored with the widget, you can switch to a stronger one later without changing the code on your site:
<script src="https://api14.com/widget.js" data-widget="YOUR_WIDGET_ID" async></script>
2. Cap every answer
Chat widgets have a maximum tokens setting that limits the length of each answer. A cap of a few hundred tokens keeps replies short and puts a ceiling on the cost of a single message. Long conversation histories are trimmed on the server, so an endless chat cannot grow the request without limit.
3. Bind the widget to an API key with its own limits
Every widget runs under one of your API keys, chosen in the editor. The list ends with Create new API key, so you can make a dedicated key for one widget in a few seconds. The key's settings then apply to every visitor request:
- Daily spend limit: the key stops for the day once it has spent this amount.
- Requests per minute: a ceiling on how fast the widget can be used.
- Allowed models: a key restricted to one model cannot be used for anything else.
Usage for the widget is recorded under that key, so Usage shows exactly what the widget cost. If you ever need to stop the widget at once, delete or replace the key.
4. Widget and account caps
On top of the key, the widget editor has its own daily spend limit, and Settings, Widget controls adds one cap across all widgets on the account. Each visitor is also limited per minute and per day, so one person cannot exhaust your budget.
| Control | Where you set it |
|---|---|
| Model and maximum tokens | Widget editor |
| Key daily spend, rate and allowed models | API keys |
| Widget daily spend limit | Widget editor |
| Daily limit for all widgets, requests per visitor | Settings, Widget controls |
5. Your balance is the final limit
Visitor requests are charged to your USD balance at the model's normal price. When the balance reaches zero, widgets stop answering until you add funds. With Email me when a widget fails turned on, you hear about it the same day.
Combine two or three of these controls and the worst case is always a number you chose. Build your widget on the widgets page and see current prices on pricing.