Command reference

← Back to homepage

Setup and authentication

Running tools and commands

The command does not have to be one of the tools the gateway configures: an unknown name gets every supported tool's variables. So anything speaking the OpenAI API (OPENAI_BASE_URL, OPENAI_API_KEY) works unmodified:

No API key is needed. The key variables are set to the placeholder value proxy; the local proxy replaces it with your real credential on the way out. Because it relies on that local proxy, this does not cover CI runners or other machines where you cannot log in with ai-gateway.

The Anthropic and Google/Vertex variables are set too, so the official SDKs work the same way. ANTHROPIC_BASE_URL points at the proxy, which serves the Messages API. Every ai-gateway run sets it, but ai-gateway env deliberately does not: in a general shell it would redirect Claude Code when Claude Code is signed in to a Claude subscription rather than the gateway. So wrap Anthropic SDK scripts in ai-gateway run, or set the variable yourself for the command that needs it. Your own ANTHROPIC_API_KEY is left alone when you run a known tool — apart from goose, which uses that variable to reach the gateway. An unknown command gets the placeholder, like every other provider key.

One caveat for the unknown-name case: the variables include GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION, so a script that also calls gcloud, bq or terraform under ai-gateway run targets the gateway's Vertex project. Set them explicitly in the script if that is not what you want.

On Linux with systemd the proxy runs as a background service and your shell already has the variables, so run is optional there. On macOS and WSL nothing starts the proxy in the background, so use run, or keep ai-gateway serve going in a dedicated terminal — ai-gateway env alone leaves the variables pointing at a port with nothing listening.

Configuration

Background service (Linux with systemd)