AI Card Bao DASH.AICARDBAO.COM
Home / 开源 / Aether Gateway
AI TOOL / #12831

Aether Gateway

A self-hosted, OpenAI-compatible LLM gateway (written in Java/Spring Boot, licensed under MIT), featuring failover mechanisms, caching capabilities, quota management, and cost tracking.

Introduction

One self-hosted endpoint in front of all your LLM providers, speaking both the OpenAI and the Anthropic API, with failover, caching, quotas, PII redaction and per-request cost tracking built in.

Free and open source (MIT). Java 25 / Spring Boot 4.1.

▶ Watch the 70-second demo

Documentation: setup guide, usage guide, architecture decision records and design docs.

Who it's for

  • Teams that want one OpenAI-compatible endpoint across Ollama, Groq, Gemini, Anthropic, OpenAI and any other OpenAI-compatible provider, without changing application code when a provider changes or goes down.
  • Teams that need to self-host the gateway, keeping prompts, keys and the request log on their own infrastructure.
  • JVM and Spring shops in particular, who want a gateway they can read, debug, extend and run with tooling they already know.

Quickstart

Try it in one container

Lite mode runs the whole gateway in a single container: no Postgres, no Redis, no model download.

docker run -p 8080:8080 -e AETHER_LITE_BOOTSTRAP_API_KEY=aeth_try_me ashishvaghelaa/aether-gateway-proxy:lite
# or, from a checkout: docker compose -f docker-compose.lite.yml up --build   (key: aeth_lite_local_dev_key)

curl -sS -D - http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer aeth_try_me" -H "Content-Type: application/json" \
  -d '{"model":"echo","messages":[{"role":"user","content":"hello"}]}'
# "Echo: hello" with X-Aether-Cache: MISS. Send it again: X-Aether-Cache: EXACT_HIT

The echo model answers in-process, so you need no provider key. Add -e OPENAI_API_KEY=... (or GEMINI_API_KEY, ANTHROPIC_API_KEY) and use the gpt, gemini or claude model aliases for real providers.

Lite mode is single-replica and caching is exact-match only. By default it is not durable: API keys, prompts, the request log and budgets reset on restart. Set AETHER_LITE_DATA_DIR to a mounted volume (as docker-compose.lite.yml does) to persist them to an embedded SQLite file. See lite mode for the full support matrix. :lite is published with each release; :edge-lite tracks trunk.

The full stack

docker compose up -d
# First run builds the images and downloads the embedding model; give it a minute, then:
curl -X POST http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"mock","messages":[{"role":"user","content":"hello"}]}'

That brings up the gateway, Postgres + pgvector, Redis, two mock providers (so you can test failover without a real outage), Prometheus, and Grafana with a pre-built dashboard at http://localhost:3000. You don't need any provider keys to try it.

Then point any OpenAI SDK at http://localhost:8080/v1.

Python

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8080/v1", api_key="local-dev")
reply = client.chat.completions.create(
    model="mock",
    messages=[{"role": "user", "content": "What is 2+2?"}],
)
print(reply.choices[0].message.content)

TypeScript

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "http://localhost:8080/v1", apiKey: "local-dev" });
const reply = await client.chat.completions.create({
  model: "mock",
  messages: [{ role: "user", content: "What is 2+2?" }],
});
console.log(reply.choices[0].message.content);

The Compose stack allows anonymous requests so the quickstart works without creating a key first. Outside local development, create real API keys through the admin API. Anonymous access is off by default and in the Kubernetes manifests. To use real providers, set their keys (for example OPENAI_API_KEY or GEMINI_API_KEY) in your shell or a root .env file and use the gpt or gemini model aliases from routing.docker.yaml.

What you get back

Every response includes headers that show what the gateway did. This output was captured from the Compose stack:

$ curl -sS -D - http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" \
    -d '{"model":"mock","messages":[{"role":"user","content":"What is 2+2?"}]}'
HTTP/1.1 200 OK
X-Aether-Cache: MISS
X-Aether-Cost-USD: 0.0000195
X-Aether-Attempts: 1
X-Aether-Provider: mock-primary

# Same prompt again: served from the exact-match cache, no provider call, no cost
X-Aether-Cache: EXACT_HIT
X-Aether-Cost-USD: 0

# Make the primary provider fail, then send a new prompt.
# The gateway fails over to the fallback. The client changes nothing.
$ curl -sS -X POST http://localhost:8082/_mock/config \
    -H "Content-Type: application/json" -d '{"fail_mode":"503","fail_rate":1.0}'
X-Aether-Cache: MISS
X-Aether-Attempts: 1
X-Aether-Provider: mock-fallback

The aether CLI

A command-line client for the admin API (see docs/cli.md):

cd aether-gateway && ./gradlew :gateway-cli:fatJar
export AETHER_URL=http://localhost:8080 AETHER_ADMIN_TOKEN=your-admin-key
alias aether="$PWD/gateway-cli/bin/aether"

KEY=$(aether keys create --name ci)
aether cost report --since 7d --group-by provider
aether tail --model gpt
aether claude-code setup --key "$KEY" --dry-run   # optional: send Claude Code traffic through the gateway

Features

  • Multi-provider failover. Each model alias maps to an ordered chain of providers. Circuit breakers, retries and bulkheads (resilience4j) move traffic to the next healthy provider. Failover took 67.92 ms at p99 over 100 independent injected outages.
  • Exact-match response caching. Repeated identical requests are answered from Redis, with Postgres behind it, and cost nothing. Each API key has its own cache namespace, and caching is skipped for requests with temperature > 0.3, requests with tools, and any request that sends X-Aether-No-Cache. If the cache fails, requests go straight to the provider (fail-open).
  • Quotas and rate limits per API key. Monthly token budgets, rate limits and concurrency caps, enforced atomically in Redis. Tokens are reserved before the request and reconciled to the real count afterwards. If quota enforcement fails, requests are rejected rather than let through unmetered (fail-closed).
  • Cost on every response. X-Aether-Cost-USD, X-Aether-Provider, X-Aether-Attempts, X-Aether-Failover-Chain and X-Aether-Quota-Remaining headers. Prices come from a hot-reloadable cost-model.yaml.
  • Streaming with cancellation. SSE in the same format as OpenAI's. When a client disconnects, the gateway cancels the upstream request, so you stop paying for tokens nobody will read.
  • Observability. Micrometer/Prometheus metrics and a pre-built Grafana dashboard covering latency by provider, cache hit rate, spend and spend avoided, breaker state, in-flight streams, top keys by cost, and errors. There is also a per-request log you can query.
  • Operator console and admin API. Manage API keys (stored as salted hashes), a versioned prompt registry, cache stats and the request explorer. See console/README.md.
  • Kubernetes-ready. Plain manifests in k8s/ with a PodDisruptionBudget, a NetworkPolicy and graceful SSE draining. In two real rolling updates, all 1,000 in-flight streams (500 per rollout) finished without a break.
  • Hot-reloadable routing. Edit routing.yaml and POST /admin/routes/reload applies it without a restart. Provider credentials are referenced by environment variable *name*, so the config file is safe to commit. Provider base URLs are checked against private network ranges (SSRF protection).
  • Tool calling. OpenAI-format tools, tool_choice, assistant tool_calls and tool results pass through end to end, streaming included (delta.tool_calls). Passed through unchanged to OpenAI-compatible providers, and translated to and from Anthropic's Messages API, Gemini's function calling (with JSON Schema converted to Gemini's subset) and Ollama's native /api/chat. Ollama can't force a tool call, so tool_choice: "required" or a named function gets a clear 400 tool_choice_not_supported instead of being silently ignored. Tool-calling traffic is never cached.
  • Reversible PII redaction. Per API key, emails, phone numbers, cards (Luhn), IBANs (mod-97), SSNs, IP addresses and common secrets are swapped for placeholders like [EMAIL_1] before any provider sees them, then restored in the response, streaming included. Modes: off, redact, mask, block, with per-category toggles. See usage and ADR-012.
  • Embeddings. OpenAI-compatible POST /v1/embeddings with the same auth, quotas, failover and cost headers as chat. Supported on OpenAI-compatible providers, Ollama and Gemini. Providers without embeddings support are skipped in the chain.
  • Provider adapters. OpenAI, Anthropic, Gemini, Groq, Ollama, AWS Bedrock and Google Vertex AI (Anthropic models), and a generic adapter for anything that speaks the OpenAI format (LiteLLM, vLLM, TGI, and so on). When the same model is offered by more than one platform, one alias can fail over between them; see the cross-cloud example.
  • Two client APIs, one pipeline. Clients can call the OpenAI-compatible /v1/chat/completions or the Anthropic-compatible /v1/messages (streaming and count_tokens included). Both go through the same routing, failover, quotas, caching and cost headers, and either can be served by any provider in the chain.
  • Provider prompt caching and extended thinking. cache_control markers and thinking / reasoning_effort are passed to providers that support them (Anthropic, Bedrock and Vertex today). Cache reads and writes are priced separately, and cache savings show up in headers and metrics.
  • Agent sessions and runaway guards. Tag requests with X-Aether-Session-Id to see an agent run's total cost, turns and timeline, and cap a session's spend, turns and tokens. Repeated identical tool calls are rejected as a loop.
  • OpenTelemetry GenAI tracing. Spans and histograms that follow the OpenTelemetry GenAI semantic conventions, exported over OTLP when configured, with per-attempt child spans.
  • Budget forecasts and alerts. Month-end spend projections per key, and webhook or Slack alerts at budget thresholds.
  • Command-line client. The aether CLI manages keys, reloads routes, reports cost and follows the request log.

Semantic cache (experimental)

The gateway can also return a cached answer for a prompt that is *similar* to an earlier one. It embeds the prompt (all-MiniLM-L6-v2, running in-process), searches pgvector for near neighbours, and then applies a guard that rejects a match when the numbers, units, dates, named entities, negation or a small set of common opposites ("open"/"closed", "increased"/"decreased") differ.

It is not yet accurate enough to recommend for answers that need to be correct. On a 502-prompt hand-labelled corpus at the default 0.94 threshold with the guard on:

Measured
Hit rate14.47% (11 of 76 paraphrase pairs)
False-hit rate (a wrong cached answer served)0.0% (0 of 50 adversarial pairs), in-sample

Treat that 0% with suspicion. The guard's negation, spelled-out-number, unit and opposites checks were written after reading which of these 50 pairs got through, so it fits this corpus by construction. On 20 new adversarial pairs written after the guard was frozen, it rejected only 6. Opposites outside its short word list ("faster" vs "slower", "fixed" vs "variable" rate) and meaning-bearing common nouns ("finance team" vs "legal team") still pass. Semantic cache correctness covers the full analysis.

Semantic matching is opt-in per route. Exact-only caching is semantic: false in a route's cache: block in routing.yaml; the shipped example configs use it, so out of the box only identical requests are served from cache. (A cache: block that omits semantic keeps the older behaviour, exact plus semantic, so existing configs are unchanged.) Clients can raise the similarity threshold for a request with X-Aether-Cache-Threshold, but never lower it below the route's configured value. See Routing policy.

How it compares

LiteLLM and Portkey are mature, widely used gateways with much broader provider coverage. If you want the widest set of integrations today, start there. Aether is aimed at teams that want a small, readable JVM codebase with published, reproducible measurements of its own behaviour.

Aether GatewayLiteLLM ProxyPortkey AI Gateway
Self-hostedYesYesYes (managed service also available)
Language / runtimeJava 25, JVMPythonTypeScript, Node.js
LicenseMITMIT for the open-source core; enterprise features licensed separatelyMIT
Provider coverage5 native adapters + any OpenAI-compatible APIVery broadVery broad
Reproducible benchmarks committed in the repoYes: BENCHMARKS.md, raw CSVs, make benchNot assessed hereNot assessed here

Competitor details may change. Check their own docs before you decide.

Benchmarks

Every number below comes from a committed run. The full tables, methodology, caveats and raw CSVs are in BENCHMARKS.md, and you can reproduce them with make bench.

MetricResultTarget
Gateway overhead on a cache miss, p956.24 ms< 15 ms
Cache-hit end-to-end latency, p958.9 ms< 50 ms
Failover latency, p99 (100 independent trials)67.92 ms< 500 ms
Quota accuracy, 100 concurrent requests0 over-issue0
Broken streams during rolling K8s update0 of 1,0000
Semantic cache hit rate (0.94 threshold, guard on)14.47%≥ 35% (not met)
Semantic cache false-hit rate0.0% on the labelled corpus (in-sample; 6 of 20 new adversarial pairs caught)≤ 5% (not shown out of sample)
Concurrent streams on 2 vCPU / 4 GB37.1% failures at 2,000≥ 2,000 (not met)

Architecture

flowchart TB
    Client["OpenAI-compatible client SDK
(baseUrl override)"]

    subgraph Gateway["Aether Gateway"]
        direction TB
        AuthN["1. AuthN
API key to KeyCtx"]
        Quota["2. Quota
Redis token bucket, Lua, atomic"]
        Prompt["3. Prompt resolution
registry, versioned"]
        Cache["4. Semantic cache lookup
embed to ANN to threshold"]
        Router["5. Router
policy to provider chain"]
        Resilience["6. Resilience
breaker / retry / bulkhead"]
        Adapter["7. Provider adapter
normalise req/resp"]
        Stream["8. Stream pump
SSE relay + cancellation"]
        Accounting["9. Accounting (async)
tokens, cost, cache write"]

        AuthN --> Quota --> Prompt --> Cache --> Router --> Resilience --> Adapter --> Stream --> Accounting
    end

    Redis[("Redis
quotas, breaker hints")]
    Postgres[("Postgres + pgvector
cache, logs, registry")]
    Ollama["Ollama (local)"]
    Groq["Groq"]
    Gemini["Gemini"]
    Mock["MockProvider
(fault injection)"]

    Client --> AuthN
    Quota  Redis
    Cache  Postgres
    Adapter --> Ollama
    Adapter --> Groq
    Adapter --> Gemini
    Adapter --> Mock

    Accounting --> Micrometer["Micrometer / OTel"]

The core follows a hexagonal (ports and adapters) layout. gateway-core depends only on the JDK, and ArchUnit tests enforce that. See the architecture diagram and module boundaries.

<
Visits:4 Updated:2026-12-03 AI tools

Related