A lightweight proxy service that normalizes and optimizes OpenAI-compatible API requests, enabling clients to work seamlessly with Ollama and other OpenAI-compatible APIs.
Many AI clients send requests with:
- Excessive token requests (often 200,000+ tokens)
- Inconsistent parameter formats
- Unnecessary or incompatible fields
This causes 400 errors or poor performance when connecting to OpenAI-compatible servers like Ollama.
This bridge acts as a middleware that:
- Intercepts requests from AI clients
- Normalizes request parameters
- Caps unreasonable values (token limits)
- Forwards clean OpenAI-format requests
- Returns responses clients understand
AI Client → Bridge (port 8443) → Ollama/OpenAI (your server)
↓
[Raw request]
↓
[Normalization]
↓
[OpenAI format]
- Clone and setup:
git clone <repository>
cd ollama-bridge
cp .env.example .env- Configure your target:
# Edit .env file
BRIDGE_TARGET_URL=http://host.docker.internal:11434/v1 # For local Ollama
# or
BRIDGE_TARGET_URL=https://api.openai.com/v1 # For OpenAI- Start the bridge:
docker-compose up -d- Use the bridge:
Your bridge is now running on
http://localhost:8443
Point your AI client to http://localhost:8443/v1 instead of the direct API.
| Variable | Description | Default | Example |
|---|---|---|---|
BRIDGE_TARGET_URL |
Where to forward requests | http://host.docker.internal:11434/v1 |
https://api.openai.com/v1 |
BRIDGE_DEBUG |
Enable debug logging | false |
true |
TARGET_API_KEY |
API key for target service | - | sk-your-key-here |
Local Ollama:
BRIDGE_TARGET_URL=http://host.docker.internal:11434/v1
BRIDGE_DEBUG=falseRemote Ollama:
BRIDGE_TARGET_URL=http://your-server:11434/v1
BRIDGE_DEBUG=falseOpenAI:
BRIDGE_TARGET_URL=https://api.openai.com/v1
TARGET_API_KEY=sk-your-openai-key-here
BRIDGE_DEBUG=false| Field | Action |
|---|---|
temperature |
Preserved |
max_tokens |
Capped at reasonable limit (4096 if > 100,000) |
top_p, frequency_penalty, presence_penalty |
Preserved |
stream, stop, n |
Preserved |
| Unsupported fields | Filtered out |
Input (from client):
{
"model": "llama3.1:latest",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 229018,
"temperature": 0.7
}Output (to Ollama):
{
"model": "llama3.1:latest",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 4096,
"temperature": 0.7
}Check if the bridge is running:
curl http://localhost:8443/healthExpected response:
{
"status": "healthy",
"bridge": "ollama-bridge",
"target": "http://host.docker.internal:11434/v1",
"uptime": 123.45
}Test the bridge with a simple request:
curl -X POST http://localhost:8443/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "llama3.1:latest",
"messages": [{"role": "user", "content": "Hello"}],
"temperature": 0.7
}'# In .env file
BRIDGE_DEBUG=true
# Restart container
docker-compose restart# Follow logs
docker-compose logs -f
# View recent logs
docker-compose logs --tail=50- Latency: +5-10ms per request
- Memory: ~50MB RAM usage
- Throughput: Handles concurrent requests
- Streaming: Supports Server-Sent Events (SSE)
- AI client optimization for better Ollama compatibility
- API normalization layer for consistent requests
- Development testing with different backends
- Token limiting to prevent excessive resource usage
# Build and start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose down
# Rebuild
docker-compose build --no-cache
# Shell access
docker-compose exec ollama-bridge shBridge not responding:
- Check if port 8443 is available:
netstat -tulpn | grep 8443 - Verify Docker container is running:
docker-compose ps
Connection to target fails:
- Test target URL directly:
curl $BRIDGE_TARGET_URL/models - Check network connectivity from container
- Verify API key if required
400 errors from target:
- Enable debug mode to see request transformation
- Check target API documentation for supported fields
MIT License - See LICENSE file for details