Environment-variable instrumentation
How to set OPENAI_BASE_URL and ANTHROPIC_BASE_URL so an app or terminal sends its AI traffic through your Sentinel gateway
OPENAI_BASE_URL and ANTHROPIC_BASE_URL tell the official OpenAI and Anthropic SDKs, and tools built on them such as Claude Code, where to send API requests. Point them at your SUPERWISE® Sentinel gateway and every request goes through its guardrails first, with no code change. For a local gateway on port 8000, run export ANTHROPIC_BASE_URL="http://localhost:8000/anthropic".
Set the variables in your current terminal session or in your application's runtime config. Assuming your local Sentinel gateway is running on http://localhost:8000:
# For OpenAI SDKs & compatible frameworks
export OPENAI_BASE_URL="http://localhost:8000/openai/v1"
# For Anthropic SDKs & frameworks
export ANTHROPIC_BASE_URL="http://localhost:8000/anthropic"
# For Gemini/Google AI Studio SDKs
export GOOGLE_GEMINI_BASE_URL="http://localhost:8000/gemini"# Current PowerShell session only
$env:OPENAI_BASE_URL = "http://localhost:8000/openai/v1"
$env:ANTHROPIC_BASE_URL = "http://localhost:8000/anthropic"
$env:GOOGLE_GEMINI_BASE_URL = "http://localhost:8000/gemini"Each provider is exposed under its own path on the gateway. The OpenAI value ends in /v1 because the OpenAI SDKs add only /chat/completions to the base URL, and the gateway checks /openai/v1/chat/completions. Without /v1, the request skips the guardrails and goes on to the provider unchecked. For the full mapping of providers to environment variables and gateway paths, see the Gateway reference.
Once these variables are set, any application that initializes a standard SDK client sends its requests through Sentinel, with no code change.
Prefer not to manage these variables by hand across terminals? The Sentinel CLI proxy can inject and remove them globally with a single toggle.
Which clients read which variable?
| Client | Reads | Set it in code instead |
|---|---|---|
| OpenAI Python SDK | OPENAI_BASE_URL | OpenAI(base_url="http://localhost:8000/openai/v1") |
| OpenAI Node SDK | OPENAI_BASE_URL | new OpenAI({ baseURL: "http://localhost:8000/openai/v1" }) |
| Anthropic Python SDK | ANTHROPIC_BASE_URL | Anthropic(base_url="http://localhost:8000/anthropic") |
LangChain ChatOpenAI | OPENAI_BASE_URL, through the OpenAI SDK | ChatOpenAI(base_url="http://localhost:8000/openai/v1") |
| Claude Code | ANTHROPIC_BASE_URL | The env block in settings.json. See Use Sentinel with Claude Code |
| Codex CLI | Its own ~/.codex/config.toml, not the variables | sentinel proxy config apps writes it for you. See Sentinel CLI proxy |
| Claude Desktop (macOS/Linux) | Its own app config, not the variables | sentinel proxy config apps writes it for you. See Sentinel CLI proxy |
| curl | Neither | Call the gateway path directly, as below |
With curl, send the request to the gateway path in place of the provider's host. Your provider key goes in the same header as before:
curl http://localhost:8000/anthropic/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "claude-sonnet-4-5", "max_tokens": 256,
"messages": [{"role": "user", "content": "Hello"}]}'Custom providers
If you are routing a self-hosted or alternative OpenAI-compatible model, point the standard OPENAI_BASE_URL variable at your custom provider's path on the gateway instead:
export OPENAI_BASE_URL="http://localhost:8000/my-custom-model/v1"See Custom providers for the full setup.
FAQ
Does my API key change?
No. Keep your provider key where it is. The gateway holds no provider keys: it forwards the key your app sends to the provider. See Deploy a gateway.
How do I confirm traffic goes through the gateway?
Run sentinel test or call the gateway's POST /test route to see what your guardrails do to a prompt. /test is never recorded, so to see a real request, send one through a provider path and watch it appear in Live activity.
How do I unset the variables?
In bash or zsh, run unset OPENAI_BASE_URL ANTHROPIC_BASE_URL GOOGLE_GEMINI_BASE_URL. In PowerShell, run Remove-Item Env:OPENAI_BASE_URL, Env:ANTHROPIC_BASE_URL, Env:GOOGLE_GEMINI_BASE_URL. If the Sentinel CLI set them, run sentinel proxy off.
Does Sentinel work with Azure OpenAI and other OpenAI-compatible providers?
Yes. Sentinel works with any endpoint that speaks the OpenAI chat completions format, Azure OpenAI included. Register the endpoint on the gateway as a custom provider, with target_routes set to the path your client calls, then point the client at that provider's path on the gateway. The gateway passes your key header, api-key or Authorization, and the api-version query string through unchanged.
For Azure OpenAI's v1 endpoint, register {"provider_name":"azure","base_url":"https://<resource>.openai.azure.com","target_routes":["openai/v1/chat/completions"]} and set OPENAI_BASE_URL to http://localhost:8000/azure/openai/v1. For the deployment-based endpoint, set target_routes to ["openai/deployments/<deployment>/chat/completions"] and give the AzureOpenAI client azure_endpoint="http://localhost:8000/azure". A request to a path that is not in target_routes goes to the provider without the guardrails. See Custom providers.
Do I need to change my code?
No, if the app builds a standard SDK client and leaves the base URL at its default. An app that sets its own base URL in code needs that value changed to the gateway path, as in the table above.
Get Sentinel: Download for Windows, or start from Get started on macOS and Linux.
See also
- Sentinel CLI proxy: let the CLI manage these variables for you.
- Use Sentinel with Claude Code: set
ANTHROPIC_BASE_URLfor Claude Code. - Gateway reference: each provider's path on the gateway.
- Custom providers: self-hosted OpenAI-compatible models.
Updated 4 days ago