Skip to content

Setup: CLIProxyAPI

Connect TomoriBot to an authorized upstream through CLIProxyAPI, a local Chat Completions proxy.

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.

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: 8
server:
host: "127.0.0.1"
port: 8317
discovery:
enabled: false
management:
allow-remote: false
secret-key: ""
disable-control-panel: true
access:
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.

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:

ProviderLogin flag
Antigravity--antigravity-login
Claude--claude-login
Codex--codex-login or --codex-device-login
Terminal window
$configPath = (Resolve-Path .\config.yaml).Path
.\cli-proxy-api.exe --config $configPath --antigravity-login

Complete 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.

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.

Terminal window
$configPath = (Resolve-Path .\config.yaml).Path
.\cli-proxy-api.exe --config $configPath

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.

  1. For a non-production bot running on the same computer as CLIProxyAPI, set ALLOW_PRIVATE_NETWORK=127.0.0.1:8317 in TomoriBot’s environment and restart the bot. Use the local listener configured above; no tunnel is needed.
  2. Run /providers (server managers) or /personal providers and add an OpenAI-Compatible custom endpoint with these settings:
FieldValue
Endpoint URLhttp://127.0.0.1:8317/v1
Auth tokenThe 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.

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.

Terminal window
$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 id
Remove-Variable engineKey, keyMatch, headers

An empty list needs upstream configuration. HTTP 401 means the server answered but rejected the client key.

SymptomAction
401Check the client key, separately from the upstream key.
404Use the /v1 base, without /chat/completions; check the model ID.
Rejected parametersLeave 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 errorsCheck tunnel setup. If you enabled Cloudflare Access, it needs the optional Access and Caddy setup; the Discord panel cannot supply Access headers directly.
Stream stopsCheck 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:

Terminal window
Get-NetTCPConnection -LocalPort 8317 |
Select-Object LocalAddress, LocalPort, State, OwningProcess

Expect 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.

Terminal window
$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.content
Remove-Variable engineKey, keyMatch, headers

A generated reply confirms upstream access. A missing socket-query result alone does not prove the API is unreachable.