Nexus AI Gateway
Route requests across multiple AI providers, cache responses, enforce guardrails, stream completions, and manage model aliases — composable, plugin-extensible, and built for production Go services.
go get github.com/xraph/nexusEverything you need for AI gateway
Nexus handles the hard parts — routing, caching, guardrails, multi-tenancy, and model management — so you can focus on your application.
Multi-Provider Routing
Route to OpenAI, Anthropic, or any OpenAI-compatible API. Priority, cost-optimized, and round-robin strategies.
gw := nexus.New( nexus.WithProvider(openai.New(apiKey)), nexus.WithProvider(anthropic.New(apiKey)), nexus.WithRouter(strategies.CostOptimized()),)Content Guardrails
PII detection, prompt injection, content filtering. Pre and post-processing guards with block, redact, and warn actions.
nexus.WithGuard(guards.PII(guards.ActionRedact)),nexus.WithGuard(guards.ContentFilter()),nexus.WithGuard(guards.PromptInjection()),Multi-Tenant Isolation
Every request is scoped to a tenant via context. API keys, rate limits, usage tracking, and model aliases per tenant.
ctx = nexus.WithTenant(ctx, "tenant-1") "text-fd-muted-foreground/60 italic">// All requests, usage, and rate limits"text-fd-muted-foreground/60 italic">// scoped to tenant-1 automaticallyPluggable Store Backends
Start with in-memory for development, swap to SQLite or PostgreSQL for production. Every subsystem is a Go interface.
gw := nexus.New( nexus.WithDatabase(postgres.New(pool)), nexus.WithCache(stores.NewRedis(rdb)),)"text-fd-muted-foreground/60 italic">// Also: memory.New(), sqlite.New(db)Model Aliases & Transforms
Map virtual model names to provider targets. Apply input/output transforms, system prompt injection, and RAG context.
nexus.WithAlias("fast", model.AliasTarget{Provider: "anthropic", Model: "claude-3.5-haiku"},)"text-fd-muted-foreground/60 italic">// Clients request model: "fast"OpenAI-Compatible Proxy
Drop-in replacement for the OpenAI API. Point any SDK at your nexus instance and get routing, caching, guardrails, and multi-tenancy for free.
proxy := proxy.New(gw)http.ListenAndServe(":8080", proxy)"text-fd-muted-foreground/60 italic">// Any OpenAI SDK can connect to"text-fd-muted-foreground/60 italic">// localhost:8080/v1/chat/completionsFrom request to response, fully orchestrated.
Nexus orchestrates the entire request lifecycle — tenant isolation, guardrail enforcement, intelligent routing, response caching, and usage tracking.
15 Plugin Lifecycle Hooks
RequestReceived, ProviderFailed, GuardrailBlocked, and 12 more. Wire metrics, audit trails, or custom processing logic without modifying engine code.
Intelligent Routing
Priority, cost-optimized, and round-robin strategies with automatic fallback and circuit breaking across multiple providers.
Response Caching
Deterministic cache keys with optional semantic matching. Memory, Redis, or custom cache backends. Cache hits skip provider calls entirely.
Simple API. Powerful gateway.
Configure providers and route requests in under 20 lines. Nexus handles the rest.
1package main2 3import (4 "context"5 "os"6 7 "github.com/xraph/nexus"8 "github.com/xraph/nexus/model"9 "github.com/xraph/nexus/providers/openai"10 "github.com/xraph/nexus/providers/anthropic"11 "github.com/xraph/nexus/store/memory"12)13 14func main() {15 gw := nexus.New(16 nexus.WithDatabase(memory.New()),17 nexus.WithProvider(openai.New(18 os.Getenv("OPENAI_KEY"))),19 nexus.WithProvider(anthropic.New(20 os.Getenv("ANTHROPIC_KEY"))),21 nexus.WithAlias("fast", model.AliasTarget{22 Provider: "anthropic",23 Model: "claude-3.5-haiku",24 }),25 )26 27 gw.Initialize(context.Background())28}1package main2 3import (4 "context"5 "fmt"6 7 "github.com/xraph/nexus"8 "github.com/xraph/nexus/provider"9)10 11func complete(12 engine *nexus.Engine,13 ctx context.Context,14) {15 ctx = nexus.WithTenant(ctx, "tenant-1")16 17 resp, _ := engine.Complete(ctx,18 &provider.CompletionRequest{19 Model: "fast", "text-fd-muted-foreground/60 italic">// resolves via alias20 Messages: []provider.Message{{21 Role: "user",22 Content: "What is Go?",23 }},24 })25 26 fmt.Println(resp.Choices[0].Message.Content)27 "text-fd-muted-foreground/60 italic">// "Go is a compiled programming language..."28}Start building with Nexus
Add production-grade AI gateway capabilities to your Go service in minutes. Nexus handles routing, caching, guardrails, and multi-tenancy out of the box.
go get github.com/xraph/nexus