Skip to main content

CLI reference

spanwayctl is the command-line client for a running gateway. It ships inside the gateway image and talks to the gateway's management and inference APIs, so it runs anywhere that can reach the gateway, not only on the host that runs it. This page describes the commands and options of the CLI in the image, and spanwayctl --help or spanwayctl <command> --help prints the exact list for the version you run.

A real-world scenario​

An engineer wants Claude Code to go through the company gateway so their usage counts against the team budget and passes the company guardrails. They sign in once with the CLI through SSO, run spanwayctl configure claude to point their Claude Code settings at the gateway with a virtual key, and then start Claude Code as usual with claude.

Steps​

  1. Define the spanwayctl shell function shown in Entry points.

  2. Sign in through the gateway's SSO. A browser opens, or the CLI prints the URL to open.

    spanwayctl --base-url https://gateway.example.com login --pkce
    spanwayctl whoami
  3. Check that the key works and which models it may use. The CLI calls the same routes as these commands.

    curl https://gateway.example.com/key/info -H "Authorization: Bearer $(spanwayctl auth print-token)"
    spanwayctl model-groups list
  4. Point Claude Code at the gateway with a virtual key, then start Claude Code on your machine as usual.

    spanwayctl configure claude --gateway-url https://gateway.example.com --api-key sk-... --model claude-sonnet-5-5
    claude
  5. In the Admin UI open Logs and filter on your user. The agent's requests are listed with their cost.

Expected result​

whoami shows you as signed in to the gateway, model-groups list shows the models your key may use, and Claude Code answers through the gateway with every request on the Logs page.

Entry points​

The image provides two commands. spanway starts the gateway itself (spanway --config config.yaml) and is documented on the quick start. spanwayctl is the client described here.

Run spanwayctl from the image by overriding the entrypoint. A shell function keeps the commands on this page short. It mounts the current directory for commands that read or write files, ~/.spanway from your machine, where the CLI keeps its login state, so spanwayctl login survives between runs, and ~/.claude, so the commands that configure Claude Code change the files it reads on your machine. The container runs as your own user id so the mounted directories stay writable, and the image's home directory is /app.

mkdir -p ~/.spanway ~/.claude
spanwayctl() {
docker run --rm -i $([ -t 1 ] && echo -t) --entrypoint spanwayctl --user "$(id -u):$(id -g)" \
-v "$PWD:/app/work" -w /app/work -v "$HOME/.spanway:/app/.spanway" \
-v "$HOME/.claude:/app/.claude" \
-e SPANWAY_PROXY_URL -e SPANWAY_PROXY_API_KEY \
registry.spanway.ai/spanway/spanway-ai:2.0.0 "$@"
}
spanwayctl --version

The function asks Docker for a terminal (-t) only when its output is a terminal. Inside $(spanwayctl auth print-token), an apiKeyHelper or a pipe it leaves -t off, because a terminal turns the line ending into a carriage return that would end up in the token and break the Authorization header.

A gateway on the Docker host is reachable from the container as http://host.docker.internal:4000 on macOS and Windows, and with --add-host host.docker.internal:host-gateway on Linux. Commands that open a browser, such as spanwayctl login --pkce, print the URL to open when no browser is available inside the container. The commands that write Claude Code settings store the gateway URL you give them, and the agent on your machine uses that URL, so give them an address that works from your machine too, such as the gateway's real hostname rather than host.docker.internal.

The image does not contain Claude Code, Codex, OpenCode or pi, so the commands that launch one of them (spanwayctl claude, spanwayctl codex, spanwayctl opencode and spanwayctl pi) and spanwayctl autoroute start, which runs a local proxy for Claude Code on your machine, do not work from the image. spanwayctl configure codex does not work from the image either, because it first checks the installed Codex version with codex --version. For Claude Code use spanwayctl configure claude or spanwayctl up, then start claude on your machine as usual. For Codex add the provider entry described on the Codex page to ~/.codex/config.toml yourself, and connect OpenCode and pi by hand as their pages describe.

Running spanwayctl with no subcommand opens an interactive shell that accepts the same commands.

Global options​

OptionEnvironment variableWhat it does
--base-urlSPANWAY_PROXY_URLGateway URL. Falls back to base_url from spanwayctl config, then to http://localhost:4000
--api-keySPANWAY_PROXY_API_KEYKey to authenticate with. When omitted, the key saved by spanwayctl login is used if it was issued for this gateway
--version, -vPrint the CLI version and the gateway's version, then exit

Every command below accepts these options before the command name, as in spanwayctl --base-url https://gateway.example.com keys list.

Authentication​

spanwayctl login​

Signs in through the gateway's SSO and stores the resulting credential locally. The CLI waits for you to finish the browser step for up to ten minutes, the time the gateway keeps the sign-in open, and then prints Authentication timed out. Please try again. Each sign-in writes an audit row on the gateway, see audit logs.

The secret part of the credential goes into your operating system's keychain (macOS Keychain, Windows Credential Manager or the Secret Service on Linux) when the optional keyring package is installed and a keychain is reachable. Otherwise it is stored in ~/.spanway/token.json, readable only by you, which also holds the non-secret details of the login. The CLI says where it went after each login, for example Credential stored in your OS keychain. or No OS keychain available. Credential stored in /app/.spanway/token.json (owner-only). Set SPANWAY_CLI_DISABLE_KEYRING=true to always use the file, for example on a shared build machine. Inside the container there is usually no keychain, so the file in the mounted ~/.spanway is used.

OptionWhat it does
--pkceSign in with an OAuth authorization code and PKCE through the system browser, with a refresh token that renews the key
--config-claudeAfter login, write the key into ~/.claude/settings.json so Claude Code routes through this gateway
spanwayctl --base-url https://gateway.example.com login --pkce

spanwayctl logout, spanwayctl whoami, spanwayctl version​

logout clears the stored key, whoami shows the current authentication status, and version prints the CLI and gateway versions.

spanwayctl whoami

spanwayctl auth print-token​

Prints a valid token and nothing else on stdout, with diagnostics on stderr, so it can serve as Claude Code's apiKeyHelper. A PKCE login renews itself here first. The token lifetime follows the gateway's SPANWAY_CLI_JWT_EXPIRATION_HOURS, 24 hours by default.

spanwayctl auth print-token

Coding agents​

spanwayctl claude, spanwayctl codex, spanwayctl opencode​

Each runs the named coding agent routed through the gateway. The command logs in if needed, verifies the key against the gateway, sets up the agent for this run, then hands off. Everything after the command name is forwarded to the agent. --skip-verify skips the pre-launch key check, and for Codex and OpenCode also the model list. spanwayctl pi does the same for pi and is hidden from the listing. What each agent gets for the run:

CommandWhat it sets upPage
spanwayctl claudeANTHROPIC_BASE_URL with the bare gateway URL, ANTHROPIC_AUTH_TOKEN with the key, ENABLE_TOOL_SEARCH and CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY when they are not set, and ANTHROPIC_API_KEY removed.Coding agent setup
spanwayctl codexA spanway provider passed as -c overrides with the gateway's /v1 address and the key in OPENAI_API_KEY, plus the gateway's model catalog written to ~/.codex/spanway-models.json.Codex
spanwayctl opencodeOPENAI_BASE_URL with the gateway's /v1 address, OPENAI_API_KEY with the key, and a spanway provider listing the key's chat models in OPENCODE_CONFIG_CONTENT.OpenCode
spanwayctl piA spanway provider written into ~/.pi/agent/models.json with the key's models and limits, SPANWAY_PROXY_API_KEY with the key, and --model spanway/<first model>.pi

There is no command for other agents. Gemini CLI, GitHub Copilot CLI, Aider and Goose are set up with their own settings, see other CLI agents.

These commands need the agent installed next to spanwayctl, and the gateway image does not contain any of them, so from the image they stop with Could not find naming the agent. For Claude Code use spanwayctl configure claude instead, which writes the gateway settings into its config on your machine.

spanwayctl up and spanwayctl down​

up patches ~/.claude/settings.json (on your machine, through the mount in the shell function) so every Claude Code session from any terminal goes through the gateway until you press Ctrl-C, writing in the key this command resolved. down restores the file after an up process was killed without a chance to clean up.

spanwayctl up

spanwayctl configure, spanwayctl reconfigure, spanwayctl unconfigure​

configure wires a coding agent to the gateway persistently (from the image, Claude Code only, see entry points) with a long-lived virtual key, choosing agents and models interactively on the first run and applying the saved setup afterwards. reconfigure edits a saved setup with the current choices as defaults. unconfigure disconnects the agents while keeping the saved setup, or deletes it with --forget. Each has claude and codex subcommands for one agent at a time.

CommandOptions
spanwayctl configure--api-key, --gateway-url (alias --base-url)
spanwayctl configure claude--api-key, --gateway-url, --model (the model Claude Code starts on, must be on /v1/models for the key), --default-model (stop pinning a model)
spanwayctl configure codex--api-key, --gateway-url, --model (required on first setup)
spanwayctl reconfigure--api-key, --gateway-url
spanwayctl reconfigure claude--api-key, --gateway-url, --model, --default-model
spanwayctl reconfigure codex--api-key, --gateway-url, --model
spanwayctl unconfigure--forget
spanwayctl unconfigure claude, spanwayctl unconfigure codex--forget
spanwayctl configure claude --gateway-url https://gateway.example.com --api-key sk-... --model claude-sonnet-5-5

spanwayctl debug claude and spanwayctl debug install-claude-command​

debug claude renders a Markdown report of one Claude Code session routed through the gateway, with spend, requests, responses and errors, and saves it under ~/.spanway/debug. install-claude-command installs a /spanway-debug slash command into ~/.claude/commands that runs it from inside Claude Code.

OptionDefaultWhat it does
--session-id$CLAUDE_CODE_SESSION_ID, else the most recent transcript in ~/.claudeWhich session to report on
--recent-bodies3Include request and response bodies for this many recent turns. Failed turns always get bodies
--max-body-chars20000Truncate each body to this length
--no-saveoffPrint only
spanwayctl debug claude --session-id e96634a3-fa28-4083-b354-55542e2dca01

spanwayctl autoroute​

Trials complexity-based auto-routing against the models your key can already use, without changing the gateway. configure discovers the accessible models and writes an ephemeral auto-router config, start launches an ephemeral local proxy on 127.0.0.1 at --port (default 5483) and routes Claude Code through it, and stop restores Claude Code's settings and stops a leftover proxy. up and down are hidden aliases of start and stop. From the image, start would run that proxy inside a container your Claude Code cannot reach, so use it only where spanwayctl and Claude Code run on the same machine.

spanwayctl autoroute configure && spanwayctl autoroute start

Keys​

spanwayctl keys list​

OptionWhat it does
--page, --sizePagination
--user-id, --team-id, --organization-id, --key-hash, --key-aliasFilters
--return-full-object, --no-return-full-objectReturn the full key object, on by default. --no-return-full-object returns only the key ids
--include-team-keysInclude team keys
--formattable (default) or json
spanwayctl keys list --team-id team-platform --format json

spanwayctl keys generate​

OptionWhat it does
--modelsComma-separated allowed models
--aliasesJSON object of model aliases
--spendMaximum spend
--durationValidity, for example 24h or 7d
--key-aliasA name for the key
--team-id, --user-id, --budget-idOwnership and budget
--configJSON object of extra parameters passed through to /key/generate
spanwayctl keys generate --models claude-sonnet-5-5,gpt-6.1-sol --key-alias ci --duration 30d --spend 50

spanwayctl keys delete​

Takes --keys or --key-aliases, each a comma-separated list.

spanwayctl keys delete --key-aliases ci

spanwayctl keys import​

Copies keys from another gateway. --source-base-url is required, --source-api-key authenticates to the source, --dry-run shows what would be imported and --created-since (YYYY-MM-DD or YYYY-MM-DD_HH:MM) limits the set.

spanwayctl keys import --source-base-url https://old-gateway.example.com --source-api-key sk-... --dry-run

