How to Connect a Web Selection Translation Extension to a Large Model API
This guide explains how to configure a browser selection-translation extension to use a large language model (LLM) chat API as its translation backend. It covers the required configuration fields—model identifier, API endpoint, authentication key, and optional proxy—along with setup steps, verification, prompt tuning, and security practices for keeping API keys safe.
1. Background and Overall Approach
For cross-language reading, selection-translation extensions in the browser have become a go-to tool for developers and researchers. Traditional translation approaches rely on fixed dictionaries and rule-based templates. When they encounter technical terminology, deeply nested long sentences, or content that depends heavily on context, the output often loses semantic coherence. Using a large language model’s chat API as the translation backend produces output that fits the surrounding context more closely, and it makes the response style easier to constrain through prompts.
The overall implementation has four layers:
- The browser extension handles interaction and text capture.
- A translation adapter inside the extension packages the selected text into a request.
- The LLM chat API performs semantic understanding and generation.
- The adapter parses the response and renders it in an on-page overlay.
This article focuses on the handoff between the third and second layers: how to fill in the API details correctly in the extension’s settings interface.
One thing worth emphasizing is that naming for settings items varies across extensions, but the underlying configuration elements are essentially the same: model identifier, API endpoint, authentication key, and an optional network proxy. Understanding what these elements mean is more valuable than memorizing a specific sequence of clicks.
2. Prerequisites
- Register and sign in to an available LLM service platform, then open the console.
- Create an access key on the console’s key management page. The key is displayed in full only once at creation time, so store it securely.
- Confirm that the account has permission to call the target model, and review the platform’s quota and rate-limit policy.
- Prepare a browser environment with outbound internet access. If access is restricted, arrange a proxy in advance.
An illustrative key format is shown below. It only demonstrates the shape and should never be placed in frontend code or committed to a repository:
sk-**************** (shown in full only once after creation)
3. Configuration Steps
Open the extension’s settings interface, go to the translation category, select the AI translation or smart translation subsection, scroll down to the chat model configuration area, and create a new entry.
Recommended values for the key parameters:
- Model identifier: the chat model name given in the platform’s documentation, such as the identifier for a general-purpose chat model.
- API endpoint: the chat completions endpoint provided by the platform, in the form
https://<platform-domain>/v1/chat/completions, where the domain follows the console documentation. - Authentication key: paste the access key created in the previous step.
- Proxy address: fill this in only if a direct connection fails; the format is usually
http://127.0.0.1:<port>.
After saving, return to the translation toggle and click it a few times to confirm that AI translation is the active mode and that the selected endpoint is the entry you just created. This is the most common mistake in practice: the configuration is saved, but the toggle is still on the old rule engine, creating the impression that “the change had no effect.”
4. Verification and Tuning
Start verification with a short sentence, then move on to longer paragraphs. If the response is empty, first check whether the key has expired, whether the model identifier is spelled correctly, and whether the API endpoint is missing part of its path. If responses are stable but the style is unsatisfactory, add constraints in the extension’s prompt or style options, for example: “output only the translation, preserve the original paragraph structure, and keep technical terms in English.”
Most compatible APIs follow a common request body shape, which helps narrow down troubleshooting:
{"model": "general-purpose chat model identifier","messages": [{"role": "system", "content": "You are a professional translator; output only the translation"},{"role": "user", "content": "text to translate"}],"temperature": 0.2}
Lowering the temperature helps improve terminology consistency. For very long text, split it by sentence or paragraph and send requests in batches to avoid exceeding the context length limit.
5. Security and Stability Recommendations
Store the key in the extension’s local storage or the system keychain. Do not expose it in plaintext in shared configuration, screenshots, or public repositories. If you use a proxy, consider whether the proxy itself is trustworthy, and avoid routing text through untrusted nodes. For production or team scenarios, a lightweight gateway can be self-hosted to centralize key management, rate limiting, and log redaction. General cloud capabilities such as log services and monitoring alerts can be used to observe call success rates and latency distribution.
6. Quick Troubleshooting Reference
- Authentication failure: the key is incorrect or has been revoked.
- Model not found: the model identifier does not match the account’s permissions.
- Request timeout: a network or proxy issue; switch nodes and retry.
- Configuration has no effect: AI translation mode was not actually enabled, or the wrong endpoint entry is selected.
Once the configuration above is complete, selection translation switches to LLM-driven output. Readers can adjust proxy and splitting strategies according to their own network and compliance requirements.
