Building a Multi-Model LLM CLI Launcher with AI Coding Assistants
This article explains how to use an AI coding assistant to quickly build a local Large Language Model (LLM) command-line interface (CLI) launcher. By leveraging the assistant's automated mode and natural language prompts, developers can bypass common setup issues like dependency failures and complex configurations. The guide covers prerequisites, prompt engineering for code generation, handling multi-model configurations, and best practices for API key security, enabling you to deploy a functional multi-model CLI tool efficiently.
Many developers use LLM CLI tools, but local setup often involves dependency installation failures, network access restrictions, and multi-point configuration changes when switching models. This article introduces an alternative approach: using an AI coding assistant in full-auto mode. By describing requirements in natural language, the tool generates project code and configuration files, while the developer only confirms at key nodes. By the end of this guide, you will have built a local launcher supporting multiple models and understand the environments where it can run seamlessly.
1. Scope and Prerequisites
This method suits individual developers who want a ready-to-use CLI tool quickly, as well as those needing to run the same tool temporarily across multiple Windows machines. It does not replace formal software engineering workflows. Before starting, verify three things:
- Node.js LTS is installed. Run
node -vin the terminal; seeing a version number is sufficient. The exact version depends on the generated project’spackage.jsonrequirements. - You have at least one LLM service API Key, along with its interface address (base_url) and an available model name.
- Your machine can access the package manager source. Special proxies are usually unnecessary, but you can configure a mirror source if access is slow.
2. Choosing Tools and Models
The AI coding assistant must meet two conditions: the ability to read and write to local directories directly, and the ability to execute terminal commands. Web-only chat interfaces that cannot write files cannot complete this process.
For models, it is recommended to fix a highly capable model in the assistant rather than allowing it to auto-switch. A fixed model ensures consistent code style, reduces context fragmentation caused by switching models, and makes it easier to locate issues during long workflows. Whether this improves efficiency depends on task complexity and the selected model’s stability. It is recommended to test with a small task first before deciding on a long-term approach.
3. Build Process
3.1 Create a working directory
Create an empty folder locally, such as llm-cli, and open it with the AI coding assistant. Ensure the tool has read/write permissions for the directory. Avoid spaces or non-ASCII characters in the path to prevent compatibility issues with certain scripts.
3.2 Write the prompt
A good prompt should include five elements: Goal, Functional Requirements, Constraints, Acceptance Criteria, and Prohibitions. Here is a template:
Goal: Build a local LLM CLI tool in the current directory.Features: 1. Support inputting questions in the terminal and outputting model answers; 2. Default model can be modified via config file; 3. Prompt for API Key on first run.Constraints: Run locally; use Node.js; minimize dependencies; do not hardcode API Keys or commit them to version control.Acceptance: Running npm start allows normal conversation; typing exit quits; missing API Key gives a clear prompt.Output: package.json, index.js, config.example.json, README.md.Prohibitions: Do not modify files outside the current directory; do not execute delete commands.
3.3 Handle confirmation nodes
The tool will request confirmation multiple times during execution. Common options and recommendations are as follows:
- Save configuration: Choose to save to a local config file (e.g.,
config.local.json) and add it to.gitignore. This prevents repeated input during subsequent runs. - Dependency installation failure: Prioritize retrying with a mirror source. Do not delete lock files or disable validation just to pass the installation.
- Overwrite files: Carefully verify file names to be overwritten. Back up important existing files first.
3.4 Acceptance check
Do not blindly trust the tool’s completion report; verify each item manually:
- Run
npm installin the project directory and ensure there are no errors. - Run
npm start, input a simple question, and confirm an answer is received. - Clear the API Key and run again; confirm a clear prompt appears instead of a program crash stack trace.
- Search the code to ensure there are no plaintext API Keys.
All four must pass to consider the build complete. The above commands are subject to the actual generated project documentation.
4. Configuration File and Multi-Model Access
The generated config file typically contains three fields, as shown below:
{"base_url": "https://api.example.com/v1","model": "example-model-name","api_key_env": "LLM_API_KEY"}
base_url: The service’s API endpoint.model: The model name, which must match the provider’s documentation.api_key_env: The environment variable name storing the API Key. The program reads the Key from this variable; no plaintext is written in the config file.
To switch to another service, simply modify base_url and model, ensuring the service is compatible with OpenAI’s request format. If the provider requires additional request headers, add them in the code.
For privacy-focused or offline scenarios, you can run an inference service locally and point base_url to a local address, such as http://localhost:8000/v1. Before connecting, check the following:
- Health check: Run
curl http://localhost:8000/v1/modelsin the terminal. If it returns a model list, the service is normal. - Model name: The
modelfield must exactly match a name in the returned list. - Port conflict: On Windows, run
netstat -ano | findstr :8000to check the process occupying the port; on macOS or Linux, runlsof -i :8000.
5. API Key Security
An API Key represents your account’s access privileges. If leaked, others may misuse it and incur charges. Follow these rules:
- Prioritize using environment variables. On Windows, add them in system environment variable settings; on macOS or Linux, write the
exportstatement in your shell config file. - If you must store it in a local file, place it in a location readable only by the current user. On Linux and macOS, execute
chmod 600 config.local.jsonto restrict permissions. - Do not write the Key into code, README files, or batch scripts.
