Ran Out of Free Quota? A Practical Guide to API Integration and Local Deployment
This guide explains how to manage rate limits and transition to paid API usage, including account setup, API key management, and three practical methods for local deployment. It also covers secure cross-device access, cloud hosting options, and best practices for protecting your API keys.
1. Why You Can’t Find the Recharge Option During Free Rate Limiting
Large language model inference requires significant GPU resources. When the request volume from free users spikes, platforms typically limit the number of concurrent requests or the number of requests per minute for each account. This rate limiting is a common protective measure in high-concurrency systems, designed to keep core services available. Therefore, if the web interface becomes slow or returns errors, it is mostly related to computing power constraints rather than an account issue.
Many users cannot find the recharge option because of the different product formats. Chat applications designed for general users often offer monthly subscriptions. Open platforms designed for developers usually charge based on Token usage, placing the recharge option on the billing or balance page in the console. Some providers do not offer subscriptions on the web interface, focusing their commercialization efforts on the API platform, which is why users cannot find the payment button on the web. For specific activation methods, refer to the pricing pages and official documentation of each platform.
You can estimate the cost of Token-based billing yourself. Suppose a model charges $1 per million input tokens and $2 per million output tokens—this is just a calculation example. If a single conversation takes about 2,000 input tokens and 1,000 output tokens, the cost per conversation would be $0.002 plus $0.002, totaling $0.004. Running 1,000 consecutive conversations would cost approximately $4. Actual prices and token counting methods are subject to the platform’s official page.
2. Preparations Before Enabling the API
The first step is to register an account on the open platform and complete any required identity verification. The second step is to create an API Key on the key management page in the console. It is recommended to create a separate Key for each use case to facilitate individual revocation and usage tracking later. The third step is to recharge and confirm the balance on the billing page.
When creating a Key, pay attention to three things. First, if the platform supports usage limits or model permission settings, only enable access to the models you need. Second, some platforms only display the Key once after generation, so you should save it immediately to a password manager or an environment variable. Third, rotate Keys regularly and revoke them immediately if you detect abnormal API calls.
3. Three Ways to Run Local Deployment
1. Directly Opening index.html
This is the simplest method, but it is not recommended as a long-term solution. When opened by double-clicking, the page address starts with file://. Browsers have strict security policies for local files, and requests to third-party APIs often fail due to Cross-Origin Resource Sharing (CORS) restrictions. Even if it works in some environments, behavior may vary across different browsers.
2. Using a Local Static Server
Start a simple HTTP service in your project directory and access the page via localhost. After installing Node.js, you can run npx serve. Python users can run python -m http.server 8080 and then open http://localhost:8080 in the browser.
A local server only resolves the issue of the page’s origin. Whether the browser can successfully call the API still depends on whether the API server returns response headers that allow cross-origin requests. If the API does not allow direct cross-origin calls from the browser, you will need the next method.
3. Using a Server-Side Proxy
A more robust approach is to run a lightweight backend on your local machine or server, which forwards requests with the Key attached. The frontend only requests its own interface, and the Key is stored in the server-side environment variables. Below is a simplified example:
import osimport requestsfrom flask import Flask, request, Responseapp = Flask(__name__)API_URL = "https://api.example-platform.com/v1/chat/completions" # Replace with the address from the platform documentationAPI_KEY = os.environ["LLM_API_KEY"] # Read from environment variables, do not hardcode in the source@app.route("/api/chat", methods=["POST"])def chat():upstream = requests.post(API_URL,headers={"Authorization": f"Bearer {API_KEY}","Content-Type": "application/json",},json=request.get_json(),stream=True,timeout=60,)return Response(upstream.iter_content(chunk_size=None),status=upstream.status_code,content_type=upstream.headers.get("Content-Type"),)
Before running, execute pip install flask requests, then set the environment variable LLM_API_KEY. The frontend needs to change the request address to /api/chat. This example lacks authentication and rate limiting, making it suitable only for personal local use. If you intend to provide a public service, you must add login verification, request rate limiting, and log desensitization.
4. Cross-Device Access and Cloud Hosting
If you want to use the application on mobile phones and tablets, you need to deploy the frontend to an address accessible via HTTPS. There are two paths to choose from.
The first is to use the official hosting address provided by the project. Before using it, verify that the address is maintained by the project team and check the usage conditions in the official instructions. The second is self-hosting. You can upload the built static files to an HTTPS-compatible static hosting service, or upload them to object storage and distribute them via a CDN. Baidu AI Cloud’s Object Storage (BOS) is one such option; refer to the corresponding product documentation for specific configurations.
Regardless of the method chosen, never hardcode the API Key into the frontend code or build artifacts. Scripts in a purely static frontend can be viewed by anyone, meaning a hardcoded Key is essentially public.
5. Key Storage and Security Boundaries
Many open-source frontends save the API Key in the browser’s localStorage. While convenient for personal use, the risk boundary is clear. If the page has a Cross-Site Scripting (XSS) vulnerability, malicious scripts can read the contents of localStorage, including the Key. The risk is higher when using shared computers, public networks, or browsers with unverified extensions installed.
For personal use, you can follow these practices: only save the Key on trusted devices; clear the Key in settings when not in use; set usage limits for the Key; and mask the Key when taking screenshots or screen recordings. If you suspect a leak, immediately revoke the Key in the console and generate a new one.
