Skip to main content

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 / LlamaIndex / CrewAI …等 一行代码都不用改

📦 Quick Start

Step-1:安装

PyPI(推荐)

uv add openai-router -U

或者

pip install openai-router -U

Step-2:启动

openai-router --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

openai_router-0.1.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_router-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file openai_router-0.1.1.tar.gz.

File metadata

  • Download URL: openai_router-0.1.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openai_router-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7e4aa6f4b08145c8792b7f25bce25c8a21a8893bca6c6f9d6c347fe398457220
MD5 2dc69b4e46335323c990944ea0022bd4
BLAKE2b-256 e2e2f20fef4d181fc408a4fa42d8dc5ea6e8e337fd72ac2982005a7d2dbf9074

See more details on using hashes here.

Provenance

The following attestation bundles were made for openai_router-0.1.1.tar.gz:

Publisher: pypi.yml on shell-nlp/openai_router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openai_router-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: openai_router-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openai_router-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd0c7b3c14ab762d1e88eff3d22be4ca1bc85006c88736fec9e68918d5ed3beb
MD5 66cafaf0fbe61001ce258b1ce31dab6c
BLAKE2b-256 84f81c7e82b6f8e1b5bc7dba8c8dd0bebe05e9bc3391519d68bfb3450f9097d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for openai_router-0.1.1-py3-none-any.whl:

Publisher: pypi.yml on shell-nlp/openai_router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page