Models​

spanwayctl models list, spanwayctl models info​

list shows the models the key can call, info shows the deployment details. Both take --format table|json, and info takes --columns, a comma-separated choice from public_model, upstream_model, credential_name, created_at, updated_at, id, input_cost and output_cost (default public_model,upstream_model,updated_at).

spanwayctl models info --columns public_model,upstream_model,input_cost,output_cost

spanwayctl models get​

Takes --id or --name.

spanwayctl models get --name claude-sonnet-5-5

spanwayctl models add, spanwayctl models update​

add MODEL_NAME creates a deployment and update MODEL_ID changes one. Both take repeatable --param (-p) entries for spanway_params and --info (-i) entries for model_info, each as key=value.

spanwayctl models add claude-sonnet-5-5 -p model=anthropic/claude-sonnet-5-5 -p api_key=os.environ/ANTHROPIC_API_KEY

spanwayctl models delete​

Takes the model id.

spanwayctl models delete 0b1c2d3e

spanwayctl models import​

Reads a YAML file in the config file's model_list shape and adds every entry. --dry-run previews, --only-models-matching-regex filters on spanway_params.model, and --only-access-groups-matching-regex filters on model_info.access_groups. Config files written for the gateway this one replaces are accepted as well, see the migration guide. Entries without a model_name or spanway_params.model stop the import before anything is sent, and models the gateway rejects are listed with the error, after which the command exits with status 1.

spanwayctl models import models.yaml --only-models-matching-regex '^anthropic/'

spanwayctl model-groups list​

Lists the model groups the key can access with their mode and pricing, as table or json through --format. This is the same /model_group/info data the VS Code extension uses for its model picker.

spanwayctl model-groups list --format json

Evals​

spanwayctl evals gate​

Starts an eval run from a YAML or JSON spec with the CI context of the job, waits for the gateway's verdict and exits 0 (passed or nothing to gate), 1 (failed), 2 (error, timeout or gateway unreachable) or 3 (bad usage). A timeout or SIGTERM cancels the run. Options are --spec (required), --dataset, --model (repeatable), --baseline-key, --timeout (default 1800 seconds), --poll (default 10 seconds), --report-detail full|summary and --github-comment. In GitHub Actions it also writes step outputs and the job summary. Gating pull requests on evals describes the spec and a workflow.

SPANWAY_PROXY_API_KEY=$SPANWAY_CI_KEY spanwayctl evals gate --spec .spanway/evals.yaml

spanwayctl evals run​

Runs one or more spec files, in the same format spanwayctl evals gate reads, prints each verdict and exits with the worst result, using the same exit codes. Every spec is checked before any run starts. --watch keeps the command open and runs the specs again whenever a spec or a --watch-path file or folder changes, until Ctrl-C, which cancels the run in flight. Options are --model (repeatable, overrides every spec's models), --watch, --watch-path (repeatable), --interval (default 1 second), --timeout (default 1800 seconds), --poll (default 10 seconds) and --report-detail full|summary. Evals as code explains the edit and re-run loop and the pytest plugin.

spanwayctl evals run .spanway/support.yaml --watch --watch-path prompts

spanwayctl evals verdict​

Prints the verdict of a run by id and exits like spanwayctl evals gate. It never starts or cancels anything. --timeout waits for a run that is still going, and --report-detail full|summary (default full) chooses whether the report lists item ids.

spanwayctl evals experiment run​

Scores a system that runs outside the gateway, such as an agent in the CI job, against a dataset and gates on the verdict like spanwayctl evals gate. It starts a run whose outputs are submitted, feeds the dataset items to COMMAND one JSON line per item on stdin, and reads back one JSON line per item with item_id and output or transcript. Options are --dataset (required), --scorer (JSON, exact match by default), --model (label for lines that name no model, default local), --baseline-key, --gate (JSON, for example {"min_pass_rate": 0.9}), --name, --command-timeout, --timeout and --report-detail full|summary. Systems that run outside the gateway covers the details.

spanwayctl evals experiment run --dataset support-golden --gate '{"min_pass_rate": 0.85}' -- python agent.py

Migrating an existing gateway​

spanwayctl migrate​

Moves an existing gateway deployment into Spanway. One subcommand copies the old gateway's Postgres database while keeping virtual key hashes, so existing keys keep working, and another translates its config file and env file. The migration guide lists both with every option.

Environments​

spanwayctl env promotes gateway config between environments as reviewed plans. It is an enterprise command that needs a license with environments, and the environments page explains scopes, approval and deploy keys. Every subcommand takes --organization <id> to work in an organization scope instead of the gateway scope. The gateway scope needs a proxy admin, and an organization scope needs an admin of that organization.

spanwayctl env export​

Writes the gateway's config as one YAML file per object into a bundle directory and removes files of exported kinds that no longer exist.

OptionWhat it does
--outDirectory of the bundle, required
--kindKind to export, repeatable. Every kind when left out
--organizationExport an organization scope
spanwayctl env export --out ./gateway-config

spanwayctl env plan​

Diffs the bundle against an environment and stores the result as a plan. It exits 0 when nothing would change, 2 when the plan has changes and 1 when the plan has problems. A bundle it cannot read, or a missing API key, exits 3.

OptionWhat it does
--dirBundle directory, required
--envName of the environment the plan targets, required
--prune, --no-pruneDelete managed objects the bundle no longer has. Off by default
--git, --no-gitRecord the commit, the bundle's path in the repository, whether it had uncommitted changes and the CI run on the plan. On by default
--git-refPlan the bundle exactly as committed at this branch, tag or commit instead of the working tree. A ref that does not exist exits 3
--organizationPlan against an organization scope
spanwayctl env plan --dir ./gateway-config --env prod

spanwayctl env approve, spanwayctl env reject​

Take the full PLAN_ID, the UUID the plan review shows, and an optional --note. The approver must be a different person from the planner, and a rejected plan can never be applied.

spanwayctl env approve 6f1c0e2a-9b7d-4c3e-8a21-5d4f3b2a1c09 --note "reviewed in the pull request"

spanwayctl env apply​

Applies PLAN_ID exactly as it was planned. It exits 1 when any object failed.

spanwayctl env apply 6f1c0e2a-9b7d-4c3e-8a21-5d4f3b2a1c09

spanwayctl env status​

Lists the latest plans of the scope.

spanwayctl env status

Teams and users​

spanwayctl teams list, spanwayctl teams available, spanwayctl teams assign-key​

list shows the teams you belong to, available shows the teams you may join, and assign-key --team-id ID moves your current virtual key, the one in --api-key or SPANWAY_PROXY_API_KEY, into a team. It refuses a spanwayctl login session with a message saying so, because a login session is issued for one team and is not a key that can move. To work in another team after spanwayctl login, sign in again and pick the team when asked.

spanwayctl teams assign-key --team-id team-platform

spanwayctl users​

CommandOptions
spanwayctl users listnone
spanwayctl users get--id
spanwayctl users create--email (required), --role (default internal_user), --alias, --team (repeatable), --max-budget
spanwayctl users delete USER_ID...one or more user ids
spanwayctl users create --email dev@example.com --role internal_user --team team-platform --max-budget 20

Credentials​

Stored credentials are reusable provider secrets that model deployments reference by name.

CommandOptions
spanwayctl credentials list`--format table
spanwayctl credentials get NAMEnone
spanwayctl credentials create NAME--info (required JSON, the non-secret fields), --values (required JSON, the secret fields), --display-name
spanwayctl credentials update NAME--display-name, --clear-display-name. The name itself cannot change
spanwayctl credentials delete NAMEnone
spanwayctl credentials create anthropic-prod --info '{"custom_llm_provider":"anthropic"}' --values '{"api_key":"sk-ant-..."}'

spanwayctl encryption migrate​

Re-encrypts credentials at rest into the AES-256-GCM format. It requires the gateway to run with general_settings.encryption_algorithm: aes-256-gcm, is idempotent and resumable, and takes --check for a read-only scan of what remains in the legacy format and --dry-run to walk everything without writing.

spanwayctl encryption migrate --check

Chat and raw HTTP​

spanwayctl chat​

An interactive streaming chat. The model is an optional argument and a picker appears without it. --temperature (-t, default 0.7), --max-tokens and --system (-s) set the request parameters.

spanwayctl chat claude-sonnet-5-5 -s "You are a terse assistant"

spanwayctl http request​

Sends any request to the gateway with the CLI's authentication. METHOD and URI are positional, --json (-j) sends a JSON body, --data (-d) sends a raw body, and --header (-H) adds a key:value header and repeats.

spanwayctl http request GET /health/readiness
spanwayctl http request POST /chat/completions -j '{"model":"claude-sonnet-5-5","messages":[{"role":"user","content":"hi"}]}'

Persistent configuration​

spanwayctl config manages ~/.spanway/config.json. get [KEY] prints one value or all of them, set KEY VALUE stores a value and unset KEY removes it. base_url is the value every command falls back to, and hidden_commands is a comma-separated list of command names to leave out of spanwayctl --help for users who should only see a curated subset. Hidden commands still run.

spanwayctl config set base_url https://gateway.example.com
spanwayctl config set hidden_commands codex,opencode

Errors​

What you seeWhat it meansFix
401 or Authentication ErrorThe stored key expired, or it was issued for another gateway.Run spanwayctl login again, or pass --api-key.
Authentication timed out. Please try again.The browser step was not finished within ten minutes, or the gateway never saw it finish.Run spanwayctl login again and finish the browser step. If you did finish it, check the gateway log for /sso/callback errors.
Your saved credential is a `spanwayctl login` session, not a virtual key, so it cannot be moved to a team. ...teams assign-key was run with a login session instead of a virtual key.Sign in again and pick the team, or pass a virtual key with --api-key.
No API key found. Please login first using 'spanwayctl login'A command that needs a credential found none.Run spanwayctl login, or pass --api-key.
401 on a request built with $(spanwayctl auth print-token)The token came back with a carriage return because the container ran with a terminal.Use the shell function above, which leaves -t off when the output is not a terminal.
Connection refused from inside the containerlocalhost inside the container is not the host.Use http://host.docker.internal:4000, with --add-host host.docker.internal:host-gateway on Linux.
login --pkce prints a URL and waitsNo browser is available inside the container.Open the URL in your browser and finish the sign in.
403 on a commandThe key's role may not run it, or the route needs a license feature.Use a key with the right role, or add the feature.
Permission denied writing ~/.spanway or ~/.claudeThe mounted directory belongs to another user, or did not exist and Docker created it as root.Keep --user "$(id -u):$(id -g)" and create both directories first.
Could not find \claude` on your PATH`The launch commands need the agent next to spanwayctl, and the image has none.Run spanwayctl configure claude, then start claude on your machine.
Claude Code cannot reach the gateway after configureThe stored URL only works inside the container, such as host.docker.internal.Run spanwayctl reconfigure claude --gateway-url with an address your machine can reach.

Logs​

spanwayctl writes no gateway log lines. It prints its own notes in the terminal, and auth print-token keeps them on standard error so they never mix with the token:

MessageMeaningAction needed
Credential stored in your OS keychain.The login secret is in the keychain.None.
Credential stored in <path> (owner-only). For OS keychain storage, install the keyring package with: ...No keyring package, so the file is used.None, or use an image that ships it.
Keychain storage is off (SPANWAY_CLI_DISABLE_KEYRING). Credential stored in <path> (owner-only).The keychain is turned off on purpose.None.
No OS keychain available. Credential stored in <path> (owner-only).No keychain is reachable, as is usual in a container.None.
Your keyring backend keeps nothing it is given, ...The keyring backend is the null backend.Run keyring --enable, or unset PYTHON_KEYRING_BACKEND.
Signed in, but the credential could not be saved to <path>: ...The login worked but nothing could be stored.Make ~/.spanway writable and sign in again.
Still waiting for authentication...The CLI is waiting for the browser step.Finish the sign-in in the browser.
Connection error (will retry): ...The gateway did not answer one poll.None unless it repeats, then check the address.