Crates.io | ollama-proxy |
lib.rs | ollama-proxy |
version | 0.1.0 |
created_at | 2025-05-18 06:06:57.940522+00 |
updated_at | 2025-05-18 06:06:57.940522+00 |
description | Proxy server for Ollama |
homepage | |
repository | https://github.com/hehaoqian/ollama-proxy |
max_upload_size | |
id | 1678402 |
size | 187,113 |
WARNING: This crate is in early development. Use at your own risk. Use in production is not recommended.
This is a lightweight HTTP server that acts as a proxy for the Ollama API. It forwards requests to an Ollama server and provides additional features like API authentication, IP allowlisting, and HTTPS support.
cargo run -- --port 3001 --ollama-url http://localhost:11434
cargo run -- --port 3001 --ollama-url http://localhost:11434 --api-key YOUR_SECRET_KEY
cargo run -- --port 3001 --ollama-url http://localhost:11434 --allowed-ips "127.0.0.1,192.168.1.5"
cargo run -- --port 3001 --ollama-url http://localhost:11434 --db-url "sqlite:logs.db"
First, generate a self-signed certificate for testing:
./generate_cert.sh
Then run the server with HTTPS enabled:
cargo run -- --https --cert-file ./certs/server.crt --key-file ./certs/server.key
To make the server publicly accessible on all network interfaces:
cargo run -- --https --cert-file ./certs/server.crt --key-file ./certs/server.key --host 0.0.0.0
All command-line arguments can also be specified using environment variables with the PROXY_OLLAMA_
prefix. For example:
export PROXY_OLLAMA_PORT=3001
export PROXY_OLLAMA_URL="http://localhost:11434"
export PROXY_OLLAMA_API_KEY="your-secret-key"
export PROXY_OLLAMA_ALLOWED_IPS="127.0.0.1,192.168.1.5"
export PROXY_OLLAMA_HTTPS=true
export PROXY_OLLAMA_CERT_FILE="./certs/server.crt"
export PROXY_OLLAMA_KEY_FILE="./certs/server.key"
export PROXY_OLLAMA_HOST="0.0.0.0"
export PROXY_OLLAMA_LOG_FILE="./proxy.log"
export PROXY_OLLAMA_LOG_ROTATE_SIZE="10MB"
export PROXY_OLLAMA_MAX_LOG_FILES=5
export PROXY_OLLAMA_DB_URL="sqlite:logs.db"
cargo run
Option | Description |
---|---|
--port |
Port to listen on (default: 3001) |
--ollama-url |
Ollama server URL (default: http://localhost:11434) |
--log-file |
Output log file (if not specified, logs go to stdout only) |
--api-key |
API key required for model management endpoints |
--allowed-ips |
List of allowed IP addresses (comma-separated) |
--https |
Enable HTTPS mode |
--cert-file |
TLS certificate file path (required when HTTPS is enabled) |
--key-file |
TLS private key file path (required when HTTPS is enabled) |
--host |
Host address to listen on (default: 127.0.0.1, use 0.0.0.0 to listen on all interfaces) |
--log-rotate-size |
Maximum log file size before rotation (default: 10MB) |
--max-log-files |
Maximum number of rotated log files to keep (default: 0, unlimited) |
--db-url |
Database URL for request/response logging in SQLite format (e.g., "sqlite:logs.db") |
Documentation for all API endpoints is available at the root URL (e.g., http://localhost:3001/
or https://localhost:3001/
).
The server can log all API requests and responses to a SQLite database for auditing and debugging purposes. This feature is enabled by default but requires a database URL to be specified using the --db-url
option.
When enabled, the following information is logged:
Database logging is a compiled feature that can be disabled at build time by excluding the "database-logging" feature:
cargo build --no-default-features