How to Connect LLMs to an AI Coding Terminal: Configuration Guide
This guide explains how to connect external large language models to an AI coding terminal through a custom provider. It covers feasibility boundaries, choosing a main and a backup model, required credentials, a full breakdown of the config.toml fields, a layered verification sequence, and a troubleshooting table for common errors. You will learn how to keep API keys in environment variables, manage main and backup models in separate profiles, and select the correct wire protocol.
1. The Bottom Line: Where the Feasibility Boundaries Are
There is only one criterion for whether a model can be connected to an AI coding terminal: whether the server side exposes an OpenAI-compatible interface that the terminal recognizes. As long as this condition is met, any model can be mounted through a “custom model provider” without modifying any front-end resource files inside the terminal installation package.
A common misconception is worth clearing up here: many people assume that connecting a new model requires “cracking” the desktop app. In fact, the desktop app already reserves the ability to configure external services. The only things you actually need to maintain are a single user-level configuration file and a set of environment variables. Writing the configuration into the user directory rather than a project repository is the prerequisite for this approach to work reliably over the long term.
The other boundary is the protocol. The OpenAI-compatible system usually has two calling styles: a Chat style for multi-turn conversation, and a structured Responses style for tool calling and reasoning traces. The terminal supports these two styles to different degrees, and choosing the wrong protocol directly causes a false failure where the connection works but the model does not.
2. Model Selection: Dividing Labor Between Main and Backup Models
Take the GLM-5.3 series from a cloud vendor’s model catalog as an example (always treat the model ID and protocol fields as whatever the console currently displays). A complete model identifier carries a vendor prefix, and the console generally also provides a short alias. Aliases are convenient to type, but the complete identifier is recommended in the configuration file to avoid ambiguity across multiple accounts and regions.
The two versions are clearly positioned differently:
| Comparison | Main model version | Lightweight multimodal version |
|---|---|---|
| Model identifier form | Complete ID with vendor prefix | Complete ID with a flash suffix |
| Input modalities | Plain text | Text, images, video, files |
| Context window | Million-level tokens | Million-level tokens |
| Typical tasks | Long-horizon coding, code review, agent planning | Multimodal understanding, fast trial and error, lightweight coding |
| Terminal recommendation | Default main model | Backup for visual input scenarios |
A million-level context window and a maximum output in the hundred-thousand-token range, combined with function calling, structured output, reasoning, and input caching, mean it is suitable for ingesting an entire repository context in one pass to make cross-file changes. But note that input caching can significantly reduce cost and time to first token, provided the request prefix stays stable; frequently changing the system prompt will invalidate the cache.
The practical recommendation is: fix on the main model when you are only working with a code repository; when a task involves screenshots, design mockups, or screen recordings, add the multimodal version separately as a backup, rather than mixing model names under the same provider — that mixing is the root cause of a large number of 404 errors later.
3. Prerequisites: Three Types of Credentials and One Configuration File
- A desktop AI coding terminal that starts normally;
- An external model management tool (used to maintain providers, models, and protocols in the desktop app, removing the need to hand-edit the package);
- An API key from the console, with confirmation that the target model is enabled for your account;
- The user-level configuration path
~/.codex/config.toml.
Keep the key only in environment variables — not in the repository, and not in plaintext in the configuration file:
export CUSTOM_LLM_API_KEY="sk-xxxxxxxx"
4. Core Configuration: Breaking Down config.toml Field by Field
model_provider = "custom"model = "z-ai/glm-5.3"[model_providers.custom]name = "Custom Provider"base_url = "https://example-endpoint/v1"env_key = "CUSTOM_LLM_API_KEY"wire_api = "responses" # "chat" is also an option[profiles.flash]model_provider = "custom"model = "z-ai/glm-5.3-flash"
Field meanings and pitfalls:
model_provider: points to a provider table name defined below; a typo produces an “unknown provider” error;base_url: must include the version path segment, and must not have/chat/completionsappended at the end, because the terminal concatenates that itself;env_key: fill in the environment variable name rather than the key itself — this is the critical step for avoiding leaks;wire_api: the protocol switch. When tool calling and structured output are required, try the structured style first, and fall back to the chat style if the server side does not implement it;profiles: multiple configurations coexist and are switched with startup arguments, so the main and backup models do not pollute each other.
5. Verification Order: Narrowing Down Layer by Layer, from Connectivity to Usability
- First make one minimal direct request to confirm the key and address are correct;
- Then do one plain-text question and answer inside the terminal to verify the protocol matches;
- Next test one tool call to verify that function-calling fields are passed through correctly;
- Finally run a small cross-file task to verify long context and the output limit.
If any step fails, stop and localize the problem first; do not stack variables on top of each other.
6. Common Errors and a Localization Table
| Symptom | Frequent cause | Direction to fix |
|---|---|---|
| 401 | Environment variable not exported or name mismatch | Reopen the terminal, check env_key |
| 404 model not found | Model ID used an alias or was mixed up | Switch back to the complete ID |
| 400 unsupported protocol-related field | Protocol style does not match the server | Switch wire_api |
| Context limit exceeded | Overly long repository not trimmed | Narrow the scope or switch to the backup model |
| Output truncated | Maximum output limit reached | Split the task, generate in segments |
7. Pre-Launch Checklist
The key lives only in environment variables, the configuration lives in the user directory, main and backup models are managed in separate tables, the protocol has been tested in practice, cost is evaluated based on cache hits, and the rollback plan is simply to delete the provider section. Pricing and available regions vary by account, so do not hardcode them in documentation or scripts.
