Sign inSign up

ftd5x/uni-api-rust

By ftd5x

•Updated about 1 year ago

Unified API gateway for LLM services - Rust implementation

Image
0

1.2K

ftd5x/uni-api-rust repository overview

⁠Uni-API Rust Implementation

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.

⁠Running

# 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:

  1. Load configuration from api.yaml
  2. Initialize the database (creates tables if they don't exist)
  3. Set up provider circular lists with rate limiting
  4. Start listening on the configured host:port

⁠Quick Start Example

# 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

⁠Docker

# 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

⁠Configuration

Uses the same api.yaml format as the Python version. See the Python version's documentation for configuration details.

⁠API Endpoints

  • POST /v1/chat/completions - Chat completions
  • POST /v1/images/generations - Image generation
  • POST /v1/audio/transcriptions - Audio transcription
  • POST /v1/audio/speech - Text-to-speech
  • POST /v1/moderations - Content moderation
  • POST /v1/embeddings - Text embeddings
  • GET /v1/models - List models
  • GET /v1/stats - Statistics (admin)
  • GET /health - Health check

⁠License

Same as the parent project

Tag summary

Content type

Image

Digest

sha256:7ec7c976c…

Size

17.9 MB

Last updated

about 1 year ago

docker pull ftd5x/uni-api-rust