Relay is a reverse proxy for LLM APIs written in Go. It routes requests to different LLM providers (OpenAI, Anthropic) based on URL path prefix. Module path: github.com/mallikarjunabr/relay.
main.go— Entry point, flag parsing, mux setup, logging middleware, HTTP serverconfig.go— YAML config types and loader with env var expansionproxy.go— Reverse proxy factory usingnet/http/httputil.ReverseProxyconfig.yaml.example— Reference config (realconfig.yamlis gitignored)
- Go version: 1.24+
- Build:
go build -o relay . - Run:
go run . -config config.yaml - Test:
go test ./... - Dependencies:
gopkg.in/yaml.v3
- Extract logic into small, well-named functions — no inline comments
- Function names should be readable and self-explanatory
- No comments in code; if something needs a comment, rename or refactor instead
- Always add tests when adding or changing functionality
- Single
package main, no sub-packages httputil.ReverseProxywithFlushInterval: -1handles streaming/SSE natively- API keys injected from config only if the client doesn't send their own auth header
os.ExpandEnvon raw YAML enables${ENV_VAR}syntax in config