AI Gateway Endpoints and Environment Variables
In addition to One-Click Takeover for ready-made AI tools, you can directly call the AI Gateway in your own applications, scripts, or any AI tool. This guide walks you through the endpoint formats provided by the gateway, and how to connect using virtual keys.
Proxy Endpoints
The AI Gateway’s proxy service listens on http://127.0.0.1:11580. To ensure compatibility with various SDKs and tools, the gateway offers multiple protocol endpoint formats on the same port:
| Protocol Format | Endpoint Path | Applicable Scenarios |
|---|---|---|
| OpenAI Compatible | http://127.0.0.1:11580/v1 | Any SDK or tool using the OpenAI API format (e.g., /v1/chat/completions) |
| Anthropic Compatible | http://127.0.0.1:11580/v1/messages | Anthropic SDK, Claude Code, and similar tools |
| Gemini Compatible | http://127.0.0.1:11580/v1beta | Google Gemini SDK, Gemini CLI, etc. |
Simply select the endpoint format that matches your SDK protocol, and direct requests to the gateway address. The gateway will then route requests to the right provider channel based on your virtual key permissions.
Authentication: Using Virtual Keys
All requests to the gateway use virtual keys for authentication, not the provider’s real API key. First, create a virtual key and copy its value from the Virtual Keys page.
On the AI Gateway → Endpoints page, you can pick a virtual key and have the gateway generate ready-to-use environment variable snippets for common tools.
Environment Variable Examples
Assuming you have already obtained a virtual key (represented as <your-virtual-key> below):
OpenAI-Compatible SDKs / Tools
bash
export OPENAI_BASE_URL="http://127.0.0.1:11580/v1"
export OPENAI_API_KEY="<your-virtual-key>"1
2
2
Claude Code / Anthropic
bash
# Note: The Anthropic protocol uses the gateway root address without /v1
export ANTHROPIC_BASE_URL="http://127.0.0.1:11580"
export ANTHROPIC_AUTH_TOKEN="<your-virtual-key>"1
2
3
2
3
Gemini
bash
export GOOGLE_GEMINI_BASE_URL="http://127.0.0.1:11580"
export GEMINI_API_KEY="<your-virtual-key>"1
2
2
Example Call (OpenAI Compatible)
bash
curl http://127.0.0.1:11580/v1/chat/completions \
-H "Authorization: Bearer <your-virtual-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "你好"}]
}'1
2
3
4
5
6
7
2
3
4
5
6
7
The model must be one you have configured in channels and that your virtual key is authorized to access.
Prerequisites
- The AI Gateway proxy service is running.
- At least one healthy channel is configured, and a virtual key has been created with the necessary model/channel permissions.
Frequently Asked Questions (FAQ)
- Q: Authentication failed in the request?
- A: Make sure you’re using a virtual key (not a real provider key), and that the key hasn’t expired or been revoked.
- Q: The model is unavailable or I lack permission?
- A: Verify that the
modelis configured in one of your channels, and your virtual key’s “allowed models/channels” includes it.
- A: Verify that the
- Q: Which endpoint format should I use?
- A: Choose based on your SDK’s protocol: OpenAI style uses
/v1, Anthropic style uses/v1/messages(base URL without/v1), Gemini style uses/v1beta.
- A: Choose based on your SDK’s protocol: OpenAI style uses
- Q: Can other devices on my local network access the gateway?
- A: By default, the gateway listens only on
127.0.0.1(localhost). This is the recommended, secure setting.
- A: By default, the gateway listens only on
Summary
The AI Gateway provides unified local endpoints compatible with OpenAI, Anthropic, and Gemini formats. With virtual key authentication, you can connect any application or AI tool to the gateway, benefiting from unified key management and usage tracking. For common CLI tools, you’ll find One-Click Takeover even more convenient.
