An open-source router for public DeepSeek API services with custom policies (e.g., lowest price, highest output token rate).
Currently, it supports DeepSeek R1 and the following providers:
- Volcengine Ark
- Together.ai
- NVIDIA NIM
- DeepSeek
- Azure AI Foundry
- Fireworks.ai
- Alibaba Cloud Bailian
- Tencent Cloud TI
- Huawei Cloud ModelArts
- SiliconFlow
- China Mobile Cloud
- State Cloud
The following table explains the metrics that this tool can evaluate:
| Abbreviation | Full Form | Description | Supported Statistics |
|---|---|---|---|
| ttft | Time to first token | Latency between input submission and generation of the first output token | average, median, p90, p99 |
| prefill | Prefill tokens per second | # of input tokens / ttft | average, median, p90, p99 |
| decode | Decode tokens per second | # of output tokens / (total time - ttft) | average, median, p90, p99 |
| otps | Output tokens per second | # of output tokens / total time | average, median, p90, p99 |
| otpr | Output tokens per request | Total output tokens (including reasoning tokens) generated to answer one user request | average, median, p90, p99 |
| success | Request success rate | Percentage of requests completed without errors/timeouts (regardless of correctness) | |
| gpqa | Graduate-Level Google-Proof Q&A | Benchmark testing expert-level knowledge across STEM/humanities | |
| aime2024 | American Invitational Mathematics Examination 2024 | Math problem-solving benchmark based on real competition questions | |
| livecodebench | Live Coding Benchmark | Code generation evaluation with execution testing | |
| mmlu | Massive Multitask Language Understanding | 57-subject multiple-choice test spanning STEM/humanities | |
| ceval | Chinese Evaluation | Chinese-language benchmark | |
| output_price | Output token price | CNY per million output tokens | |
| input_price | Input token price | CNY per million input tokens |
conda create -n deepseek_router python=3.10
conda activate deepseek_router
git clone --recurse-submodules [email protected]:llm-router/DeepSeekRouter.git
cd DeepSeekRouter
pip install -e .- Change the
logfield inconfig/cron.jsonto where you want to store the logs. - Set the
defaultfield of each provider to your own API key inconfig/keys.json. Ignore those providers of which you do not have a key and those that you do not plan to evaluate.
{
"volcengine": {
"default": "your-key-for-volcengine"
},
"together": {
"default": "your-key-for-together.ai"
},
...
- You do not need to configure the endpoints of the inference providers except for Azure AI Foundry. You need to change the
base_urlfield to your own endpoint.
- Change the connection string in
config/db.jsonto yours. If you use MySQL, it should look like:
{
"conn_str": "mysql+mysqlconnector://user:12345678@localhost:3306/deepseek_router"
}
- Run the following command to create tables:
python deepseek_router/model/model.py- Run the following command to start the web app:
python deepseek_router/app/app.py- The dashboard is available at
http://localhost:5000. You need to run the evaluation to see the results. Check outdeepseek_router/app/templates/home.htmland make your changes to the dashboard.
You should use deepseek_router/cron/benchmark_test_all.py to evaluate intelligence. It can take one day or more to run a dataset.
- Download the datasets:
./scripts/download_datasets.sh # Download dataset for opencompass evaluate- Use
llmqos/cron/benchmark_test_all.pyto evaluate intelligence. It can take one day or more to run a dataset. Use--outputflag to specify the output format.
Available datasets are under data/datasets.json. Note that only gpqa, aime2024 and ceval have been tested.
python deepseek_router/cron/benchmark_test_all.py --dataset <dataset> --output <db OR csv OR both> # run dataset for all providersYou should use deepseek_router/cron/service_perf_test_all.py to evaluate performance. It can take a few minute for one run. You should run it for enough time in order to get an accurate result.
python deepseek_router/cron/service_perf_test_all.py --output <db OR csv OR both>By default, we use ShareGPT and L-Eval datasets for performance testing. You can write your own prompt generator and use that for performance testing.
After you have done evaluation, you can provide your requirement and find out the right providers for you. A requirement file looks like:
{
"filters": [
{
"metric": "success",
"min": 0.95
},
{
"metric": "otps",
"stat": "p90",
"min": 30
},
{
"metric": "gpqa",
"min": 60
}
],
"order": [
{
"metric": "output_price"
}
]
}
Run the router program:
python deepseek_router/router/router.py --requirement <PATH_TO_YOUR_REQUIREMENT_FILE>We have referred to the design of the following projects/websites:
We reused OpenCompass for running benchmarks.