openai-router
Project description
🚀 OpenAI Router
轻量级、持久化、零配置的 OpenAI API 统一网关
一键聚合 vLLM、SGLang、lmdeploy、Ollama…
✨ Features
| Feature | Description |
|---|---|
| 🌍 统一入口 | /chat/completions、/embeddings、/images/generations… 全部转发 |
| 🧩 多后端 | vLLM、SGLang、lmdeploy、Ollama… 任意组合 |
| 💾 持久化 | SQLite + SQLModel 零配置存储路由 |
| ⚡ 实时流 | SSE & Chunked Transfer 全双工支持 |
| 🎨 Web UI | Gradio 即用的管理面板 |
| 🔍 兼容 OpenAI | SDK / LangChain / AutoGen 等无需改动一行代码 |
📦 Quick Start
Step-1:安装
uv sync
Step-2:启动
python -m openai_router.main --host localhost --port 8000
浏览器自动打开
📍 UI:http://localhost:8000
📍 API:http://localhost:8000/v1
Step-3:添加后端 在 Web UI 「添加 / 更新」填入:
- 模型名:
gpt-4 - 后端 URL:
http://localhost:8080/v1
🔧 API Usage
像官方 OpenAI SDK一样调用
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="sk-dummy"
)
resp = client.chat.completions.create(
model="gpt-4",
messages=[{"role":"user","content":"hello"}],
stream=True
)
for chunk in resp:
print(chunk.choices[0].delta.content or "", end="")
cURL
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4","messages":[{"role":"user","content":"hi"}],"stream":true}'
🗂️ Endpoints
| Method | Path | Description |
|---|---|---|
GET |
/ |
Gradio Admin UI |
GET |
/docs |
OpenAPI Swagger |
GET |
/v1/models |
List available models |
POST |
/v1/responses |
Responses API |
POST |
/v1/chat/completions |
Chat completion |
POST |
/v1/embeddings |
Text embeddings |
POST |
/v1/images/generations |
DALL·E style |
POST |
/v1/audio/transcriptions |
Whisper |
| … | … | All OpenAI endpoints supported |
⚙️ Configuration
CLI Options
python -m openai_router.main --help
| Flag | Default | Description |
|---|---|---|
--host |
localhost |
Bind address |
--port |
8000 |
Bind port |
🏗️ Architecture
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openai_router-0.1.0.tar.gz.
File metadata
- Download URL: openai_router-0.1.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bcd03ed05938a1db188b38fab87583e18cca712ee864137b0c23b3e54fba8c6
|
|
| MD5 |
63e49c381aa53c43f0a7a30c9a7e7f98
|
|
| BLAKE2b-256 |
d46a20cb23b5e6267018f4df4e0fe4d95a85741daacba5482ae19b27ac36e015
|
Provenance
The following attestation bundles were made for openai_router-0.1.0.tar.gz:
Publisher:
pypi.yml on shell-nlp/openai_router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_router-0.1.0.tar.gz -
Subject digest:
4bcd03ed05938a1db188b38fab87583e18cca712ee864137b0c23b3e54fba8c6 - Sigstore transparency entry: 662122149
- Sigstore integration time:
-
Permalink:
shell-nlp/openai_router@08ff516f8597ed284779094712302733fb2b969e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/shell-nlp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@08ff516f8597ed284779094712302733fb2b969e -
Trigger Event:
push
-
Statement type:
File details
Details for the file openai_router-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_router-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23a049dc8f4fe79f5c6c241a34da1795b34d01031f799b6b5f36e1a5cd0e2dd4
|
|
| MD5 |
8e834b691fcf8108c68287d31cdf7e62
|
|
| BLAKE2b-256 |
268041e5b281cf906808d1dd9c5a96717fe42bd4b4a95fee060a9b6c5419f4ce
|
Provenance
The following attestation bundles were made for openai_router-0.1.0-py3-none-any.whl:
Publisher:
pypi.yml on shell-nlp/openai_router
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_router-0.1.0-py3-none-any.whl -
Subject digest:
23a049dc8f4fe79f5c6c241a34da1795b34d01031f799b6b5f36e1a5cd0e2dd4 - Sigstore transparency entry: 662122164
- Sigstore integration time:
-
Permalink:
shell-nlp/openai_router@08ff516f8597ed284779094712302733fb2b969e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/shell-nlp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@08ff516f8597ed284779094712302733fb2b969e -
Trigger Event:
push
-
Statement type: