Skip to content
poleraPublic

About

waarn - Workflow Aware Agent Routing Network

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

waarn logo

waarn

Workflow Aware Agent Routing Network

waarn is an OpenAI-compatible AI gateway built with Elixir/OTP. It provides multi-provider routing, centralized access control, cost accounting, and an administrative interface for AI workloads.

Features

  • Route requests to OpenAI, Google Cloud Vertex AI, Anthropic, AWS Bedrock, and OpenRouter.
  • Automatically select models with the Jev classifier.
  • Manage virtual keys, rate limits, budgets, and upstream cost accounting.
  • Apply tenant-scoped caching and guardrails.
  • Administer organizations, teams, users, virtual keys, model deployments, routing, classifier settings, and encrypted provider credentials through a Phoenix LiveView UI.
  • Explore filtered spend analytics by organization, team, user, model, and agent harness version, with CSV downloads.

Quick start

Run the local container stack with Podman and podman-compose:

export WAARN_MASTER_KEY="$(openssl rand -hex 32)"
make up

The stack starts PostgreSQL, Valkey, database migrations, and two waarn nodes. Open the Admin UI at http://localhost:4001 and enter the master key in the Master Key or Administrator API Key field. The gateway API is available at http://localhost:4000/v1.

Run make down to stop the stack. Set CONTAINER_TOOL and COMPOSE_TOOL to use a different container runtime or Compose implementation.

Configuration

Model deployments, routing, caching, and classifier settings live in waarn.yaml. Set WAARN_CONFIG_PATH to use a different configuration file. opencode.jsonc contains a sample OpenCode client configuration.

Ports

Port Environment variable Services
4000 PORT Gateway API (/v1/*), management and reporting APIs, /health, /ready
4001 OPS_PORT Admin UI (/), Swagger UI (/swaggerui), OpenAPI spec (/api/openapi), Prometheus metrics (/metrics)

The generated API reference is available at http://localhost:4001/swaggerui during local development.

Admin authentication

WAARN_MASTER_KEY is the secret used to sign in to the Admin UI. Generate it once, store it in a secret manager, and reuse it across restarts and on every node in the cluster:

export WAARN_MASTER_KEY="$(openssl rand -hex 32)"

Global and organization administrator virtual keys can also sign in with their respective access scopes. Use virtual keys for routine API clients. Leaving the master key unset allows unauthenticated access in local development mode only.

Access and usage

  • Global administrators manage the gateway. Organization administrators manage users and view usage within their organization.
  • Create proxy-only sub-keys with POST /key/sub-key/generate, specifying user_email, max_budget_usd, and expires_at. Organizations and teams can configure maximum lifetimes with max_sub_key_ttl_seconds.
  • Explore usage in the Admin UI, including model and agent harness/version breakdowns, filters, and CSV downloads. The /spend/report API provides daily spend by user and model.

Local development

Local development requires Elixir 1.17 or later, Hex 2.6 or newer, PostgreSQL, and Valkey. Configure DATABASE_URL and VALKEY_URL, then run:

make bootstrap
make migrate
make run

Use mix local.hex --force to upgrade Hex. Hex waits seven days after publication before selecting new releases during dependency resolution. Installs from mix.lock are unaffected, and Hex can skip the wait when a locked dependency has a security advisory. Run mix hex.config cooldown to check the setting.

Common commands

Command Purpose
make bootstrap Install local build tools and dependencies, then compile
make deps Fetch locked dependencies
make deps-update Update all dependencies
make migrate Apply database migrations
make run Start the application
make test Run the test suite
make format Format the source code
make audit Run dependency and security audits
make check Run formatting, compilation, tests, and audits
make build-image Build the waarn:local container image
make up / make down Start or stop the container stack
make site-build Build the static site
make site-serve Serve the static site locally

Production

Production (MIX_ENV=prod) fails closed on boot unless these variables are set:

  • SECRET_KEY_BASE: at least 64 bytes
  • WAARN_ENCRYPTION_KEY: provider credential encryption key
  • WAARN_MASTER_KEY: Admin UI master key

The local compose.yaml opts into insecure development defaults with WAARN_ALLOW_INSECURE_DEV=true.

Optional hardening settings include WAARN_ALLOWED_ORIGINS, SESSION_COOKIE_SECURE, FORCE_SSL, DATABASE_SSL with DATABASE_CA_CERT_FILE for a private CA, VALKEY_SSL, OPS_METRICS_TOKEN, and WAARN_SECRETS_DIR.

Server TLS

Set TLS_CERT_FILE to a PEM certificate chain and TLS_KEY_FILE to its PEM private key to serve HTTPS directly on both listeners:

export TLS_CERT_FILE=/path/to/fullchain.pem
export TLS_KEY_FILE=/path/to/privkey.pem
make run

Set both variables or neither. Without them, both listeners serve HTTP. Both files must be readable by the waarn process, and the certificate must be valid for the hostnames clients use to reach both endpoints. Restart waarn after updating the files.

In containers, mount the certificate and key as readable files and set the paths inside the container. When terminating TLS at a reverse proxy, configure it to forward requests to waarn and use FORCE_SSL=true if redirects are desired. The proxy must set a trusted X-Forwarded-Proto header.

For Kubernetes TLS configuration, see Kubernetes TLS.

Kubernetes

The Helm chart in charts/waarn deploys waarn with the official Valkey chart and a CloudNativePG PostgreSQL 17 cluster.

Prerequisites

  • Kubernetes 1.29 or later
  • The CloudNativePG operator and its CRDs when using the bundled database
  • A storage class with dynamic provisioning for the bundled database
  • A waarn image available to the cluster

Build the image with make build-image, then push it to a registry your cluster can access or load it into your local cluster.

In the release namespace, create a Secret named <release>-secrets containing:

  • SECRET_KEY_BASE, at least 64 bytes
  • WAARN_ENCRYPTION_KEY
  • WAARN_MASTER_KEY
  • RELEASE_COOKIE

For bundled Valkey, create a separate Secret named <release>-valkey-password with a VALKEY_PASSWORD key. Use distinct randomly generated values and keep them stable across upgrades.

Install and verify

make helm-deps
helm upgrade --install waarn charts/waarn -n waarn --wait --wait-for-jobs --timeout 20m \
  --set image.repository=registry.example.com/waarn --set image.tag=local \
  --set migrations.enabled=true
helm test waarn -n waarn --filter name=waarn-http
kubectl -n waarn port-forward svc/waarn-ops 4001:4001

Networking, scaling, and monitoring

  • Set replicaCount to scale the gateway with DNS-based node discovery. Enable podDisruptionBudget.enabled=true for availability during voluntary disruptions. The PDB defaults to minAvailable: 1; configure either podDisruptionBudget.minAvailable or podDisruptionBudget.maxUnavailable to change it.
  • Use ingress.enabled, ingress.host, and ingress.tlsSecret to expose the gateway over HTTPS. The operations service stays internal.
  • To supply your own waarn.yaml, set config.existingConfigMap to a ConfigMap containing that key.

To scrape /metrics, install the Prometheus Operator CRDs, add OPS_METRICS_TOKEN to <release>-secrets, and set serviceMonitor.enabled=true. Set serviceMonitor.labels to match your Prometheus ServiceMonitor selector if needed.

Alternatively, set serviceMonitor.tokenSecret.name and serviceMonitor.tokenSecret.key to use another Secret in the release namespace. If serviceMonitor.namespace differs from the release namespace, copy the token Secret there and put the same token in the OPS_METRICS_TOKEN key of <release>-secrets. Set serviceMonitor.tokenSecret.key to an empty string to omit authorization when authentication is disabled.

External PostgreSQL and Valkey

To use existing services, disable the corresponding dependency and provide a connection Secret:

  • Set postgresql.enabled=false and database.existingSecret to a Secret containing DATABASE_URL.
  • Set valkey.enabled=false and cache.existingSecret to a Secret containing VALKEY_URL.

Back up the bundled database before removing or replacing it.

Database migrations

waarn does not run migrations when its application starts. Apply migrations before starting or upgrading the application:

  • For local development, run make migrate with DATABASE_URL configured. make up runs a separate migration service before starting waarn.
  • For an assembled release, run /app/bin/waarn eval 'Waarn.Release.migrate()' with the database and runtime environment configured.
  • For Helm, opt into the migration Job with migrations.enabled=true.

On the first Helm install, the migration runs as a normal Job alongside the bundled database because that database does not exist before Helm installs its resources. Gateway pods may restart until the schema is ready. On upgrade, it runs as a pre-upgrade hook using the new image, and Helm waits for it before updating the Deployment. Set --timeout long enough for database provisioning and the Job.

When the Job is disabled, run migrations separately before starting the new version. Provide externally managed Secrets before an upgrade hook runs. Back up the database and use migrations compatible with the old and new application versions during rolling upgrades. Helm rollback does not roll back database migrations.

Initial bootstrap

To initialize an organization, team, user, or virtual key, start with examples/bootstrap.json, customize the desired sections, and store the resulting file in a Kubernetes Secret. Replace the example virtual key with a unique key generated by a cryptographically secure random generator; it must be at least 16 bytes. Keep the file and Secret private and do not commit real credentials.

kubectl -n waarn create secret generic waarn-bootstrap \
  --from-file=bootstrap.json=/secure/path/bootstrap.json

Set bootstrap.existingSecret=waarn-bootstrap in the Helm release. The setup Job runs bootstrap after migrations, or against an already migrated database if the migration Job is disabled.

Bootstrap is atomic and runs once per database. Later upgrades do not overwrite changes or recreate deleted keys. To add entities after the first bootstrap, use the Admin UI or API. Outside Kubernetes, set WAARN_BOOTSTRAP_PATH and run /app/bin/waarn eval 'Waarn.Bootstrap.run()' after migrating.

Kubernetes TLS

Create a TLS Secret containing tls.crt and tls.key in the release namespace and set tls.existingSecret to its name. Both services then use HTTPS.

For end-to-end TLS through an ingress, configure your ingress controller to use HTTPS and verify the upstream certificate against its trusted CA and hostname. ingress.tlsSecret configures the separate client-facing certificate. Controller-specific upstream TLS settings go in ingress.annotations or the controller configuration.

Certificates must cover the names used by clients, ingress, monitoring, and the Helm smoke test. Configure serviceMonitor.tlsConfig for Prometheus CA and server-name verification. For helm test, configure tls.test.caSecret or tls.test.caConfigMap for a private CA and tls.test.serverName if the certificate name differs from the Service names. Kubernetes HTTPS probes do not verify the certificate.

About

waarn - Workflow Aware Agent Routing Network

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages