Unified API gateway for LLM services - Rust implementation
1.2K
A high-performance Rust rewrite of uni-api, target is to maintaining 100% compatibility with the Python version's api.yaml configuration format.
This is a uni-api rust port(Yes RIIR), and with some changes like
/v1/messages.
# Set environment variables (all optional)
export DATABASE_URL=sqlite://./uni-api.db # Default: sqlite://./uni-api.db
export CONFIG_PATH=./api.yaml # Default: ./api.yaml
export HOST=0.0.0.0 # Default: 0.0.0.0
export PORT=8000 # Default: 8000
export RUST_LOG=uni_api_rust=debug # Optional: Enable debug logging
# Run the server
cargo run --release
# Or build and run the binary
cargo build --release
./target/release/uni-api-rust
The server will automatically:
api.yaml# 1. Create a minimal api.yaml
cat > api.yaml << 'EOF'
database_url: "sqlite://./uni-api.db"
providers:
- provider: openai
base_url: https://api.openai.com/v1
api:
- sk-your-openai-api-key
model:
- gpt-4
- gpt-3.5-turbo
tools: true
preferences:
rate_limit: "15/min"
api_keys:
- api: test-key-123:
role: admin
EOF
# 2. Run the server
cargo run --release
# Build Docker image
docker build -t uni-api-rust .
# Run container
docker run -p 8000:8000 -v $(pwd)/api.yaml:/app/api.yaml uni-api-rust
Uses the same api.yaml format as the Python version. See the Python version's documentation for configuration details.
POST /v1/chat/completions - Chat completionsPOST /v1/images/generations - Image generationPOST /v1/audio/transcriptions - Audio transcriptionPOST /v1/audio/speech - Text-to-speechPOST /v1/moderations - Content moderationPOST /v1/embeddings - Text embeddingsGET /v1/models - List modelsGET /v1/stats - Statistics (admin)GET /health - Health checkSame as the parent project
Content type
Image
Digest
sha256:7ec7c976c…
Size
17.9 MB
Last updated
about 1 year ago
docker pull ftd5x/uni-api-rust