Other CLI agents
Many coding agents run in a terminal, and most of them can be pointed at a different server than their vendor's. This page connects four of them to Spanway: Gemini CLI, GitHub Copilot CLI, Aider and Goose. Once connected, each tool uses a virtual key your admin controls, so its spend counts against your team budget, the company guardrails and logging apply, and the admin can serve it any model the gateway knows. spanwayctl has launch commands only for Claude Code, Codex, OpenCode and pi, so these four tools are set up with their own settings, as shown below. Each tool speaks one of the API styles the gateway serves, and that decides which address you give it.
A real-world scenario
A team has developers who each prefer a different terminal agent: one uses Gemini CLI, one uses GitHub Copilot CLI, one uses Aider and one uses Goose. The admin wants all four on the gateway with the same budget rules. They create one key per developer and tool, for example ravi-gemini-cli and mei-aider, each with a monthly budget. Each developer follows their tool's section on this page, sends one prompt, and finds the request on the Logs page under their own key alias. When one developer's agent loops overnight, only that key hits its budget and stops.
Prerequisites
- The tool installed, at a current version. The setting names below come from each tool's own documentation and can change between releases.
- The gateway's address, for example
https://gateway.example.com, reachable from your machine. - A virtual key for the tool, made as in the next section.
- For Gemini CLI, at least one public model name on the gateway that the CLI can send. The name can point at any provider, see Gemini CLI.
Make a key for each tool
- In the Admin UI open Virtual Keys (
/ui/api-keys) and click + Create New Key. - Set Key Name to who and which tool, for example
ravi-gemini-cli,mei-aider,sam-gooseorlee-copilot-cli. Leave Key Type on AI APIs. - In Models, pick the models the developer will use in the tool, plus any helper model the tool sends side tasks to. Aider sends commit messages and chat summaries to its weak model, and Gemini CLI sends short helper calls to its own default models. A missing helper model makes those calls fail with 403 while the main chat works.
- Open Optional Settings. Set Max Budget (USD), for example
100, with Reset Budget on monthly, and a Requests per minute Limit (RPM) such as60. Leave Tags empty unless the gateway has an Enterprise license, because key tags need one and without it the key is not created (Only premium users can add tags to keys). The key name already keeps this tool's spend apart in Usage. - Click Create Key and copy the key. It is shown once.
curl -X POST https://gateway.example.com/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "mei-aider", "key_type": "llm_api", "models": ["claude-sonnet-5-5", "claude-haiku-5-5"], "max_budget": 100, "budget_duration": "30d", "rpm_limit": 60}'
Make a key for a tool explains every field.
Which address each tool needs
| Tool | API style | Setting for the address | Value | Route the gateway sees |
|---|---|---|---|---|
| Gemini CLI | Google Gemini | GOOGLE_GEMINI_BASE_URL | https://gateway.example.com, without /v1 or /v1beta | /v1beta/models/<model>:streamGenerateContent |
GitHub Copilot CLI, type openai | OpenAI | baseUrl in providers.json | https://gateway.example.com/v1, with /v1 | /v1/chat/completions, or /v1/responses with wireApi responses |
GitHub Copilot CLI, type anthropic | Anthropic | baseUrl in providers.json | https://gateway.example.com, without /v1 | /v1/messages |
| Aider | OpenAI | OPENAI_API_BASE | https://gateway.example.com/v1, with /v1 | /v1/chat/completions |
Goose, built-in openai provider | OpenAI | OPENAI_HOST and OPENAI_BASE_PATH | https://gateway.example.com and v1/chat/completions | /v1/chat/completions |
| Goose, custom provider | OpenAI | base_url in the provider file | https://gateway.example.com/v1/chat/completions, the full path | /v1/chat/completions |
Connect any client explains why some tools want /v1 and others do not.
Steps
Gemini CLI
Gemini CLI speaks the Google Gemini API. The gateway serves that API for any provider, so a public name such as gemini-3.8-flash can point at a Gemini deployment or at any other model the admin chooses.
-
Ask the admin which public model names your key may send. Gemini CLI cannot list models from the gateway, because the Gemini model listing route is not served, so you need the name in advance.
-
Set the key, the address and the model, in your shell profile or in
~/.gemini/.env. The base URL is the bare gateway root, because Gemini CLI adds/v1beta/models/...itself.export GEMINI_API_KEY="sk-..."export GOOGLE_GEMINI_BASE_URL="https://gateway.example.com"export GEMINI_MODEL="gemini-3.8-flash" -
Make sure Gemini CLI signs in with the API key and not with a Google account. A Google account sign-in ignores
GOOGLE_GEMINI_BASE_URLand goes straight to Google. Pick Use Gemini API Key in the CLI's/authmenu, or set it in~/.gemini/settings.json:{"security": { "auth": { "selectedType": "gemini-api-key" } },"model": { "name": "gemini-3.8-flash" }} -
Start the CLI and send a prompt, or run one prompt without the interface:
gemini -p "Say hello"
Gemini CLI sends the key in the x-goog-api-key header, which the gateway accepts. For a Vertex AI setup instead (GOOGLE_GENAI_USE_VERTEXAI=true and the vertex-ai sign-in), the address setting is GOOGLE_VERTEX_BASE_URL, which works the same way.
Gemini CLI also sends short helper calls of its own, for example to count tokens or to shorten a long session, and some of them name one of its default models rather than the one you set. If Logs shows 400 or 403 rows for a model name you never typed, the admin adds a deployment under that public name in Models + Endpoints (it may point at any provider) and adds it to your key.
GitHub Copilot CLI
GitHub Copilot CLI can use your own model provider through a file called providers.json. The gateway works as an openai type provider, or as an anthropic type provider for Claude models.
-
Open
~/.copilot/providers.json, or create it. To keep it somewhere else, setCOPILOT_PROVIDERS_CONFIGto its path before starting the CLI. -
Add the gateway as a provider, and list each model you will use. Copilot CLI does not read the gateway's model list, so every model is listed by hand.
{"providers": [{"name": "spanway","type": "openai","baseUrl": "https://gateway.example.com/v1","apiKey": "sk-...","wireApi": "completions"}],"models": [{ "id": "claude-sonnet-5-5", "provider": "spanway", "maxPromptTokens": 1000000, "maxOutputTokens": 128000 },{ "id": "sol", "provider": "spanway", "wireModel": "gpt-6.1-sol", "maxPromptTokens": 922000, "maxOutputTokens": 128000 }]} -
Protect the file, because the key is stored in it as plain text. Copilot CLI treats a value such as
$SPANWAY_API_KEYin this file as literal text and does not read your environment.chmod 600 ~/.copilot/providers.json -
Start the CLI on a gateway model. Switch during a session with
/model.copilot --model spanway/claude-sonnet-5-5
| Setting | What to put | Why |
|---|---|---|
type | openai, or anthropic for Claude models | Decides the API style. With anthropic, set baseUrl to https://gateway.example.com without /v1. |
baseUrl | https://gateway.example.com/v1 for openai | The CLI adds /chat/completions or /responses. |
apiKey or bearerToken | The virtual key | Either one works. The gateway reads the key from Authorization and from x-api-key. |
wireApi | completions (the default) or responses | Picks /v1/chat/completions or /v1/responses. Both work on the gateway. |
models[].id | The name you pick in the CLI | Also the name sent to the gateway, unless wireModel is set. |
models[].wireModel | A public name from GET /v1/models | Lets the CLI show a short id while sending the gateway's name. |
models[].modelId | A model name the CLI knows | Optional. Gives the CLI that model's built-in settings for a gateway name it does not know. |
maxPromptTokens, maxOutputTokens | From GET /model_group/info | The CLI uses them to fit the conversation into the model. |
An explicitly selected file wins over an environment configured provider, and an environment configured provider wins over the default providers.json. Setting COPILOT_OFFLINE=true before starting the CLI stops it from contacting its vendor's servers, for example for telemetry, while the model calls still go to the gateway.
Aider
Aider is a pair programming tool for the terminal that edits files in a git repository. It connects to the gateway as an OpenAI compatible endpoint.
-
Set the address and the key. The address includes
/v1.export OPENAI_API_BASE="https://gateway.example.com/v1"export OPENAI_API_KEY="sk-..." -
Start Aider with a gateway model name. Put
openai/in front of the name. Aider uses the prefix to pick the OpenAI style and removes it before sending, so the gateway receivesclaude-sonnet-5-5.aider --model openai/claude-sonnet-5-5 --weak-model openai/claude-haiku-5-5 -
To keep the settings, put them in
.aider.conf.ymlin your home folder or the repository root instead:openai-api-base: https://gateway.example.com/v1openai-api-key: sk-...model: openai/claude-sonnet-5-5weak-model: openai/claude-haiku-5-5
The weak model writes commit messages and summarises long chats. If you do not set one, Aider picks its own default, which may not be a name on the gateway. Aider does not know the context window or price of gateway names, so it prints a warning about an unknown model at start. The warning is harmless, and --no-show-model-warnings hides it.
Goose
Goose is an agent for the terminal and the desktop that uses extensions and MCP tools. It connects to the gateway with its built-in openai provider, its built-in anthropic provider, or a custom provider file.
-
Built-in
openaiprovider. Set the host without/v1, because Goose addsOPENAI_BASE_PATH, which defaults tov1/chat/completions.export GOOSE_PROVIDER="openai"export GOOSE_MODEL="claude-sonnet-5-5"export OPENAI_HOST="https://gateway.example.com"export OPENAI_BASE_PATH="v1/chat/completions"export OPENAI_API_KEY="sk-..."goose sessiongoose configureasks for the same values interactively, under Configure Providers. It stores the key in the system keychain. A key typed into Goose'sconfig.yamlis ignored, so the requests then arrive without one and fail with 401. -
Built-in
anthropicprovider, for Claude models. SetGOOSE_PROVIDER="anthropic",ANTHROPIC_HOST="https://gateway.example.com"without/v1, andANTHROPIC_API_KEYto the virtual key. -
Custom provider, which shows up in Goose under its own name. Create
~/.config/goose/custom_providers/spanway.json(on Windows,%APPDATA%\Block\goose\config\custom_providers\spanway.json). Herebase_urlis the full path.{"name": "spanway","engine": "openai","display_name": "Spanway","api_key_env": "SPANWAY_API_KEY","base_url": "https://gateway.example.com/v1/chat/completions","models": [{ "name": "claude-sonnet-5-5", "context_limit": 1000000 },{ "name": "gpt-6.1-sol", "context_limit": 922000 }],"headers": { "x-spanway-tags": "tool:goose" },"supports_streaming": true,"requires_auth": true}Export
SPANWAY_API_KEYwith the virtual key, then start a session withgoose session --provider spanway.
To tag requests from the built-in provider, set OPENAI_CUSTOM_HEADERS="x-spanway-tags=tool:goose". The gateway reads x-spanway-tags and records it on every request, so Usage can group Goose's spend.
Expected result
Each tool answers your prompt as it normally does. On the gateway's Logs page (/ui/logs), open Filters, pick the tool's Key Alias and click Apply Filters. Each call is one row with the model, tokens and cost, on the route from the address table. Helper calls, such as Aider's commit messages on the weak model or Gemini CLI's token counts, appear as their own short rows.
None of these tools show response headers. To read them, send one request with the same key from a terminal, in the tool's API style. For the OpenAI style:
curl -i https://gateway.example.com/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Say hello"}]}'
For the Gemini style, which is what Gemini CLI sends:
curl -i "https://gateway.example.com/v1beta/models/gemini-3.8-flash:generateContent" \
-H "x-goog-api-key: $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"contents": [{"role": "user", "parts": [{"text": "Say hello"}]}]}'
Look at x-spanway-call-id (the id to search for on Logs), x-spanway-model-group and x-spanway-routing-reason (which model group served the call and why, see routing decision headers), x-spanway-response-cost, and x-spanway-key-spend with x-spanway-key-max-budget for the budget left.
What works through the gateway
| Feature | Gemini CLI | GitHub Copilot CLI | Aider | Goose |
|---|---|---|---|---|
| Streaming | Yes, over :streamGenerateContent | Yes | Yes. --no-stream turns it off | Yes. Set supports_streaming in a custom provider |
| Tool calls | Yes. Gemini function declarations are translated for other providers | Yes | Aider edits files from the model's text answer and needs no tool calls | Yes. Goose depends on tool calls for its extensions, so pick models that support them |
| Images | Yes, when the model takes images | Yes, when the model takes images | Yes, add image files to the chat for a model that takes images | Yes, when the model takes images |
| Reasoning | thinkingConfig reaches models that support thinking | Model dependent | --reasoning-effort for models that support it | Model dependent |
| Prompt caching | Provider dependent | Provider dependent | --cache-prompts marks the prompt for caching. It only helps on models whose provider caches | Provider dependent |
| Model list from the gateway | No, the name is typed | No, models are listed in providers.json | No, the name is typed | No, models are typed or listed in the provider file |
A parameter that a tool always sends but the provider behind the name does not take fails with 400 and the message does not support parameters. The admin can turn on drop params for that deployment to remove it instead.
Errors
The third column is the text the gateway sends. Each tool wraps it in its own words: Gemini CLI shows it as an API Error with the message inside, Copilot CLI shows the status and message in the session, Aider prints the error type, such as AuthenticationError, followed by the message, and Goose shows the status and message in the session or in its log. The client error reference lists the same errors for every tool.
| Case | Status | Gateway text | Fix |
|---|---|---|---|
| No key reached the gateway | 401 | Authentication Error, No api key passed in. | The variable is not set in that terminal, or for Goose the key is in config.yaml. Set the key the way the tool's section says. |
| Wrong or deleted key | 401 | Authentication Error, Invalid proxy server token passed | Copy the key again from Virtual Keys, or ask the admin whether it was blocked. |
| Blocked key | 401 | Authentication Error, Key is blocked. Update via `/key/unblock` if you're an admin. | Ask the admin to open the key in Virtual Keys and click Unblock Key. |
| The key may not use the model | 403 | The requested model '<model>' is not available for this API key, or the model name is invalid. | Use a model the key allows, or ask the admin to add it, including helper models such as Aider's weak model. |
| The model name does not exist on the gateway | 400 | Invalid model name passed in model=<name> | Use a name from GET /v1/models, typed exactly. For Aider, check that only one openai/ prefix is in front of it. |
| A parameter the provider does not take | 400 | does not support parameters: <names>, for model=<model> | Ask the admin to turn on drop params for that deployment, or pick another model. |
| The budget is spent | 422 | Budget has been exceeded! Key=<key alias> Current cost: <spend>, Max budget: <max> | Wait for the reset, or ask the admin to raise the budget. |
| The key's rate limit is reached | 429 | Rate limit exceeded for <scope>: <value>. Limit type: <type>. | Wait for the reset time in the message, or ask for a higher RPM or TPM limit. |
Wrong path, such as /v1/v1/chat/completions or /v1/v1beta/... | 404 | Not Found | Use the exact value from the address table. Goose's OPENAI_HOST and Gemini CLI's GOOGLE_GEMINI_BASE_URL must not end in /v1. |
| Gemini CLI answers but nothing shows on Logs | none | None | The CLI signed in with a Google account and bypassed the gateway. Switch /auth to Use Gemini API Key. |
| Connection refused | none | None, the gateway never answered. | Check the address and port, and run curl https://gateway.example.com/health/liveliness. |
| TLS or certificate error | none | None, the connection failed before any answer. | Give the tool the company root certificate. Gemini CLI and Copilot CLI are Node programs that read NODE_EXTRA_CA_CERTS. Aider is a Python program that reads SSL_CERT_FILE or REQUESTS_CA_BUNDLE. For Goose, add the certificate to the operating system's trust store. See connection problems. |
Troubleshooting
- Find the request on Logs by the tool's key alias and the time. If a row is there, the drawer shows the status, the message, the model group the router picked and the provider's answer.
- If there is no row, the request never reached the gateway. Check the address against the address table and run the matching curl above with the same values.
- Turn on the tool's own debug output from the table below and look for the URL it calls and the status it gets back.
- Read the routing headers from the curl above.
x-spanway-attemptshigher than1means the gateway retried or fell back, andx-spanway-routing-reasonsays why.
| Tool | Debug switch | Where the output goes |
|---|---|---|
| Gemini CLI | gemini --debug (or -d) | The terminal. Press F12 in the CLI to open its debug console. |
| GitHub Copilot CLI | copilot --log-level debug | Log files in ~/.copilot/logs/, one per session, or the folder set with --log-dir. |
| Aider | aider --verbose | The terminal, with the settings Aider loaded and each request. |
| Goose | No switch needed | Goose writes logs under ~/.local/state/goose/logs/ on macOS and Linux, with the model requests in the llm_request files there. |
| Gateway | spanway --config config.yaml --detailed_debug on a test instance | The gateway log, with every request, the key check and the routing decision. |
Rotate or remove the key
To rotate, open the key on Virtual Keys, click Regenerate Key and set a Grace Period such as 24h so the old key keeps working while you switch. Put the new key where the tool reads it: the environment variable for Gemini CLI, Aider and Goose (or the keychain through goose configure), and apiKey in providers.json for Copilot CLI. POST /key/{key}/regenerate does the same from the API and needs an Enterprise license. Without one, create a new key, switch to it and delete the old one.
To stop using the gateway, remove the address setting from the tool: unset GOOGLE_GEMINI_BASE_URL, remove the spanway provider from providers.json, unset OPENAI_API_BASE for Aider, or switch Goose back to another provider in goose configure. To cut the key off, use Block Key in the key's actions menu, which can be undone, or delete the key. From the API, POST /key/block with {"key": "sk-..."} blocks it and POST /key/delete with {"keys": ["sk-..."]} deletes it.
Related
- Connect any client for the base URL rules shared by every tool.
- Client error reference for every gateway error with its cause.
- Gemini generateContent for the Gemini routes Gemini CLI calls.
- Make a key for a tool for the admin side.
- Codex, OpenCode and pi for the other terminal agents, and coding agent setup for Claude Code.