Local Deployment of LLM Chat Apps Under Service Quotas

    As free tiers for large language models tighten, this article explains the difference between free quotas, pay-as-you-go APIs, and subscriptions, then shows how to build a self-hosted chat frontend with a lightweight backend proxy, migrate and persist conversation history in a unified message format, choose between local, intranet, and public deployment, and control token costs through model tiering, caching, budgets, and retries.

    1. Why Quotas Change the Experience

    Discussions about shrinking free-tier limits on large language models have been increasing lately. Users typically notice slower responses, fewer requests, and an inability to continue their previous usage. The deeper reason is that a free quota is essentially a subsidy in which the provider absorbs inference costs. Its size depends on compute supply, concurrency scheduling, and business timing, so it is inherently adjustable. When traffic grows quickly, tightening the free tier is an almost inevitable choice for any platform.

    One common misunderstanding is worth clearing up: the absence of a subscription option for individual users does not mean paid usage is impossible. In this industry, pay-as-you-go API access for developers and monthly subscriptions for ordinary users are two parallel commercialization paths. The former has long been open and is metered by token; whether the latter is offered depends on the vendor’s product strategy. Conflating the two is where many arguments begin.

    2. What the Three Billing Models Mean Technically

    Understanding this helps with sound technical selection:

    • Free quota: zero barrier to entry, but with rate limits and a total cap. Suitable for evaluation and light trials. The risk is that the policy can change at any time.
    • Pay-as-you-go (API): metered by input/output tokens, with no extra charges beyond any concurrency guarantees, suitable for integration into applications and automated workflows, with cost growing linearly with usage.
    • Subscription: a fixed periodic payment in exchange for a higher or unlimited number of interactions, suitable for high-frequency individual use, but usually without a programmable interface.

    Key takeaway: if you need something stable, programmable, and portable, the pay-as-you-go API is the right entry point; if you want unlimited chat interactions, a subscription fits better. The two cannot substitute for each other.

    3. Self-Hosted Chat Apps: Taking Back Control

    When the free tier is limited, a practical approach is to build your own chat frontend while the backend still calls the standard API. This preserves the original interaction experience and removes exposure to policy swings at a single entry point.

    The typical architecture is simple: a static frontend page, a lightweight backend proxy, and keys plus configuration. Illustrative code:

    1. // Frontend: route everything through your own backend proxy so keys are never exposed in the browser
    2. async function chat(messages) {
    3. const resp = await fetch('/api/chat', {
    4. method: 'POST',
    5. headers: { 'Content-Type': 'application/json' },
    6. body: JSON.stringify({
    7. model: 'your-model-name',
    8. messages,
    9. stream: false
    10. })
    11. });
    12. if (!resp.ok) throw new Error('upstream error: ' + resp.status);
    13. return resp.json();
    14. }
    1. # Backend proxy: keys exist only in server-side environment variables
    2. import os, json, urllib.request
    3. def proxy(payload):
    4. req = urllib.request.Request(
    5. os.environ['LLM_ENDPOINT'],
    6. data=json.dumps(payload).encode(),
    7. headers={
    8. 'Content-Type': 'application/json',
    9. 'Authorization': 'Bearer ' + os.environ['LLM_API_KEY']
    10. }
    11. )
    12. with urllib.request.urlopen(req, timeout=60) as r:
    13. return json.loads(r.read())

    Three engineering details that must be handled:

    1. Never send keys to the client. Any scheme that writes a key into a frontend script or a local configuration file amounts to public disclosure.
    2. Handle interruptions in streaming output. With streaming responses, implement timeout-and-reconnect logic and partial saving of already-generated content so network jitter does not lose the whole segment.
    3. Trim context length proactively. Unbounded conversation history drives up token consumption, so compress it as “system prompt + last N turns + summary.”

    4. Migrating and Saving Conversation History

    The core of migration is abstracting a session into a unified message array structure, decoupled from any specific product:

    1. {
    2. "session_id": "s-1024",
    3. "model": "your-model-name",
    4. "messages": [
    5. { "role": "system", "content": "You are a rigorous technical assistant" },
    6. { "role": "user", "content": "..." },
    7. { "role": "assistant", "content": "..." }
    8. ]
    9. }

    As long as exported data can be mapped to the structure above, it can be moved between any compatible APIs. Engineering recommendations: persist locally with a lightweight embedded database or structured files; record an estimated token count for each session to support later cost accounting; and generate rolling summaries for long sessions to inject as new system context.

    5. Deployment Options: Local, Intranet, and Public

    • Local: data never leaves the machine, offering the best privacy, suitable for deep personal use and long role-play conversations.
    • Intranet or home network: multiple devices share one backend for a consistent experience on phone and computer, with minimal access control added.
    • Public: authentication, rate limiting, logging, and monitoring alerts are mandatory; otherwise the endpoint is easily scanned and abused, and the bill can spiral quickly.

    For zero operations, you can also use cloud container platforms, object storage, and logging services to get running fast: host static assets in object storage, run the proxy service on a container platform, and observe call volume, failure rate, and token consumption through monitoring alerts. These are general capability categories; follow the official documentation of your chosen cloud provider for specifics.

    6. Cost Control Checklist

    1. Assign different model tiers to different scenarios; do not call a high-capability model for simple tasks.
    2. Cache answers to frequent questions to reduce repeated charges.
    3. Set a daily token budget and a hard circuit-breaker threshold.
    4. Use backoff retries for failed requests to avoid retry storms amplifying consumption.
    5. Audit key usage sources regularly and rotate keys promptly.

    7. Closing Thoughts

    Quota adjustments are the norm. Rather than arguing about whether an entry point exists, make the architecture one with a replaceable backend: you own the frontend and the data, and the model service is a pluggable dependency. Then business continuity is unaffected no matter how the free quota changes or whether an individual subscription appears. Vendors such as Baidu AI Cloud also offer pay-as-you-go model services along with supporting cloud capabilities, and developers can freely choose a backend implementation based on their own compliance and cost requirements.