Build a Local Chat UI with an API Key When Free-Tier Limits Tighten
This article explains how to distinguish subscription plans from pay-as-you-go API billing, choose a trustworthy local chat front end, and deploy it with an API key. It also covers CORS troubleshooting, API key limits, privacy, conversation backup, cost estimation, and the commercial logic behind subscription and API pricing.
First, distinguish the two billing channels
Many users are confused by free web-tier limits: they are willing to pay but cannot find a top-up entry. The reason is that LLM services often offer two billing channels in different places, with different billing logic.
| Comparison | Subscription | Pay-as-you-go API |
|---|---|---|
| Target audience | General consumers | Developers and advanced users |
| Entry point | Subscription page in the official app or web interface | Developer platform console |
| Cost model | Fixed monthly or annual fee | Prepaid balance deducted by token |
| Cost predictability | Relatively high | Depends on actual usage |
| Limit mechanism | Fair-use policy, implicit rate limits | Balance, usage caps, and alerts |
| Main risk | May not be able to continue after exceeding the plan | Long conversations or misuse can lead to higher-than-expected costs |
If you do not see a subscription entry, it usually only means the product does not have that entry; it does not mean the provider does not accept payment. Developer platforms generally provide API key applications and balance top-ups, but the usage model differs from subscription purchases inside a mobile app.
How to choose a local chat front end
When choosing a front end, check the following:
- Is it officially provided or open source by the provider, and actively maintained?
- Does it support custom API base URLs and model names?
- Does it support exporting and importing conversation history?
- Where is the key stored? Is it kept only in the local browser?
Do not download front-end packages from unknown sources. Once an API key is entered into a page, malicious code may read it.
Deployment steps and configuration checklist
Follow this order and record the result of each step so you can trace problems.
- Get the release package: Download the chat project’s release from the provider’s official documentation or an open-source repository, and extract it to a separate directory.
- Create an API key: Sign in to the developer platform, complete any required account verification, add credit, and create an API key. Give the key a purpose name, such as “local chat front end,” to make future rotation easier.
- Record three configuration values: API base URL, model name, and API key. Use the provider’s official documentation for the base URL and model ID; formats vary significantly across platforms.
- Start a local static server: Most pure front-end projects should not be opened by double-clicking, because browsers impose cross-origin and module-loading restrictions on the
file://protocol, and the page may be blank or requests may fail. In the extracted directory, run:
cd /path/to/extracted-projectpython -m http.server 8080
If Node.js is installed, you can also run npx serve .. Then visit http://localhost:8080 in your browser.
- Fill in settings: Enter the base URL, model name, and API key in the page settings, and send a short test message.
- Check usage: Return to the developer platform and check usage statistics to confirm that the billing unit and amount match expectations.
Note that a pure static page cannot read operating-system environment variables. If the documentation shows something like export API_KEY=..., that applies only to projects with a backend service or a build script. For a pure front-end page, the key usually has to be entered manually on the settings page.
What to do about CORS errors
Browsers check cross-origin response headers. If the console shows CORS-related errors, troubleshoot in this order:
- Confirm that you are accessing the page through
http://localhost, not by opening a local file directly. - Check whether the protocol, domain, and path of the base URL are spelled correctly.
- Check the provider’s documentation to confirm whether its API allows direct browser calls.
- If the API does not allow direct browser calls, forward requests through a backend or proxy that you control. The proxy will have access to the key, so you must secure it when deploying.
How to limit API key exposure
An API key is equivalent to the account’s payment permission. The stricter the limits and isolation, the smaller the risk.
- Create a separate key for this front end and do not share it with other projects.
- Set a usage cap or budget alert in the platform if the platform supports it.
- If the platform supports IP allowlists, add the allowed addresses. Residential broadband public IPs may change, so check periodically.
- Rotate keys regularly. If you suspect a leak, delete the old key in the platform and create a new one immediately.
- Do not enter the key on pages hosted by others or in public environments.
- Browser extensions and page scripts can read input on the page, so use the key only on trusted devices and in trusted environments.
Privacy: history stays local, but content is still uploaded
Conversation history is usually stored in the browser’s localStorage or IndexedDB and is deleted when you clear browser data. However, each time you ask a question, the current conversation content is sent to the model service with the request. How the provider stores, retains, and uses that data depends on its privacy policy and account settings; check them before use.
How to migrate and back up conversation history
- Export conversations from the original interface; JSON is a common format.
- Confirm that the import feature supports that format, import the file, and spot-check several records for completeness.
- Export and back up important conversations regularly to avoid losing them when clearing browser data.
- When changing devices, migrate the exported files together with the front-end project. Keep the API key separately in a password manager; do not write it into the export file.
How to estimate costs
For pay-as-you-go billing, monthly cost can be estimated with:
Monthly cost ≈ monthly input tokens × input unit price + monthly output tokens × output unit price
One detail is easy to overlook: each request usually includes the previous context, so the longer the conversation, the more input tokens each turn consumes.
Example (unit prices are hypothetical; use official pricing in practice): Suppose you have 20 conversation turns per day, with an average of 2,000 input tokens per turn (including history) and 800 output tokens, for 30 days per month.
- Monthly input tokens: 20 × 2,000 × 30 = 1.2 million
- Monthly output tokens: 20 × 800 × 30 = 480,000
- If input costs CNY 2 per million tokens and output costs CNY 8 per million tokens, the monthly cost is about 1.2 × 2 + 0.48 × 8 = CNY 6.24.
You can view actual usage on the platform’s usage statistics page and compare it with your estimate before adjusting. Starting a new conversation when beginning a new topic can effectively control context length.
The business logic of subscriptions and APIs
Provider pricing strategies may be influenced by multiple factors, commonly including:
- LLM compute costs are high and change with model capability.
- Usage varies widely among users on a fixed monthly fee; heavy users may make costs hard to cover, so providers may set limits or prefer pay-as-you-go billing.
- Developer APIs are closely tied to enterprise business, and revenue structures and strategic priorities differ across providers.
- Free web-tier limits may be a cost-control measure and may also relate to product positioning and user feedback.
For specific reasons, refer to each provider’s announcements and pricing documentation; external speculation is only a reference.
Conclusion
Free web-tier limits do not mean LLMs are unavailable. Pay-as-you-go APIs offer another path for users with controllable usage who are willing to configure things themselves. Before starting, add a small amount of credit, complete a test conversation, and confirm that configuration, billing, and privacy settings meet expectations before deciding whether to use it long term.
