Setup: CLIProxyAPI
Connect TomoriBot to an authorized upstream through CLIProxyAPI, a local Chat Completions proxy.
1. Install CLIProxyAPI
Section titled “1. Install CLIProxyAPI”Follow the official quick start. The release archives contain ready-to-run executables; choose your operating system and CPU, extract the archive, and verify its checksum. Building a Git clone is optional.
2. Create the configuration
Section titled “2. Create the configuration”Configure CLIProxyAPI before starting it. If the installer started a service, stop it first.
Create config.yaml beside the executable (cli-proxy-api.exe on Windows). A separate config folder is optional; these examples keep both files together. Replace the client-key placeholder with at least 32 random bytes encoded as hex or base64, generated by your password manager.
config-version: 8server: host: "127.0.0.1" port: 8317 discovery: enabled: falsemanagement: allow-remote: false secret-key: "" disable-control-panel: trueaccess: api-keys: - "REPLACE_WITH_RANDOM_CLIENT_KEY"oauth: auth-dir: "~/.cli-proxy-api"The client key under access.api-keys authenticates TomoriBot to CLIProxyAPI. Keep config.yaml and the oauth.auth-dir credential files private and out of Git. Restrict access to your account and the process account.
Leave MANAGEMENT_PASSWORD unset and avoid --password and the management TUI: the empty management secret keeps management routes disabled, including behind the tunnel. If your version uses a different config format, apply these settings to its bundled config.example.yaml.
3. Connect the upstream
Section titled “3. Connect the upstream”Choose how CLIProxyAPI authenticates to the model provider. Both methods use the base configuration above.
Run the login command from the folder containing the executable and config.yaml. These examples use Antigravity; substitute your provider’s flag and review its consent screen before signing in:
| Provider | Login flag |
|---|---|
| Antigravity | --antigravity-login |
| Claude | --claude-login |
| Codex | --codex-login or --codex-device-login |
$configPath = (Resolve-Path .\config.yaml).Path.\cli-proxy-api.exe --config $configPath --antigravity-login./cli-proxy-api --config "$(pwd)/config.yaml" --antigravity-login./cli-proxy-api --config "$(pwd)/config.yaml" --antigravity-loginComplete the browser sign-in and wait for the terminal to report success. CLIProxyAPI saves credentials in oauth.auth-dir; an OAuth-only setup needs no upstream API-key block. Keep OAuth callback listeners local and use the same config path for login and startup. Other login flags are listed in --help and the upstream provider guides.
For an OpenAI-compatible API, add this top-level block to config.yaml and replace the sample URL, upstream key, and model ID:
api-keys: openai-compatibility: - name: "authorized-backend" base-url: "https://api.example.com/v1" keys: - api-key: "REPLACE_WITH_UPSTREAM_KEY" models: - name: "upstream-model-id" alias: "home-chat"4. Start the server
Section titled “4. Start the server”Start the server from the folder containing config.yaml. Substitute the executable’s actual path or installed command if needed; keep --config so it loads this file.
$configPath = (Resolve-Path .\config.yaml).Path.\cli-proxy-api.exe --config $configPath./cli-proxy-api --config "$(pwd)/config.yaml"./cli-proxy-api --config "$(pwd)/config.yaml"Leave the server running and continue to step 5. Keep server.host at 127.0.0.1; no inbound firewall exception or router port forwarding is needed.
5. Connect TomoriBot
Section titled “5. Connect TomoriBot”- For a non-production bot running on the same computer as CLIProxyAPI, set
ALLOW_PRIVATE_NETWORK=127.0.0.1:8317in TomoriBot’s environment and restart the bot. Use the local listener configured above; no tunnel is needed. - Run
/providers(server managers) or/personal providersand add anOpenAI-Compatiblecustom endpoint with these settings:
| Field | Value |
|---|---|
| Endpoint URL | http://127.0.0.1:8317/v1 |
| Auth token | The client key from access.api-keys |
Select the saved connection, add a Text Model using an ID or alias served by CLIProxyAPI, and confirm a Discord reply.
This URL assumes the bot runs directly on the host. In Docker, 127.0.0.1 identifies the container, so it cannot reach the host’s listener through that address. A bot running in production mode still requires the hosted-production route.
- Complete Cloudflare Tunnel using the text-engine profile and port 8317. Production requires a public HTTPS URL and public DNS answers.
- Run
/providers(server managers) or/personal providersand add anOpenAI-Compatiblecustom endpoint with these settings:
| Field | Value |
|---|---|
| Endpoint URL | Your tunnel’s base, such as https://engine.example.com/v1 |
| Auth token | The client key from access.api-keys |
Select the saved connection, add a Text Model using an ID or alias served by CLIProxyAPI, and confirm a Discord reply.
How to list available models
With CLIProxyAPI running, open another terminal to list its model IDs. Disable PowerShell transcripts or shell tracing before loading the client key. Close this terminal when finished.
Run this from the folder containing config.yaml; it reads the first client key from the layout above.
$keyMatch = [regex]::Match((Get-Content -LiteralPath .\config.yaml -Raw), '(?m)^access:\r?\n api-keys:\r?\n - "([A-Za-z0-9+/=_-]+)"[ \t]*\r?$')if (!$keyMatch.Success) { throw 'Expected a quoted client key under access.api-keys in config.yaml.' }$engineKey = $keyMatch.Groups[1].Value$headers = @{ Authorization = "Bearer $engineKey" }$base = 'http://127.0.0.1:8317/v1'$models = Invoke-RestMethod "$base/models" -Headers $headers$models.data | Select-Object idRemove-Variable engineKey, keyMatch, headersThe key is read without echo and passed to curl through stdin, keeping it out of process arguments.
set +xprintf 'CLIProxyAPI client key: 'read -r -s engine_keyprintf '\n'base='http://127.0.0.1:8317/v1'printf 'header = "Authorization: Bearer %s"\n' "$engine_key" | curl --config - --fail --silent --show-error "$base/models"unset engine_keyThe key is read without echo and passed to curl through stdin, keeping it out of process arguments.
set +xprintf 'CLIProxyAPI client key: 'read -r -s engine_keyprintf '\n'base='http://127.0.0.1:8317/v1'printf 'header = "Authorization: Bearer %s"\n' "$engine_key" | curl --config - --fail --silent --show-error "$base/models"unset engine_keyAn empty list needs upstream configuration. HTTP 401 means the server answered but rejected the client key.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Action |
|---|---|
401 | Check the client key, separately from the upstream key. |
404 | Use the /v1 base, without /chat/completions; check the model ID. |
| Rejected parameters | Leave context override blank and reasoning on Auto; TomoriBot already retries eligible parameter rejections before output starts. Check logs for degraded requests before enabling tools or relying on sampling controls. |
403, HTML login page, or tunnel errors | Check tunnel setup. If you enabled Cloudflare Access, it needs the optional Access and Caddy setup; the Discord panel cannot supply Access headers directly. |
| Stream stops | Check PC sleep, upstream quota, tunnel health, and the stream limits in the Cloudflare guide. |
Keep request/debug logging off unless diagnosing a redacted local reproduction. Rotate a leaked client key in CLIProxyAPI and TomoriBot’s saved endpoint, plus any optional relay using it. Revoke leaked upstream credentials separately.
Retire an account login
Revoke access in the upstream account settings, stop the proxy, and remove its local credential files. File deletion alone does not revoke tokens.
Check the local binding address
If the local API is unreachable, check its binding address from another terminal while CLIProxyAPI is running:
Get-NetTCPConnection -LocalPort 8317 | Select-Object LocalAddress, LocalPort, State, OwningProcessss -ltnp 'sport = :8317'lsof -nP -iTCP:8317 -sTCP:LISTENExpect only 127.0.0.1; stop if you see 0.0.0.0, ::, *, or a LAN address. Review existing firewall rules (wf.msc on Windows); do not open an inbound port or add router port forwarding. Windows TCP-state reporting can miss a reachable endpoint, so the query includes all states; the optional model lookup tests API reachability.
Test a local reply
If a model fails to reply in Discord, test it directly while CLIProxyAPI is running. Disable PowerShell transcripts or shell tracing before loading the client key.
Run this from the folder containing config.yaml; it reads the first client key from the layout above.
$keyMatch = [regex]::Match((Get-Content -LiteralPath .\config.yaml -Raw), '(?m)^access:\r?\n api-keys:\r?\n - "([A-Za-z0-9+/=_-]+)"[ \t]*\r?$')if (!$keyMatch.Success) { throw 'Expected a quoted client key under access.api-keys in config.yaml.' }$engineKey = $keyMatch.Groups[1].Value$headers = @{ Authorization = "Bearer $engineKey" }$base = 'http://127.0.0.1:8317/v1'$body = @{ model = Read-Host 'Model ID to test' messages = @(@{ role = 'user'; content = 'Reply with hello.' }) stream = $false} | ConvertTo-Json -Depth 4$reply = Invoke-RestMethod "$base/chat/completions" -Method Post -Headers $headers -ContentType 'application/json' -Body $body$reply.choices.message.contentRemove-Variable engineKey, keyMatch, headersThe key is read without echo and passed to curl through stdin, keeping it out of process arguments.
Replace REPLACE_WITH_MODEL_ID with the ID to test.
set +xprintf 'CLIProxyAPI client key: 'read -r -s engine_keyprintf '\n'base='http://127.0.0.1:8317/v1'printf 'header = "Authorization: Bearer %s"\n' "$engine_key" | curl --config - --fail --silent --show-error "$base/chat/completions" \ --header 'Content-Type: application/json' \ --data '{"model":"REPLACE_WITH_MODEL_ID","messages":[{"role":"user","content":"Reply with hello."}],"stream":false}'unset engine_keyThe key is read without echo and passed to curl through stdin, keeping it out of process arguments.
Replace REPLACE_WITH_MODEL_ID with the ID to test.
set +xprintf 'CLIProxyAPI client key: 'read -r -s engine_keyprintf '\n'base='http://127.0.0.1:8317/v1'printf 'header = "Authorization: Bearer %s"\n' "$engine_key" | curl --config - --fail --silent --show-error "$base/chat/completions" \ --header 'Content-Type: application/json' \ --data '{"model":"REPLACE_WITH_MODEL_ID","messages":[{"role":"user","content":"Reply with hello."}],"stream":false}'unset engine_keyA generated reply confirms upstream access. A missing socket-query result alone does not prove the API is unreachable.