simple-one-api
repository·main·Indexed 25 days ago
https://github.com/fruitbars/simple-one-apiA lightweight proxy layer that unifies domestic and international LLM providers into a single, standardized OpenAI-compatible API. It supports load balancing, model aliasing, automatic model selection, and rate limiting. It is designed for easy access to free model tiers from providers such as iFlytek Spark, Baidu Qianfan, Tencent Hunyuan, Cloudflare Workers AI, Coze.cn, Groq, Google Gemini, and SiliconFlow, making them compatible with clients like Next Chat, Lobe Chat, and gpt_academic.
What's inside simple-one-api
- simple-one-api is a proxy service designed to unify various domestic (Chinese) and international large language models (LLMs) into a single, standardized OpenAI-compatible API format. It aims to simplify integration by handling the subtle differences in API implementations across different providers, making them easy to use with any OpenAI-compatible client (like Next Chat, Lobe Chat, or gpt_academic) without needing to manage complex billing or traffic tracking for each individual provider.
Configure load balancing for credentials and models
mainThe
load_balancingconfiguration key controls how the backend selects between multiple available options. Settingload_balancingtorandomallows the system to automatically choose between multiple credential sets for the same model or between different services/models that are marked asenabled: true.Load balancing multiple credentials
To rotate through different API keys for the same model, define multiple service entries with the same model name but different
credentials:{ "server_port": ":9099", "load_balancing": "random", "services": { "openai": [ { "models": ["@cf/meta/llama-2-7b-chat-int8"], "enabled": true, "credentials": { "api_key": "xxx" }, "server_url": "https://api.cloudflare.com/..." }, { "models": ["@cf/meta/llama-2-7b-chat-int8"], "enabled": true, "credentials": { "api_key": "yyy" }, "server_url": "https://api.cloudflare.com/..." } ] } }Load balancing between different models/services
To let the backend randomly select a model from all enabled services, set
load_balancingtorandomand ensure the desired models haveenabled: true:{ "server_port": ":9099", "load_balancing": "random", "services": { "openai": [ { "models": ["@cf/meta/llama-2-7b-chat-int8"], "enabled": true, "credentials": { "api_key": "xxx" }, "server_url": "https://api.cloudflare.com/..." } ], "ollama": [ { "models": ["llama2"], "enabled": true, "server_url": "http://127.0.0.1:11434/api/chat" } ] } }Supported features of simple-one-api
mainThe service provides several advanced management features for LLM orchestration:
- Load Balancing: Supports configuring multiple models with random load balancing, and multiple
api_keys per model with random load balancing. - Unified API: Provides a single external
api_keyand supports both/v1and/v1/chat/completionspaths. - Model Aliasing: Supports model name redirection (aliasing) and global redirection (using
allmode to redirect all requests). - Automatic Model Selection: Supports a
randommodel type that automatically finds an available configured model. - Prompt Compatibility: For models that do not support a
systemrole, simple-one-api automatically prepends the system prompt to the first user prompt to ensure compatibility with clients like Immersive Translate. - Rate Limiting: Supports setting QPS (Queries Per Second), QPM (Queries Per Minute), or concurrency limits per service.
- Endpoint Management: Allows setting specific service addresses for each model type.
- Standard Endpoints: Supports
/v1/modelsand/v1/models/:modelfor model discovery.
- Load Balancing: Supports configuring multiple models with random load balancing, and multiple
Set up load balancing strategies
mainYou can control how the API selects between multiple enabled services or multiple API keys for the same model using the
load_balancingfield. Supported values are:first: Always picks the first enabled configuration.random: Randomly selects an enabled configuration.
To provide multiple API keys for a single model, add multiple objects to the service's array in
services.{ "api_key":"123456", "load_balancing": "random", "services": { "xinghuo": [ { "models": ["spark-lite"], "enabled": true, "credentials": { "appid": "xxx", "api_key": "xxx", "api_secret": "xxx" } }, { "models": ["spark-lite"], "enabled": true, "credentials": { "appid": "yyy", "api_key": "yyy", "api_secret": "yyy" } } ] } }Enable automatic load balancing in simple-one-api
mainTo avoid concurrency limits and automatically distribute requests across multiple models or multiple accounts for the same model, use the
load_balancingconfiguration key.Using
randomLoad BalancingSetting
load_balancingtorandomallows the server to automatically select a model from the pool of available services whereenabledis set totrue.Scenario 1: Mixing multiple different models
If you want to rotate between different providers (e.g., Spark, Qianfan, and Hunyuan), include them in your
servicesconfiguration and setload_balancing: "random".Scenario 2: Load balancing multiple accounts for a single model
If you have multiple sets of credentials (e.g., multiple
appids forspark-lite), you can define multiple entries for the same model within a service array. Whenload_balancingis set torandom,simple-one-apiwill randomly select one of the enabled credential sets for each request.{ "api_key":"sk-123456", "server_port":":9090", "load_balancing": "random", "services": { "qianfan": [ { "models": ["yi_34b_chat", "ERNIE-Speed-8K"], "enabled": true, "credentials": { "api_key": "xxx", "secret_key": "xxx" } } ], "xinghuo": [ { "models": ["spark-lite"], "enabled": true, "credentials": { "appid": "xxx", "api_key": "xxx", "api_secret": "xxx" } } ] } }Supported Model Providers and Features
mainsimple-one-api acts as a unified proxy for various providers, normalizing them to the OpenAI API format.
Supported Providers
- OpenAI ChatGPT series (OpenAI, Azure OpenAI, Cloudflare Workers AI, Groq)
- ByteDance Coze (Coze.com)
- Ollama (Local LLM runner)
Key Capabilities
- Load Balancing: Supports random load balancing across multiple models or multiple
api_keys for a single model. - Global Settings: Ability to set a global
api_keyor a global proxy mode. - Model Aliasing: Support for setting aliases for models.
- Automatic Model Selection: Using the
randommodel name automatically finds an enabled model. - Protocol Normalization: Supports both
/v1and/v1/chat/completionspaths. For models that do not natively support asystemrole, simple-one-api automatically injects the system prompt into the first user prompt to ensure compatibility with clients like immersive translation.
Apply for Tencent Hunyuan (hunyuan-lite) API access
mainTo use the
hunyuan-litemodel viasimple-one-api, you must first obtain an API key from the Tencent Cloud console.- Visit the Tencent Hunyuan access page: https://console.cloud.tencent.com/hunyuan/start.
- Locate the option to create keys (创建密钥).
- On the new page, select 'New Key' (新建密钥) to generate your credentials.
- You can use the Tencent Cloud debugging interface to test your keys before integrating them into
simple-one-api.
Obtain API access for coze.cn
mainTo use coze.cn models via
simple-one-api, you must first create and publish a Bot on the coze.cn platform with API capabilities enabled. Follow these steps:- Create a Bot: Navigate to the coze.cn platform and initiate the Bot creation process.
- Configure the Bot: Set up your Bot's configuration and select your desired model.
- Publish the Bot:
- Click publish.
- Select Skip and publish directly (跳过并直接发布).
- Crucially, check the Bot as API option before clicking publish.
- Retrieve Credentials:
- Personal Access Token: Generate this at https://www.coze.cn/open/api.
- Bot ID: This is the numeric ID found in the URL of your Bot's development page (e.g., in
.../bot/73428668*****, the ID is73428668*****).
Manage the simple-one-api systemd service
mainOnce the service is installed, you can manage thesimple-one-apiservice using standardsystemctlcommands.Apply for iFlytek Spark-Lite (spark-lite) model credentials
mainTo use the
spark-litemodel viasimple-one-api, you must obtain credentials from the iFlytek Spark API platform.- Visit the Spark API introduction page: https://xinghuo.xfyun.cn/sparkapi?scr=true.
- Access the iFlytek Console at https://console.xfyun.cn/services/cbm to retrieve your specific credentials.
- Locate the following three required pieces of information in the console:
appidapikeyapisecret
You can also use the iFlytek Debugging Center to test the model before integrating it.
Build the project using build_docker.sh
mainTo build the project using the provided shell script, follow these steps:
- Grant execution permissions: Ensure the script is executable.
- Run the script: Execute the script and pass the desired version number as an argument (e.g.,
v0.5).
chmod +x build_docker.sh ./build_docker.sh v0.5Configure Gemini in simple-one-api
mainTo use Google Gemini models, create a new service entry with the type
geminiin your configuration. You must provide your API key obtained from the Google AI Studio.Because the Gemini free tier has strict rate limits, it is highly recommended to configure the
limitobject within the service definition to prevent API errors.Gemini Free Tier Limits:
- RPM (Requests Per Minute): 15
- TPM (Tokens Per Minute): 1,000,000
- RPD (Requests Per Day): 1,500
{ "server_port": ":9099", "log_level": "prodj", "load_balancing": "random", "services": { "gemini": [ { "models": ["gemini-1.5-flash"], "enabled": true, "credentials": { "api_key": "xxx" }, "limit": { "rpm": 15, "timeout": 120 } } ] } }