How to Connect a Desktop AI Agent to a Custom LLM Provider: A Practical Guide
This guide walks through connecting a desktop CLI-based AI agent to a custom large language model provider. It covers pre-installation checks, configuring a custom provider, layered connectivity verification, common troubleshooting scenarios, and ongoing security practices such as key rotation, backups, and upgrades. Readers will learn how to set up the integration safely and verify each layer before relying on it in production.
This guide uses agent-cli to refer to the AI agent tool in question. It is a command-line program that runs on macOS, Linux, or Windows. Before getting started, make sure you meet the following prerequisites:
- You can run commands in a terminal and edit text files.
- You have obtained an API key from your model provider and know the service’s base URL and available model identifiers.
- The service endpoint is OpenAI-compatible, meaning it exposes both
/v1/modelsand/v1/chat/completions. If your provider uses a different protocol, the curl checks below will need to be adapted according to its documentation. - Your runtime version meets the tool’s requirements—check the official documentation for details.
The configuration field names used below (provider, base_url, api_key_env, model) are generic and intended to illustrate the configuration approach. When configuring your actual tool, compare each field against its documentation.
Pre-Installation Checks
- Confirm your system architecture. On macOS and Linux, run
uname -mand check forx86_64orarm64/aarch64. On Windows PowerShell, run$env:PROCESSOR_ARCHITECTURE. - Confirm available disk space. On macOS and Linux, run
df -h ~and make sure the partition containing your home directory has enough free space—consult the tool documentation for the required amount. - Verify the installation package. Copy the SHA256 value from the release page, compute it locally, and compare:
shasum -a 256 agent-cli-installer.pkg # macOSsha256sum agent-cli-installer.tar.gz # Linux
Get-FileHash -Algorithm SHA256 .\agent-cli-installer.exe # Windows
If the hashes don’t match, delete the file and download it again. Do not proceed with installation.
- Check network proxy settings. Run
env | grep -i proxy. On Windows, runGet-ChildItem Env: | Where-Object Name -match proxy. If your corporate network requires a proxy, set the proxy variables in your configuration, or ask your network administrator to whitelist the service domain. - Create the configuration directory and restrict its permissions:
mkdir -m 700 ~/agent-config
On Windows, run the following in Command Prompt to restrict the directory to the current user:
icacls "%USERPROFILE%\agent-config" /inheritance:r /grant:r "%USERNAME%:(OI)(CI)F"
After installation, run agent-cli --version and agent-cli --help. Both commands must produce normal output before you proceed. Do not enter a real API key yet.
Configuring the Custom Provider
Start the interactive wizard:
agent-cli config add-provider
The wizard will ask for the following. Here’s how to fill in each item:
- Provider name: a local label only, such as
llm-provider. Avoid embedding environment names or personal names, so you can easily switch between multiple configurations. - Service endpoint (
base_url): enter the URL up to the version segment, for examplehttps://llm.example.com/v1. Do not append/chat/completions—the tool appends the path itself, and a duplicated path will result in a 404. Keep trailing slashes consistent; omitting them is recommended. - Key source: enter the environment variable name
LLM_API_KEY, not the key itself. The tool reads the variable at runtime, so the key never gets written into the configuration file. - Model identifier (
model): must exactly match theidreturned by the service, including case and version suffixes. The model list check in the next section will show these ids.
Once complete, the generated configuration file looks like this:
provider: llm-providerbase_url: https://llm.example.com/v1api_key_env: LLM_API_KEYmodel: model-id-from-provider
The configuration file path is determined by the tool; run agent-cli config path to find it. Make sure the file is readable and writable only by the current user:
chmod 600 ~/agent-config/config.yaml # use the path from `config path` outputls -l ~/agent-config/
The file’s permission bits in the output should be -rw-------.
When injecting the key, using the system keychain is recommended so the key never appears in shell history.
On macOS, store the key in the keychain first. You’ll be prompted for the password interactively:
security add-generic-password -s llm-api-key -a "$USER" -w
Then load it into an environment variable when needed:
export LLM_API_KEY="$(security find-generic-password -s llm-api-key -w)"
On Linux, read the key without echo so it only exists in the current session:
read -rs -p "API Key: " LLM_API_KEY && export LLM_API_KEY
On Windows, store the key in Credential Manager, then read it into an environment variable in your session startup script.
Layered Connectivity Verification
Verify in order from the bottom layer up. Only move to the next layer after the current one passes.
Layer 1: DNS and port.
nslookup llm.example.comnc -vz llm.example.com 443
On Windows, run Test-NetConnection -ComputerName llm.example.com -Port 443. The expected result is a resolved IP address and a successful connection on the port.
Layer 2: Authentication. Pass the key via an environment variable to keep it out of your command history. Don’t use the -v flag here—it prints request headers (including the key) to the terminal.
curl -sS -o /dev/null -w "HTTP %{http_code}\n" \-H "Authorization: Bearer $LLM_API_KEY" \https://llm.example.com/v1/models
The expected output is HTTP 200.
Layer 3: Model list.
curl -sS -H "Authorization: Bearer $LLM_API_KEY" \https://llm.example.com/v1/models | grep -o '"id": *"[^"]*"'
The ids in the output should match the model value in your configuration file.
Layer 4: Minimal chat request.
curl -sS https://llm.example.com/v1/chat/completions \-H "Authorization: Bearer $LLM_API_KEY" \-H "Content-Type: application/json" \-d '{"model":"model-id-from-provider","messages":[{"role":"user","content":"ping"}],"max_tokens":8}'
The expected response is JSON containing a choices field. Once this works, run a simple conversation through agent-cli itself.
Layer 5: Tool invocation chain. Before enabling file read/write or command execution, test in an empty directory and record the actual permission boundaries that take effect.
Log redaction: Before sharing logs in a support ticket or chat window, filter out sensitive data:
sed -E 's/(Bearer )[A-Za-z0-9._-]+/\1****/g; s/("api_key": *")[^"]*/\1****/g' agent.log > agent.redacted.log
Fields that need redaction include: Authorization headers, any field whose name contains key, token, or secret, cookies, full prompts, and model response bodies.
Troubleshooting Common Issues
| Symptom | Possible Cause | Verification Command | Fix |
|---|---|---|---|
| command not found | Executable not in PATH | which agent-cli |
Add the install directory to PATH, then reopen the terminal |
| HTTP 401 | Key is wrong, expired, or lacks permissions | echo ${#LLM_API_KEY} to check length without printing content |
Verify the environment variable; reissue and rotate the key if needed |
| HTTP 404 | /v1 missing or duplicated in base_url |
Request /v1/models directly |
Correct base_url |
| model not found | Case or version suffix mismatch in model |
Layer 3 above | Use the id returned by the service |
| Connection timeout | Proxy, firewall, or whitelist restrictions | curl -sS -o /dev/null --connect-timeout 5 -w "%{http_code} %{time_connect}\n" https://llm.example.com/v1/models |
Configure the proxy, or ask your network admin to allow the domain |
| TLS certificate error | Corporate intermediate certificate not trusted | openssl s_client -connect llm.example.com:443 -servername llm.example.com </dev/null |
Add the corporate CA certificate to the system trust store |
| HTTP 429 | Rate limit exceeded | Check the Retry-After response header |
Reduce request frequency and back off according to Retry-After |
When troubleshooting, work from the outside in: check the network first, then authentication, then the tool’s configuration. Change only one parameter at a time—otherwise you can’t tell which change had an effect.
Security and Operations
Key Rotation
- Generate a new key in the provider console.
- Update the key in your keychain or Credential Manager—don’t touch the configuration file.
- Reload the environment variable and restart
agent-cli. - Run the Layer 2 check from the verification section; proceed once it returns 200.
- Revoke the old key in the console.
Step 5 is irreversible. Before revoking, confirm that all running instances have switched to the new key, or service will be interrupted.
Permission Checks
find ~/agent-config -perm -004 -print
This command lists files readable by other users. No output means the permissions are correct. If there is output, tighten the listed files with chmod 600.
Backups
Backups should not contain keys. After backing up, check with a fixed-string match:
grep -rIlF -- "$LLM_API_KEY" ~/agent-backup/
No output means the key isn’t in the backup. If there is output, delete or redact the listed files before storing the backup.
Upgrades and Rollback
- Record the current version:
agent-cli --version > ~/agent-config/version-before.txt. - Back up the configuration directory and confirm the backup contains no keys.
- Upgrade the tool and read the release notes for any configuration format changes.
- Run all the checks from the verification section.
- If any check fails, restore the previous installer and the configuration backup.
Risk note: some version upgrades rewrite the configuration format. Without a prior backup, your custom provider configuration may be lost and you’ll need to rerun the wizard from the configuration section.
Audit Fields
Audit logs should record timestamps, provider name, model identifier, HTTP status code, duration, and request ID. Do not log full conversation content or keys.
Summary
- Verify the installer hash before installation and make sure the configuration directory has 700 permissions.
- Add the provider through the wizard, with
base_urlending at/v1, and inject the key via an environment variable or the system keychain. - Complete layered verification in order: network, authentication, model list, chat request.
- Redact logs and check backups for keys before sharing them.
- Rotate keys regularly, back up your configuration before upgrades, and keep the previous installer on hand for rollback.
