How nidjbs/go-ai-gateway works
go-ai-gateway is an OpenAI-compatible gateway that authenticates client requests, applies limits and optional guardrails, routes model aliases to upstream providers, and records outcomes. The gateway handlers own request execution, including retries and failover; provider adapters handle upstream protocols. A separate operational surface exposes administration and observability, while the documented gw CLI provides a local HTTP client for chat, agent commands, and scheduling. Relationships among unsampled subsystems are included only where documented; some internal wiring remains unverified.
Main entry points: handlers.go API handlers · server.go HTTP server · executor.go Retry and failover · main.go gw CLI
Components 23
Gateway API
- API handlers
internal/gateway/handlers.go - Authentication
internal/auth/auth.go - Limits and quotas
internal/ratelimit/limiter.go - Injection guardrails
internal/guardrails/middleware.go - Output DLP
internal/dlp/dlp.go - HTTP server
internal/gateway/server.go
Request Execution
- Alias routing
internal/routing/router.go - Retry and failover
internal/retry/executor.go - Circuit breaker
internal/circuitbreaker/breaker.go - OpenAI adapter
internal/provider/openai.go - Anthropic adapter
internal/provider/anthropic.go - Plugin framework
internal/plugin/plugin.go
Operations
- Usage records
internal/usage/usage.go - SQLite usage store
internal/usage/sqlite_driver.go - Key revocation
internal/revocation/revocation.go - Prometheus metrics
internal/metrics/metrics.go - OpenTelemetry tracing
internal/tracing/tracing.go
CLI Client
- gw CLI
cli/main.go - Agent REPL
cli/repl.go - Task scheduler
cli/schedule.go
Other components
- AI clients
- Model providers
- CLI user
Connections 23
- AI clients → API handlers: sends API requests
README.md - HTTP server → API handlers: routes requests
internal/gateway/server.go - API handlers → Authentication: checks identity
internal/gateway/handlers.go - API handlers → Limits and quotas: checks quotas
internal/gateway/handlers.go - HTTP server → Injection guardrails: installs middleware
internal/gateway/server.go - API handlers → Output DLP: masks output
internal/gateway/handlers.go - API handlers → Plugin framework: runs plugins
internal/gateway/handlers.go - API handlers → Alias routing: resolves aliases
internal/gateway/handlers.go - API handlers → Retry and failover: executes attempts
internal/gateway/handlers.go - Retry and failover → Circuit breaker: checks breaker
internal/retry/executor.go - Retry and failover → OpenAI adapter: invokes adapter
- Retry and failover → Anthropic adapter: invokes adapter
- OpenAI adapter → Model providers: calls provider
- Anthropic adapter → Model providers: calls provider
- API handlers → Usage records: records usage
internal/gateway/handlers.go - Usage records → SQLite usage store: persists records
- HTTP server → Key revocation: configures revocation
- HTTP server → Prometheus metrics: serves metrics
internal/gateway/server.go - HTTP server → OpenTelemetry tracing: enables tracing
- CLI user → gw CLI: runs commands
README.md - gw CLI → API handlers: calls gateway API
README.md - gw CLI → Agent REPL: starts REPL
- gw CLI → Task scheduler: manages schedules