Minimal Ruby OpenAI proxy focused on the core pieces required to replace LiteLLM for OpenAI-only routing.
Supported use case: transparent OpenAI proxying with MySQL-backed project and token storage, Redis for hot-path caching and async usage queues, off-path logging, and expiring tokens.
- OpenAI-compatible transparent proxy on
/v1/* - Project management with one OpenAI API key per project
- Short-lived token minting on
/tokens/mint - Token validation backed by MySQL with Redis hot-path caching
- Redis-backed HTTP response caching for cacheable OpenAI requests
- Usage logging shipped off the request path through Redis to CloudWatch Logs
- No admin UI and no benchmark suite
This is intentionally a minimum viable service:
- Each project stores exactly one upstream OpenAI API key
- Project API keys are encrypted at rest with AES-256-GCM
- Token records carry
project_idand free-form metadata for routing context and observability - CloudWatch shipping uses structured log events compatible with the current Go deployment shape
Not included:
- Admin UI
- Full management API beyond minimal project creation and listing
- Benchmark harness
GET /projectsPOST /projectsGET /healthPOST /tokens/mintANY /v1/*
OPENAI_PROXY_UPSTREAM_BASE_URLdefault:https://api.openai.comOPENAI_PROXY_MANAGEMENT_TOKENrequired for/projectsand/tokens/mintOPENAI_PROXY_DATABASE_URLrequired, MySQL URL for SequelOPENAI_PROXY_ENCRYPTION_KEYrequired, base64-encoded 32-byte key for encrypting stored upstream API keysOPENAI_PROXY_REDIS_URLrequiredOPENAI_PROXY_CLOUDWATCH_LOG_GROUPoptionalOPENAI_PROXY_CLOUDWATCH_LOG_STREAMoptionalOPENAI_PROXY_CLOUDWATCH_REGIONoptionalOPENAI_PROXY_USAGE_QUEUE_KEYdefault:openai_proxy:usage_events
lib/runtime codespec/RSpec coveragedocs/standalone project documentation.github/repo-local Copilot and extraction-ready CI templates
bundle install
bundle exec puma -C config/puma.rbOr:
make runBuild the image locally from the openai-proxy directory:
docker build -t openai-proxy:dev .
docker run --rm -p 8080:8080 --env-file .env openai-proxy:devBring up the full local stack with MySQL and Redis:
docker compose up --buildGitHub Actions workflows for CI and image publishing live under .github/workflows/.
Default image target:
ghcr.io/sofatutor/openai-proxy
Apply db/schema.sql to the target MySQL database before boot.
export RBENV_VERSION=3.3.9
bundle exec rspec
make lint{
"name": "search",
"api_key": "sk-live-project-key"
}{
"project_id": "<project-uuid>",
"ttl_seconds": 3600,
"metadata": {
"feature": "search",
"user_id": "123"
}
}