Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@kdump/gemini-any-llm) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Gemini Any LLM Gateway
Let the Gemini CLI access any large language model provider
中文版请见 README_CN.md
🎯 Project Overview
Gemini Any LLM Gateway is an API gateway service that lets you seamlessly access various large language model providers (such as OpenAI, ZhipuAI, Qwen, etc.) via the Gemini CLI. You can enjoy diverse AI model services without modifying the Gemini CLI.
Core Features:
- 🔌 Plug-and-play - Fully compatible, no Gemini CLI changes required
- 🌐 Multi-provider support - Supports Codex, OpenAI, ZhipuAI, Qwen, and more
- ⚡ High-performance streaming responses - Real-time streaming output for a smooth experience
- 🛠️ Intelligent tool calling - Complete Function Calling support
- 📁 Flexible configuration management - Global plus project-level configuration for easy use
🚀 Quick Start
Installation
- Install Gemini CLI (if you haven't yet):
npm install -g @google/gemini-cli@latest --registry https://registry.npmmirror.com
npm install -g @google/gemini-cli-core@latest --registry https://registry.npmmirror.com
- Install this gateway:
npm install -g @kdump/gemini-any-llm@latest --registry https://registry.npmmirror.com
First Run
Run the following command to get started:
gal code
First-run flow:
- The system automatically launches a setup wizard and asks you to choose an AI Provider (
openai
orcodex
) - Then fill in the following based on your provider:
- Base URL (OpenAI default:
https://open.bigmodel.cn/api/paas/v4
, Codex default:https://chatgpt.com/backend-api/codex
) - Default model (OpenAI default:
glm-4.5
, Codex default:gpt-5-codex
) - Auth mode (Codex only, supports
ApiKey
orChatGPT
) - API Key (required when you pick OpenAI or Codex in
ApiKey
mode)
- Base URL (OpenAI default:
- Configuration is saved to
~/.gemini-any-llm/config.yaml
- Automatically generates or updates
~/.gemini/settings.json
, setting the auth type togemini-api-key
- Automatically starts the background gateway service and waits for it to become ready
- Launches the Gemini CLI for conversation
💡 Codex ChatGPT mode: If you choose
Codex + ChatGPT
in the wizard, the first request will prompt you to finish OAuth login in a browser. The login link appears in the terminal. After a successful login, the token is stored in~/.gemini-any-llm/codex/auth.json
. Tokens refresh automatically so you don’t need to log in again.
Reconfigure
Run this when you need to reconfigure or switch providers:
gal auth
💡 Usage Examples
Basic conversation
# Start a conversation
gal code "Write an HTTP service in TypeScript"
# Explain code
gal code "Explain what this code does"
# Optimization tips
gal code "Help me optimize this algorithm"
Pass file content
# Analyze the code files in the current directory
gal code "Please analyze the architecture of this project"
# Request a code review
gal code "Please review my code and suggest improvements"
More options
# View all Gemini CLI options
gal code --help
# Use other Gemini CLI parameters
gal code --temperature 0.7 "Write a creative story"
📖 User Guide
Command overview
gal
provides the following primary commands:
gal code [prompt]
- Chat with the AI assistant (main feature)gal auth
- Configure AI service credentialsgal start
- Manually start the background gateway servicegal stop
- Stop the gateway servicegal restart
- Restart the gateway servicegal status
- Check the gateway statusgal kill
- Force-kill stuck processes (for troubleshooting)gal version
- Display the current versiongal --help
- Show help information
Codex ChatGPT (OAuth) mode
- Run
gal auth
, choose Codex as the provider, and set the auth mode to ChatGPT in the wizard. - The first time you run
gal code
orgal start
, the terminal prints ahttps://auth.openai.com/oauth/authorize?...
link. Copy it into a browser to complete the login. - During login the CLI spins up a temporary callback service on
127.0.0.1:1455
. If the port is taken, free it or try again (the CLI retries automatically and shows error reasons). - After the authorization succeeds you’ll see “Login successful, you may return to the terminal.” Tokens are saved to
~/.gemini-any-llm/codex/auth.json
, includingaccess_token
,refresh_token
,id_token
, and the refresh timestamp. - The gateway refreshes tokens automatically afterwards, so you don’t need to log in again. If you delete or move
auth.json
, the browser login will be triggered the next time you send a request.
To customize the token directory, set the
CODEX_HOME
environment variable (defaults to~/.gemini-any-llm/codex
).
Configuration management
The system supports a flexible configuration hierarchy. Higher priority values override lower ones:
- Project configuration (
./config/config.yaml
) - Highest priority, project-specific - Global configuration (
~/.gemini-any-llm/config.yaml
) - Medium priority, user defaults - Environment variables - Lowest priority, baseline settings
Supported providers
Provider | Base URL | Recommended models |
---|---|---|
Codex | https://chatgpt.com/backend-api/codex |
gpt-5-codex |
ZhipuAI (default) | https://open.bigmodel.cn/api/paas/v4 |
glm-4.5 |
OpenAI | https://api.openai.com/v1 |
gpt-4 , gpt-4o |
Qwen | https://dashscope.aliyuncs.com/compatible-mode/v1 |
qwen-plus , qwen-turbo |
Other OpenAI-compatible services | Custom URL | Matching model name |
Environment variable configuration
You can also configure settings with environment variables (baseline settings with the lowest priority):
# Choose the primary provider (supports openai or codex)
export GAL_AI_PROVIDER="codex"
# Codex configuration
# Auth mode can be apikey / chatgpt (default apikey)
export GAL_CODEX_AUTH_MODE="chatgpt"
# Provide the API Key when using ApiKey mode; leave empty for ChatGPT mode
export GAL_CODEX_API_KEY="your-codex-api-key"
export GAL_CODEX_BASE_URL="https://chatgpt.com/backend-api/codex"
export GAL_CODEX_MODEL="gpt-5-codex"
export GAL_CODEX_TIMEOUT="60000"
# Optional: reasoning parameters and output verbosity control
export GAL_CODEX_REASONING='{"effort":"medium"}'
export GAL_CODEX_TEXT_VERBOSITY="medium"
# Optional: custom OAuth token directory (defaults to ~/.gemini-any-llm/codex)
export CODEX_HOME="$HOME/.custom-codex"
# OpenAI / compatible service configuration
export GAL_OPENAI_API_KEY="your-api-key"
export GAL_OPENAI_BASE_URL="https://api.openai.com/v1"
export GAL_OPENAI_MODEL="gpt-4"
export GAL_OPENAI_TIMEOUT="30000"
# Optional: OpenAI organization ID
export GAL_OPENAI_ORGANIZATION="org-xxxxxx"
# Gateway configuration
export GAL_PORT="23062"
export GAL_HOST="0.0.0.0"
export GAL_LOG_LEVEL="info"
export GAL_GATEWAY_LOG_DIR="~/.gemini-any-llm/logs"
# General advanced configuration
export GAL_RATE_LIMIT_MAX="100" # API rate limit cap (per 15 minutes)
export GAL_REQUEST_TIMEOUT="120000" # Request timeout in milliseconds
export GAL_ALLOWED_ORIGINS="http://localhost:3000,http://localhost:8080" # Allowed origins for CORS
export GAL_LOG_DIR="/custom/log/path" # Custom log directory
Project-specific configuration
If you want different models or settings for a given project, create the following in the project directory:
mkdir config
cat > config/config.yaml << EOF
openai:
apiKey: "project-specific-key"
model: "gpt-4"
baseURL: "https://api.openai.com/v1"
timeout: 30000
gateway:
port: 23062
host: "0.0.0.0"
logLevel: "info"
logDir: "./logs"
EOF
To make Codex the default provider for the project, add:
aiProvider: codex
codex:
authMode: ApiKey
apiKey: "project-codex-key"
baseURL: "https://chatgpt.com/backend-api/codex"
model: "gpt-5-codex"
timeout: 60000
# Optional: customize reasoning effort and output verbosity
reasoning:
effort: medium
textVerbosity: medium
For OAuth login, switch to:
aiProvider: codex
codex:
authMode: ChatGPT
baseURL: "https://chatgpt.com/backend-api/codex"
model: "gpt-5-codex"
timeout: 60000
reasoning:
effort: medium
summary: auto
textVerbosity: medium
🔧 Detailed Configuration
API settings
aiProvider
- Primary provider type, chooseopenai
orcodex
codex.authMode
- Codex auth mode, supportsApiKey
(static key) orChatGPT
(OAuth login with automatic refresh)openai.apiKey
- API key for OpenAI or compatible services (required when usingopenai
)openai.baseURL
- Endpoint URL for OpenAI-compatible APIs (default: ZhipuAI)openai.model
- Default model name (default:glm-4.5
)openai.timeout
- Request timeout in milliseconds (default: 30000)codex.apiKey
- Codex API key (required only inApiKey
mode, optional inChatGPT
mode)codex.baseURL
- Codex API endpoint URL (default:https://chatgpt.com/backend-api/codex
)codex.model
- Codex model name (default:gpt-5-codex
)codex.timeout
- Codex request timeout in milliseconds (default: 60000)codex.reasoning
- Codex reasoning configuration, follows the Codex Responses API JSON schemacodex.textVerbosity
- Codex text verbosity, supportslow
/medium
/high
Gateway settings
gateway.port
- Service port (default: 23062)gateway.host
- Bind address (default: 0.0.0.0)gateway.logLevel
- Log level:debug
/info
/warn
/error
(default: info)gateway.logDir
- Log directory (default:~/.gemini-any-llm/logs
)
🛠️ Troubleshooting
AI assistant not responding
Symptom: gal code
hangs or shows no response
Solution:
# 1. Clean up stuck processes
gal kill
# 2. Try the conversation again
gal code "Hello"
Authentication failure
Symptom: API Key is rejected or authentication fails
Solution:
# Reconfigure credentials
gal auth
Checklist:
- Make sure the API Key is correct and still valid
- Verify that the baseURL matches the provider
- Confirm that the account has sufficient quota
Service fails to start
Symptom: Gateway fails to boot or health check reports errors
Solution:
# 1. Check service status
gal status
# 2. Restart the service manually
gal restart
# 3. If issues persist, force clean up
gal kill
gal start
Checklist:
- Check network connectivity to the AI provider
- Ensure port 23062 is free
- Verify the configuration file format is correct
Port conflict
Symptom: Port 23062 is already in use
Solution:
- Change the port in the configuration file:
# ~/.gemini-any-llm/config.yaml
gateway:
port: 23063 # Switch to another available port
- Or set it via environment variables:
export PORT=23063
Configuration issues
Symptom: Configuration validation fails
Solution:
- Check the syntax in
~/.gemini-any-llm/config.yaml
- Make sure all required fields are filled in
- Validate file permissions (should be 600)
Permission issues
Symptom: Unable to read or write configuration files
Solution:
# Ensure the directory permissions are correct
chmod 700 ~/.gemini-any-llm
chmod 600 ~/.gemini-any-llm/config.yaml
Network connectivity issues
Symptom: Connection times out or reports network errors
Solution:
- Check your network connection
- Try another
baseURL
(for example, a local mirror) - Increase the timeout:
openai:
timeout: 60000 # 60 seconds
View logs
To debug, inspect detailed logs:
# Tail gateway logs
tail -n 300 -f ~/.gemini-any-llm/logs/gateway-{date-time}.log
# Enable debug mode
export LOG_LEVEL=debug
gal restart
❓ FAQ
Q: What should I do when the input length exceeds the limit?
Symptom:
- Gemini CLI shows: "Model stream ended with an invalid chunk or missing finish reason."
- Gateway logs (
~/.gemini-any-llm/logs/
) contain errors such as:
InternalError.Algo.InvalidParameter: Range of input length should be [1, 98304]
Cause: The number of input tokens exceeds the default limit of the model
Solution:
- Increase the input limit via
extraBody.max_input_tokens
:
# ~/.gemini-any-llm/config.yaml or a project configuration file
openai:
apiKey: "your-api-key"
baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1"
model: "qwen-plus-latest"
extraBody:
max_input_tokens: 200000 # Increase the input token limit
- Default limits for common models:
qwen-plus-latest
: default 129,024, expandable to 1,000,000qwen-plus-2025-07-28
: default 1,000,000- Refer to vendor manuals for other models
Q: How can I switch to another AI provider?
Solution:
# Reconfigure credentials
gal auth
In the wizard, choose the provider you need. You can also preselect it with the environment variable GAL_AI_PROVIDER
(openai
or codex
).
Common configuration examples:
- OpenAI:
https://api.openai.com/v1
+gpt-4
orgpt-4o
- Qwen:
https://dashscope.aliyuncs.com/compatible-mode/v1
+qwen-plus
orqwen-turbo
- ZhipuAI:
https://open.bigmodel.cn/api/paas/v4
+glm-4.5
- Codex:
https://chatgpt.com/backend-api/codex
+gpt-5-codex
Q: How do I use a different model for a specific project?
Solution:
Create a config/config.yaml
file in the project root:
openai:
apiKey: "project-specific-key"
model: "gpt-4"
baseURL: "https://api.openai.com/v1"
timeout: 30000
gateway:
logLevel: "debug" # Use debug mode during project development
Project configuration has the highest priority and overrides global settings.
Q: The service is unreachable or slow after it starts?
Solution:
- Check the service status:
gal status
- Verify the network connection to the AI provider
- Consider increasing the timeout:
openai:
timeout: 60000 # 60 seconds
- If the issue persists, restart the service:
gal restart
📚 More Resources
- 📋 Development Guide - Development environment setup and build instructions
- 🧠 Architecture Guide - Detailed technical architecture and development notes
- 🧪 Testing Guide - Testing architecture and run instructions
🙏 Acknowledgements
This project draws inspiration from claude-code-router, llxprt-code, and aio-cli. We sincerely thank these excellent open-source projects and their contributors.
🤝 Contributing
Issues and pull requests are welcome!
📄 License
Apache License 2.0