Ollama API Proxy Server
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.
Features
- API Forwarding: Forwards requests to an Ollama API server
- Authentication: Optional API key authentication for model management endpoints
- IP Allowlisting: Restrict access to specific IP addresses
- HTTPS Support: Optional TLS/SSL encryption for secure connections
- Logging: Console and file logging options
- Database Logging: Optional request and response logging to SQLite database
Usage
Basic HTTP Server
With Authentication
With IP Allowlisting
With Database Logging
With HTTPS (Secure Connections)
First, generate a self-signed certificate for testing:
Then run the server with HTTPS enabled:
To make the server publicly accessible on all network interfaces:
Using Environment Variables
All command-line arguments can also be specified using environment variables with the PROXY_OLLAMA_ prefix. For example:
Command-Line Options
| 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") |
API Endpoints
Documentation for all API endpoints is available at the root URL (e.g., http://localhost:3001/ or https://localhost:3001/).
Database Logging
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.
Database Schema
When enabled, the following information is logged:
- Timestamp of the request
- Client IP address
- HTTP method
- Request path
- Request headers (as JSON)
- Request body (as JSON when possible)
- Response status code
- Response headers (as JSON)
- Response body (as JSON when possible)
Disabling Database Logging
Database logging is a compiled feature that can be disabled at build time by excluding the "database-logging" feature: