Overview
Anar Gateway is the foundation layer of the Anar platform. Every AI call across all 14 products flows through the Gateway for unified routing, authentication, cost tracking, and governance. Written in Go with 18 plugins including semantic caching, it adds less than 100 microseconds of overhead at 5,000 requests per second.
The Gateway exposes an OpenAI-compatible API, meaning any client or SDK that works with OpenAI works with Anar Gateway out of the box. This includes the official OpenAI Python and JavaScript SDKs, LangChain, Haystack, and any other tool that speaks the OpenAI protocol.
Key Capabilities
Multi-Provider Routing
Route requests across Azure UAE North (sovereign), Groq (fast inference), and sovereign cloud providers. The Gateway handles model mapping, API key injection, and protocol translation transparently.
Adaptive Load Balancing
EWMA-based health tracking monitors error rates and latency per provider/model pair. A 4-state machine (Healthy, Degraded, Failed, Recovering) automatically shifts traffic away from unhealthy providers with configurable thresholds and cooldown periods.
Enterprise Security
- RBAC with API key and JWT authentication, four default roles, and custom role definitions
- OIDC integration with any standards-compliant identity provider (RSA + EC key support, JWKS auto-discovery)
- Guardrails integration with Anar Guard for real-time content safety scanning
Semantic Cache
Frequently repeated queries are served from a built-in semantic cache, reducing latency and provider costs for common request patterns without any client-side changes.
Cost Tracking
Per-request cost calculation with built-in pricing for 30+ models across OpenAI, Anthropic, Google, Groq, and Azure. Token usage, costs, and tenant attribution are persisted to SQLite or PostgreSQL with batch writing for minimal performance impact.
Audit Logging
SOC2/GDPR-grade compliance event logging covering model requests, config changes, key operations, auth failures, and MCP tool executions. Events are batched (100 per flush or every 2 seconds) with automatic retention cleanup.
OpenTelemetry
Native trace export via HTTP and gRPC protocols, with Prometheus metrics endpoint for scraping. Integrates directly with the Anar observability stack (Grafana, Tempo, Loki, Prometheus).
Architecture
All plugins hook into the request lifecycle via four plugin interfaces (LLMPlugin, HTTPTransportPlugin, MCPPlugin, ObservabilityPlugin), executing pre-request and post-response logic without modifying the core routing engine.
Available Models
Azure OpenAI (UAE North)
| Model | Type |
|---|---|
gpt-4o-uaenorth | Chat |
text-embedding-3-large-uaenorth | Embedding (3072-dim) |
Groq (Fast Inference)
| Model | Type |
|---|---|
llama-3.3-70b-versatile | Chat |
allam-2-7b | Chat (Arabic, SDAIA) |
meta-llama/llama-4-scout-17b-16e-instruct | Chat |
meta-llama/llama-4-maverick-17b-128e-instruct | Chat |
meta-llama/llama-guard-4-12b | Safety |
qwen/qwen3-32b | Chat |
openai/gpt-oss-120b | Chat |
llama-3.1-8b-instant | Chat |
Sovereign Cloud (Fallback)
| Model | Type |
|---|---|
gpt-4o | Chat |
gpt-4.1 | Chat |
text-embedding-3-large | Embedding |
Quick Start
docker compose up -d gateway
Verify the gateway is running:
curl http://localhost:8080/health
Send a chat completion:
curl http://localhost:8080/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llama-3.3-70b-versatile",
"messages": [{"role": "user", "content": "Hello from Anar Gateway"}]
}'
OpenAI SDK Compatible
Any OpenAI SDK client works with the Gateway. Set the base URL to http://localhost:8080/v1 and you are ready to go. See the API Reference for SDK examples.
Integration with Anar Products
All products route AI calls through the Gateway using the standard OpenAI-compatible API:
| Product | Usage |
|---|---|
| Chat | Chat completions + embeddings for RAG |
| Guard | Proxied chat with safety scanning |
| Voice | STT via Whisper + chat for voice agents |
| Agents | Chat completions for agent reasoning |
| Eval | Model evaluation across providers |
| Docs AI | LLM-based extraction and classification |
| Flow | Chat completions for workflow AI steps |
| Insights | Chat completions for NL analytics queries |
Test Suite
The Gateway has 550 tests covering all 18 custom plugins:
| Package | Tests |
|---|---|
| Governance (health tracker, routing, budgets) | 190+ |
| Semantic Cache | 50+ |
| Guardrails | 23 |
| OIDC | 32 |
| Audit | 17 |
| RBAC | 11 |
| Object Store | 9 |
| Other plugins | 200+ |
cd gateway/src && go test ./...