{"id":45653622,"url":"https://github.com/xraph/nexus","last_synced_at":"2026-06-01T14:00:41.345Z","repository":{"id":339973832,"uuid":"1163772671","full_name":"xraph/nexus","owner":"xraph","description":"Composable AI gateway library for Go. Route, cache, guard, and observe LLM traffic at scale.","archived":false,"fork":false,"pushed_at":"2026-05-14T16:37:03.000Z","size":16611,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-14T18:07:15.812Z","etag":null,"topics":["ai","ai-gateway"],"latest_commit_sha":null,"homepage":"https://nexus.xraph.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xraph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":"audit_hook/events.go","citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-22T05:44:17.000Z","updated_at":"2026-05-14T16:34:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/xraph/nexus","commit_stats":null,"previous_names":["xraph/nexus"],"tags_count":193,"template":false,"template_full_name":null,"purl":"pkg:github/xraph/nexus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Fnexus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Fnexus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Fnexus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Fnexus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xraph","download_url":"https://codeload.github.com/xraph/nexus/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xraph%2Fnexus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33777971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","ai-gateway"],"created_at":"2026-02-24T07:23:45.646Z","updated_at":"2026-06-01T14:00:41.339Z","avatar_url":"https://github.com/xraph.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nexus\n\nComposable AI gateway library for Go. Route, cache, guard, and observe LLM traffic at scale.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/xraph/nexus.svg)](https://pkg.go.dev/github.com/xraph/nexus)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/xraph/nexus)](https://go.dev)\n\n---\n\nNexus is a **library**, not a SaaS. Import it, compose your AI gateway, and own your infrastructure. You bring your own providers, database, and HTTP server — Nexus provides the gateway orchestration plumbing.\n\n## Features\n\n**Multi-Provider Routing** — Route to OpenAI, Anthropic, or any OpenAI-compatible API. Priority, cost-optimized, round-robin, and latency-based strategies.\n\n**Content Guardrails** — PII detection, prompt injection blocking, and content filtering with block/redact/warn actions.\n\n**Response Caching** — Deterministic cache keys with optional semantic matching. Memory and Redis backends.\n\n**Multi-Tenant Isolation** — Tenant-scoped requests, API keys, rate limits, usage tracking, budget enforcement, and per-tenant model aliases.\n\n**Model Aliases** — Map virtual model names to provider targets with per-tenant overrides and weighted routing.\n\n**Input/Output Transforms** — System prompt injection, RAG context augmentation, data anonymization, and output normalization.\n\n**Plugin System** — 15 lifecycle hooks for metrics, audit trails, webhooks, and custom processing.\n\n**OpenAI-Compatible Proxy** — Drop-in replacement for the OpenAI API. Point any SDK at your gateway.\n\n**Versatile Streaming** — Reasoning deltas, tool-call streaming, multi-modal chunks, and four pluggable wire formats: SSE (OpenAI envelope), nexus-native SSE with named events, NDJSON, and a bidirectional WebSocket endpoint at `/v1/realtime`. Channel-based Go API, idempotent record-and-replay caching, and lifecycle hooks for stream observability.\n\n**Three Storage Backends** — PostgreSQL, SQLite, and in-memory.\n\n**Forge Integration** — Drop-in `forge.Extension` with auto-discovery and DI-registered Gateway.\n\n## Quick Start\n\n```bash\ngo get github.com/xraph/nexus\n```\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n    \"os\"\n\n    \"github.com/xraph/nexus\"\n    \"github.com/xraph/nexus/cache/stores\"\n    \"github.com/xraph/nexus/guard/guards\"\n    \"github.com/xraph/nexus/model\"\n    \"github.com/xraph/nexus/provider\"\n    \"github.com/xraph/nexus/providers/openai\"\n    \"github.com/xraph/nexus/router/strategies\"\n)\n\nfunc main() {\n    gw := nexus.New(\n        nexus.WithProvider(openai.New(os.Getenv(\"OPENAI_API_KEY\"))),\n        nexus.WithRouter(strategies.NewCostOptimized()),\n        nexus.WithCache(stores.NewMemory()),\n        nexus.WithGuard(guards.NewPII(\"redact\")),\n        nexus.WithAlias(\"fast\", model.AliasTarget{\n            Provider: \"openai\",\n            Model:    \"gpt-4o-mini\",\n        }),\n    )\n\n    ctx := context.Background()\n    if err := gw.Initialize(ctx); err != nil {\n        log.Fatal(err)\n    }\n    defer gw.Shutdown(ctx)\n\n    resp, err := gw.Engine().Complete(ctx, \u0026provider.CompletionRequest{\n        Model:    \"fast\",\n        Messages: []provider.Message{{Role: \"user\", Content: \"Hello!\"}},\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    fmt.Println(resp.Choices[0].Message.Content)\n}\n```\n\n## Examples\n\n| Example | Description |\n|---------|-------------|\n| [`_examples/standalone`](./_examples/standalone) | Standalone gateway — no framework, just Go |\n| [`_examples/proxy`](./_examples/proxy) | OpenAI-compatible proxy with SSE/NDJSON/WS + stream cache + metrics |\n| [`_examples/streaming`](./_examples/streaming) | Streaming completions via iterator, channel, and accumulator APIs |\n| [`_examples/multi-tenant`](./_examples/multi-tenant) | Multi-tenant with API keys and usage tracking |\n| [`_examples/forge`](./_examples/forge) | Integration with the Forge framework |\n\n## Architecture\n\nEvery request flows through a priority-sorted middleware pipeline:\n\n```\nRequest\n  │\n  ├─ Tracing         (priority 10)\n  ├─ Timeout          (priority 20)\n  ├─ Guardrails       (priority 150)\n  ├─ Transforms       (priority 200)\n  ├─ Alias Resolution (priority 250)\n  ├─ Cache            (priority 280)\n  ├─ Retry            (priority 340)\n  ├─ Provider Call    (priority 350)   ← core routing + LLM call\n  ├─ Headers          (priority 500)\n  └─ Usage Tracking   (priority 550)\n  │\nResponse\n```\n\nMiddleware is added or removed via functional options. The pipeline is assembled at `Initialize()` time.\n\n### Design Principles\n\n- **Library, not service.** You control `main`, the database, and the process lifecycle.\n- **Interfaces over implementations.** Every subsystem defines a Go interface. Swap any component with a single type change.\n- **Tenant-scoped by design.** Context-injected tenant isolation enforced at every layer.\n- **Pipeline-driven.** Priority-sorted middleware chain — add, remove, or reorder without touching engine code.\n\n## Plugin System\n\nExtensions implement one or more hook interfaces and are registered at gateway creation:\n\n```go\nnexus.New(\n    nexus.WithExtension(myAuditPlugin),\n)\n```\n\n| Category | Hooks |\n|----------|-------|\n| **Request** | `OnRequestReceived`, `OnRequestCompleted`, `OnRequestFailed`, `OnRequestCached` |\n| **Stream** | `OnStreamStarted`, `OnChunkReceived`, `OnStreamCompleted`, `OnStreamFailed` |\n| **Provider** | `OnProviderFailed`, `OnCircuitOpened`, `OnFallbackTriggered` |\n| **Guardrail** | `OnGuardrailBlocked`, `OnGuardrailRedacted` |\n| **Tenant** | `OnTenantCreated`, `OnTenantDisabled` |\n| **Key** | `OnKeyCreated`, `OnKeyRevoked` |\n| **Budget** | `OnBudgetWarning`, `OnBudgetExceeded` |\n\nThe registry type-caches hooks at registration time — emit calls iterate only over extensions that implement the relevant interface.\n\n## Documentation\n\nFull documentation is available at [nexus.xraph.com](https://nexus.xraph.com).\n\n## Contributing\n\nContributions are welcome. Please open an issue to discuss larger changes before submitting a PR.\n\n```bash\n# Run tests\ngo test ./...\n\n# Lint\ngolangci-lint run ./...\n\n# Build docs\ncd docs \u0026\u0026 pnpm install \u0026\u0026 pnpm dev\n```\n\n## License\n\nSee [LICENSE](./LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxraph%2Fnexus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxraph%2Fnexus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxraph%2Fnexus/lists"}