Product Requirements Document: Ollama-OpenAI Proxy Service
Documents a completed proxy that translates Ollama API calls to OpenAI-compatible backends, enabling zero-code migration for existing Ollama applications.
What this file does
Documents a completed proxy that translates Ollama API calls to OpenAI-compatible backends, enabling zero-code migration for existing Ollama applications.
When to use it
- Evaluating whether to adopt this proxy for your own project
- Planning a similar API translation proxy between two LLM formats
- Reviewing a production-grade implementation as a reference architecture
- Assessing the feature set before contributing or forking
Assumes this stack
Product Requirements Document: Ollama-OpenAI Proxy Service
Executive Summary
✅ PRODUCTION-READY STATUS: This PRD documents a mature, enterprise-grade proxy service that has successfully achieved and exceeded all original requirements. The Ollama-OpenAI Proxy (v0.6.8) is now a comprehensive, production-ready solution that seamlessly translates between Ollama API format and OpenAI-compatible API backends.
Current Status: The proxy enables applications built for Ollama to work with any OpenAI-compatible LLM service (OpenAI, vLLM, LiteLLM, OpenRouter, etc.) without code changes, while providing advanced features beyond the original scope.
Primary Use Cases:
- ✅ N8N Integration: Enable N8N's Ollama model node to connect to OpenAI-compatible APIs
- ✅ Zero-Code Migration: Existing Ollama applications work unchanged
- ✅ Dual API Support: Native support for both Ollama and OpenAI API formats
- ✅ Enterprise Deployment: Production-ready with comprehensive monitoring and observability
Project Evolution: Originally planned as a basic translation proxy, the project has evolved into a sophisticated, enterprise-grade service with advanced features including metrics collection, tool calling, multimodal support, and comprehensive error handling - all while maintaining the core simplicity and reliability goals.
High-Level Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Ollama Client │────│ Proxy Service │────│ OpenAI API │
│ Applications │ │ (Translation) │ │ Compatible │
│ │ │ │ │ Backend │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Core Value Proposition
- Zero Code Changes: Existing Ollama applications work unchanged
- Dual API Support: Support both Ollama and OpenAI API formats simultaneously
- Universal Compatibility: Works with any OpenAI-compatible backend
- Production Ready: Proper logging, error handling, and monitoring
Implementation Phases
✅ Phase 1: Foundation & Core Translation (COMPLETED - v0.1.0 to v0.3.0)
✅ 1.1 Project Setup & Infrastructure (COMPLETED)
Goal: Establish development foundation
- ✅ FastAPI project structure with proper Python packaging
- ✅ Configuration management using Pydantic Settings
- ✅ Logging infrastructure with structured logging
- ✅ Environment-based configuration (.env support)
- ✅ Docker containerization setup
- ✅ Comprehensive CI/CD pipeline (GitHub Actions)
- ✅ Test framework setup (pytest, coverage >65%)
✅ 1.2 Core API Translation Engine (COMPLETED)
Goal: Implement basic request/response translation
- ✅ Pydantic models for Ollama and OpenAI API formats
- ✅ Translation layer between API formats:
- ✅ Chat completion requests/responses
- ✅ Text generation requests/responses
- ✅ Model listing endpoints
- ✅ Error response translation
- ✅ HTTP client with proper retry logic and connection pooling
- ✅ Request/response validation and sanitization
✅ 1.3 Basic Endpoints Implementation (COMPLETED)
Goal: Implement core proxy endpoints
- ✅
/api/chat→/v1/chat/completions(Ollama chat to OpenAI chat) - ✅
/api/generate→/v1/chat/completions(Ollama generate to OpenAI chat) - ✅
/api/tags→/v1/models(Model listing) - ✅
/v1/chat/completions(Native OpenAI format passthrough) - ✅
/v1/models(Native OpenAI format passthrough) - ✅ Health check and status endpoints
✅ 1.4 Configuration & Model Mapping (COMPLETED)
Goal: Flexible configuration system
- ✅ Environment variable configuration
- ✅ Optional model name mapping (JSON file)
- ✅ Default model handling
- ✅ Configuration validation
✅ Phase 2: Streaming & Advanced Features (COMPLETED - v0.4.0 to v0.5.0)
✅ 2.1 Streaming Support (COMPLETED)
Goal: Real-time streaming responses
- ✅ Server-Sent Events (SSE) for Ollama streaming format
- ✅ OpenAI streaming format support
- ✅ Streaming response translation between formats
- ✅ Proper connection handling and cleanup
- ✅ Stream error handling and recovery
✅ 2.2 Error Handling & Resilience (COMPLETED)
Goal: Production-grade error handling
- ✅ Comprehensive error mapping between API formats
- ✅ Retry logic with exponential backoff
- ✅ Circuit breaker pattern for upstream failures
- ✅ Timeout handling and configuration
- ✅ Graceful degradation strategies
✅ 2.3 Request Processing & Validation (COMPLETED)
Goal: Robust request handling
- ✅ Input validation and sanitization
- ✅ Request size limits and rate limiting
- ✅ Parameter translation and normalization
- ✅ Content-type handling (JSON, multipart)
- ✅ Request ID tracking for debugging
✅ 2.4 Logging & Monitoring (COMPLETED)
Goal: Observability and debugging
- ✅ Structured logging with correlation IDs
- ✅ Request/response logging (configurable verbosity)
- ✅ Performance metrics collection
- ✅ Health check endpoints with detailed status
- ✅ Error tracking and reporting
✅ Phase 3: Production Features & Polish (COMPLETED - v0.6.0 to v0.6.8)
✅ 3.1 Advanced Model Features (COMPLETED)
Goal: Enhanced model compatibility
- ✅ Embeddings endpoint support (
/api/embeddings↔/v1/embeddings) - ✅ Model capability detection
- ✅ Dynamic model routing
- ✅ Model health checking
✅ 3.2 Tool Calling & Multimodal Support (COMPLETED)
Goal: Advanced AI capabilities
- ✅ Function/tool calling translation between formats
- ✅ Image input support (base64, data URLs)
- ✅ Multimodal request handling
- ✅ Tool response formatting
✅ 3.3 Performance & Security (COMPLETED)
Goal: Production hardening
- ✅ Connection pooling optimization
- ✅ SSL/TLS configuration
- ✅ Security headers and CORS setup
- ✅ Request rate limiting
- ✅ Input sanitization for security
✅ 3.4 Deployment & Documentation (COMPLETED)
Goal: Easy deployment and adoption
- ✅ Multi-architecture Docker images
- ✅ Docker Compose configurations
- ✅ Comprehensive documentation
- ✅ API compatibility matrix
- ✅ Example integrations and use cases
✅ Phase 4: Advanced Features & Production Enhancements (COMPLETED - v0.6.0+)
Note: This phase represents features implemented beyond the original PRD scope, demonstrating the project's evolution into a mature, production-ready service.
✅ 4.1 Advanced Metrics & Observability (COMPLETED)
Goal: Production-grade monitoring and analytics
- ✅
/v1/metricsendpoint with Prometheus format support - ✅ System metrics collection (CPU, memory, disk usage)
- ✅ Request/response performance tracking
- ✅ Custom metrics middleware with detailed analytics
- ✅ Request body size and processing time tracking
- ✅ Error rate and success rate monitoring
✅ 4.2 Enhanced Error Handling System (COMPLETED)
Goal: Comprehensive error management and debugging
- ✅ Custom exception hierarchy (
ProxyException,UpstreamError,TranslationError) - ✅ Request correlation ID tracking for distributed tracing
- ✅ Error context preservation and detailed error reporting
- ✅ Graceful error propagation with proper HTTP status codes
- ✅ Error boundary handling for upstream service failures
✅ 4.3 Production Middleware Stack (COMPLETED)
Goal: Enterprise-grade request processing
- ✅ Advanced logging middleware with structured output
- ✅ Metrics collection middleware with performance tracking
- ✅ CORS handling for web application integration
- ✅ Request size validation and timeout enforcement
- ✅ Connection pooling with configurable limits
✅ 4.4 Version Management & API Versioning (COMPLETED)
Goal: Mature version control and API evolution
- ✅ Comprehensive version tracking system
- ✅
/v1/versionendpoint with detailed build information - ✅ API versioning support for future compatibility
- ✅ Build metadata and commit SHA tracking
- ✅ Development version detection
✅ 4.5 Advanced Request Processing (COMPLETED)
Goal: Robust input handling and validation
- ✅ Smart request body parsing with error recovery
- ✅ Content-type validation and normalization
- ✅ Request size limits and memory management
- ✅ Input sanitization for security compliance
- ✅ Parameter validation with detailed error messages
🔄 Phase 5: Documentation Enhancement & Developer Experience (IN PROGRESS)
Goal: Transform basic documentation into comprehensive, production-ready API reference that significantly improves developer onboarding and integration experience.
Priority: High - Critical for developer adoption and ecosystem growth
🔄 5.1 Comprehensive API Documentation (IN PROGRESS)
Goal: Complete documentation for all endpoints with examples and usage guidance
- 🔄 Document all available endpoints (
/api/*and/v1/*) with comprehensive examples - 🔄 Include detailed request/response examples for every endpoint
- 🔄 Document all supported parameters with validation rules and constraints
- 🔄 Add endpoint descriptions explaining purpose, use cases, and best practices
- 🔄 Create interactive examples that developers can test directly
🔄 5.2 Production Documentation Access (IN PROGRESS)
Goal: Enable comprehensive documentation in production environments
- 🔄 Enable Swagger/OpenAPI documentation access in production (currently DEBUG-only)
- 🔄 Add configurable documentation visibility controls
- 🔄 Implement proper access controls and security considerations
- 🔄 Create schema export capabilities (JSON/YAML) for CI/CD integration
- 🔄 Add documentation performance optimizations
🔄 5.3 Error Code & Authentication Documentation (IN PROGRESS)
Goal: Complete reference for error handling and authentication flows
- 🔄 Document all possible HTTP status codes with context and examples
- 🔄 Include error response examples with proper error structures
- 🔄 Add troubleshooting guidance for common error scenarios
- 🔄 Document API key requirements, format, and usage patterns
- 🔄 Include authentication examples for different endpoint types
- 🔄 Add security best practices and guidelines
🔄 5.4 Developer Experience Enhancements (PLANNED)
Goal: Reduce integration complexity and improve developer onboarding
- 🔄 Add code samples for popular programming languages (Python, JavaScript, cURL)
- 🔄 Document model compatibility and mapping strategies
- 🔄 Create quick start guides and common usage patterns
- 🔄 Add integration examples for popular frameworks (LangChain, N8N)
- 🔄 Implement schema validation in test suite for documentation consistency
🔄 5.5 Advanced Documentation Features (PLANNED)
Goal: Professional-grade documentation infrastructure
- 🔄 Dynamic versioning integration from
_version.py - 🔄 Contact information, license, and terms of service integration
- 🔄 Operation IDs for better client SDK generation
- 🔄 Pre-generated schema files for version control
- 🔄 CI/CD integration for schema consistency validation
Technical Requirements
✅ Core Technologies (IMPLEMENTED)
- Framework: FastAPI 0.104.0+ (modern, async, comprehensive auto-docs)
- Validation: Pydantic v2.5.0+ (advanced request/response models with custom validators)
- HTTP Client: httpx 0.25.0+ (async HTTP with advanced retry logic and connection pooling)
- Logging: structlog 23.2.0+ (structured logging with correlation IDs)
- Deployment: Multi-platform Docker + uvicorn with production optimizations
- Testing: pytest + pytest-asyncio + pytest-cov with 65.4% coverage
- Metrics: Custom middleware with Prometheus format support
- Security: Comprehensive input validation, CORS, SSL/TLS support
✅ Key Configuration Parameters (IMPLEMENTED)
# Required
OPENAI_API_BASE_URL=https://api.openai.com/v1 # Your OpenAI-compatible API URL
OPENAI_API_KEY=sk-your-api-key # API key for authentication
# Core Optional Settings
PROXY_PORT=11434 # Port for proxy service
LOG_LEVEL=INFO # Logging verbosity (DEBUG, INFO, WARNING, ERROR)
REQUEST_TIMEOUT=60 # Request timeout in seconds
MAX_RETRIES=3 # Maximum retry attempts
DEBUG=false # Enable debug mode
# Advanced Configuration
MODEL_MAPPING_FILE=./config/model_mapping.json # Optional model name mapping
DISABLE_SSL_VERIFICATION=false # Disable SSL verification (not recommended)
ENABLE_METRICS=true # Enable metrics collection
CORS_ORIGINS=* # CORS allowed origins
REQUEST_MAX_SIZE=10485760 # Max request size (10MB)
# Production Features (v0.6.0+)
ENABLE_PROMETHEUS_METRICS=true # Prometheus format metrics
METRICS_PATH=/v1/metrics # Metrics endpoint path
VERSION_ENDPOINT_ENABLED=true # Enable version endpoint
HEALTH_CHECK_TIMEOUT=30 # Health check timeout
✅ Deployment Options (IMPLEMENTED)
- Docker Hub:
eyalrot2/ollama-openai-proxy:latest(recommended) - GitHub Container Registry:
ghcr.io/eyalrot/ollama_openai:latest - PyPI Package:
pip install ollama-openai-proxy - Source Installation: Direct from GitHub repository
- Multi-Architecture: linux/amd64, linux/arm64 support
✅ API Endpoints (IMPLEMENTED)
✅ Ollama Format Endpoints
- ✅
POST /api/chat- Chat completion (Ollama style) with streaming support - ✅
POST /api/generate- Text generation (Ollama style) with streaming support - ✅
GET /api/tags- List available models with caching - ✅
POST /api/embeddings- Generate embeddings with batch support
✅ OpenAI Format Endpoints
- ✅
POST /v1/chat/completions- Chat completion (OpenAI style) with tool calling and multimodal - ✅
GET /v1/models- List available models with detailed metadata - ✅
POST /v1/embeddings- Generate embeddings with OpenAI compatibility
✅ Utility & Monitoring Endpoints
- ✅
GET /health- Health check with upstream status - ✅
GET /ready- Readiness check with dependency validation - ✅
GET /- Service information and available endpoints - ✅
GET /v1/version- Version information and build metadata - ✅
GET /v1/metrics- Prometheus format metrics (CPU, memory, requests)
🔄 Documentation Endpoints (Phase 5 - IN PROGRESS)
- 🔄
GET /docs- Interactive Swagger UI (production access) - 🔄
GET /redoc- ReDoc documentation interface - 🔄
GET /openapi.json- OpenAPI schema export - 🔄
GET /openapi.yaml- YAML schema export
Success Criteria
✅ Phase 1 Success Metrics (ACHIEVED)
- ✅ All core endpoints functional with basic translation
- ✅ Comprehensive test coverage (65.4% - exceeds >60% target)
- ✅ Docker deployment working (multi-architecture, Docker Hub + GHCR)
- ✅ Basic documentation complete
✅ Phase 2 Success Metrics (ACHIEVED)
- ✅ Streaming responses working for both API formats
- ✅ Error handling covers all common failure scenarios
- ✅ Performance excellent (<50ms translation overhead, better than <100ms target)
- ✅ Production logging and monitoring in place
✅ Phase 3 Success Metrics (ACHIEVED)
- ✅ Feature parity with major Ollama capabilities
- ✅ Tool calling and multimodal support working
- ✅ Production-ready deployment options (Docker Hub, GHCR, PyPI)
- ✅ Complete documentation and examples
✅ Phase 4 Success Metrics (ACHIEVED - Beyond Original Scope)
- ✅ Advanced metrics system with Prometheus format support
- ✅ Enterprise-grade error handling with custom exception hierarchy
- ✅ Production middleware stack with comprehensive logging
- ✅ Version management and API versioning system
- ✅ Advanced request processing and validation
🔄 Phase 5 Success Metrics (IN PROGRESS - Documentation Enhancement)
- 🔄 Production-accessible Swagger/OpenAPI documentation
- 🔄 Complete API reference with examples and error codes
- 🔄 Developer onboarding time reduced by 50%
- 🔄 Schema export functionality for CI/CD integration
- 🔄 Multi-language code samples and integration guides
Quality Requirements
✅ Performance (ACHIEVED - Exceeds Targets)
- ✅ Translation overhead: <50ms for non-streaming requests (target met)
- ✅ Memory usage: ~50MB base memory footprint (better than <100MB target)
- ✅ Concurrent connections: Supports 100+ simultaneous requests with connection pooling
- ✅ Streaming latency: <10ms first token time overhead (target met)
- ✅ Advanced metrics: CPU, memory, and disk usage monitoring
✅ Reliability (ACHIEVED - Production Grade)
- ✅ Uptime: 99.9% availability target with health checks
- ✅ Error recovery: Comprehensive graceful handling of upstream failures
- ✅ Retry logic: Exponential backoff with jitter and configurable timeouts
- ✅ Timeouts: Fully configurable with intelligent defaults
- ✅ Circuit breaker: Advanced failure detection and recovery
✅ Security (ACHIEVED - Enterprise Standards)
- ✅ Input validation: Comprehensive request sanitization with Pydantic
- ✅ API key handling: Secure forwarding with no logging exposure
- ✅ SSL/TLS: Full certificate handling and HTTPS support
- ✅ CORS: Configurable cross-origin support with security headers
- ✅ Security scanning: Integrated Trivy, Bandit, and TruffleHog scanning
✅ Maintainability (ACHIEVED - High Standards)
- ✅ Test coverage: 65.4% overall (exceeds >60% target), >90% for core translation logic
- ✅ Code quality: Full type hints, ruff linting, black formatting, mypy type checking
- ✅ Documentation: Comprehensive API docs, deployment guides, extensive examples
- ✅ Monitoring: Advanced structured logging, detailed health checks, Prometheus metrics
- ✅ CI/CD: Complete GitHub Actions pipeline with automated testing and deployment
🔄 Developer Experience (IN PROGRESS - Phase 5)
- 🔄 API Documentation: Production-accessible Swagger/OpenAPI documentation
- 🔄 Integration Examples: Multi-language code samples and framework integrations
- 🔄 Schema Export: JSON/YAML schema export for automated tooling
- 🔄 Developer Onboarding: Streamlined getting-started experience
Implementation Guidelines
Development Principles
- Simplicity First: Keep architecture simple and maintainable
- Test-Driven: Write tests before implementation
- Configuration-Driven: Avoid hardcoded values
- Error-Friendly: Provide clear error messages
- Performance-Conscious: Optimize for low latency
- Security-Aware: Validate all inputs, handle secrets properly
✅ Code Organization (CURRENT STRUCTURE)
ollama_openai/
├── src/ # Main application source
│ ├── main.py # FastAPI app with production setup
│ ├── config.py # Pydantic Settings configuration
│ ├── models.py # Comprehensive Pydantic models
│ ├── _version.py # Version management and metadata
│ ├── routers/ # API endpoint handlers
│ │ ├── chat.py # Chat and generation endpoints
│ │ ├── models.py # Model listing endpoints
│ │ ├── embeddings.py # Embeddings endpoints
│ │ ├── metrics.py # Metrics and monitoring
│ │ └── version.py # Version information
│ ├── translators/ # Format translation logic
│ │ ├── base.py # Base translation interfaces
│ │ ├── chat.py # Chat format translation
│ │ └── embeddings.py # Embeddings translation
│ ├── middleware/ # Request processing middleware
│ │ ├── error_handler.py # Global error handling
│ │ ├── logging_middleware.py # Structured logging
│ │ └── metrics_middleware.py # Performance tracking
│ └── utils/ # Shared utilities
│ ├── exceptions.py # Custom exception hierarchy
│ ├── http_client.py # Advanced HTTP client
│ ├── logging.py # Logging configuration
│ ├── metrics.py # Metrics collection
│ └── request_body.py # Request processing utilities
├── tests/ # Comprehensive test suite
│ ├── unit/ # Unit tests (290+ tests)
│ │ ├── routers/ # Router-specific tests
│ │ ├── translators/ # Translation logic tests
│ │ └── utils/ # Utility function tests
│ ├── performance/ # Performance and load tests
│ └── test_docker.py # Docker integration tests
├── docs/ # Comprehensive documentation
│ ├── QUICK_START.md # Getting started guide
│ ├── CONFIGURATION.md # Configuration reference
│ ├── API_COMPATIBILITY.md # API compatibility matrix
│ ├── TESTING.md # Testing documentation
│ └── SECURITY.md # Security guidelines
├── docker/ # Docker configurations
│ ├── Dockerfile.prod # Production Dockerfile
│ ├── docker-compose.*.yml # Various deployment configs
│ └── build.sh # Build automation
├── examples/ # Usage examples
│ ├── python/ # Python SDK examples
│ ├── javascript/ # JavaScript examples
│ └── phase2/ # Advanced feature examples
├── pyproject.toml # Python project configuration
├── Makefile # Development automation (50+ commands)
└── ARCHITECTURE.md # System architecture documentation
✅ Quality Gates (IMPLEMENTED)
- ✅ All tests must pass before merge (290+ tests)
- ✅ Code coverage must not decrease (currently 65.4%, minimum 10%)
- ✅ Linting and formatting checks must pass (ruff, black, mypy)
- ✅ Security scan must pass (Trivy, Bandit, TruffleHog)
- ✅ Docker build must succeed (multi-architecture builds)
- ✅ Performance benchmarks must meet thresholds
- ✅ Documentation must be updated for new features
✅ Current Development Practices (v0.6.8)
- Automated CI/CD: Complete GitHub Actions pipeline
- Multi-Architecture Builds: AMD64 and ARM64 Docker images
- Package Distribution: PyPI package with semantic versioning
- Container Registries: Docker Hub and GitHub Container Registry
- Test Coverage: Comprehensive unit, integration, and performance tests
- Security Scanning: Automated vulnerability detection
- Code Quality: Enforced linting, formatting, and type checking
Conclusion
This PRD documents the successful completion of a production-ready Ollama-OpenAI proxy service that has exceeded all original requirements. The service now provides:
✅ Achieved Goals (Phases 1-4 Complete)
- Seamless Integration: Zero-code migration for existing Ollama applications
- Universal Compatibility: Works with all major OpenAI-compatible backends
- Production Excellence: Enterprise-grade reliability, performance, and security
- Advanced Features: Tool calling, multimodal support, comprehensive metrics
- Developer Experience: Extensive documentation, examples, and deployment options
🔄 Current Focus (Phase 5 - Documentation Enhancement)
The primary remaining effort focuses on enhancing the developer experience through:
- Production-accessible Swagger/OpenAI documentation
- Interactive API examples and code samples
- Comprehensive error code reference
- Multi-language integration guides
Impact and Success
- 65.4% test coverage with 290+ comprehensive tests
- Multi-architecture Docker deployment on Docker Hub and GHCR
- PyPI package distribution for easy installation
- Enterprise security standards with automated vulnerability scanning
- Advanced monitoring with Prometheus metrics and structured logging
The Ollama-OpenAI Proxy has successfully transformed from a simple translation concept into a mature, enterprise-ready service that maintains simplicity while providing comprehensive functionality for production deployments.
What's inside
7 major phases, 5 success criteria sections, 4 quality requirement groups, 1 code tree, 1 configuration block, 1 endpoint list.
Change this for your project
- Replace
eyalrot/ollama_openaiwith your own repository path in all URLs and references - Replace
eyalrot2/ollama-openai-proxywith your own Docker Hub image name - Replace
OPENAI_API_BASE_URL=https://api.openai.com/v1with your actual upstream endpoint - Replace
OPENAI_API_KEY=sk-your-api-keywith your own API key
Where it goes
Keep it in your repository where the agent or team that needs it will read it.
Worth borrowing
- Phase-based PRD structure that tracks completion status (✅/🔄) for every requirement
- Separate success metrics per phase, making it easy to verify delivery
- Code tree in the PRD itself, giving a quick overview of the project layout
Related Documents
SourceAtlas PRD v2.9.6
Defines the product requirements, architecture, and command interface for an AI-powered codebase understanding assistant integrated into Claude Code.
AGENTS.md — ShakkaShell v2.0
Guides AI coding agents through building a CLI that translates natural language into offensive security commands, with a defined tech stack, structure, and implementation order.
Fleet Management System - Product Requirements Document (PRD)
Defines functional, non-functional, and technical requirements for a fleet management system with compressed GPS tracking and predictive maintenance.
TracePerf - Advanced Console Logging & Performance Tracking
Defines a Node.js logging library with execution flow tracing, performance bottleneck detection, and conditional log modes for dev/staging/prod.