name: vision-agents # Every port is published on this machine's loopback only: Postgres keeps its default # password, Redis has none, and the router may run with no auth. ROUTER_PUBLISH_ADDRESS # publishes the router on another address, such as 0.0.0.0 for a phone on the same network. # # A second, isolated stack: `docker compose -p `, with the host ports moved by # ROUTER_PUBLISH_PORT, USAGE_PUBLISH_PORT, POSTGRES_PUBLISH_PORT and REDIS_PUBLISH_PORT. # Its containers, network, volume (_pgdata19) and router image (-router) are # all its own; compose sets COMPOSE_PROJECT_NAME from -p, from .env or from the name above. # Keep the name above: every existing stack's data is in the vision-agents_pgdata19 volume. services: postgres: image: postgres:19-alpine environment: POSTGRES_PASSWORD: postgres POSTGRES_DB: model_router ports: - "127.0.0.1:${POSTGRES_PUBLISH_PORT:-55432}:5432" volumes: - pgdata19:/var/lib/postgresql healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres -d model_router"] interval: 5s retries: 10 redis: image: redis:7-alpine ports: - "127.0.0.1:${REDIS_PUBLISH_PORT:-56379}:6379" healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s retries: 10 router: build: context: ./acceleration # Per project, so a build in one checkout or stack never retags the image another runs. image: ${COMPOSE_PROJECT_NAME:-vision-agents}-router # Provider credentials come from the repo-root .env; the two below are the # ones that differ inside the network and so are set here instead. env_file: - path: .env required: false environment: ROUTER_POSTGRES_DSN: postgres://postgres:postgres@postgres:5432/model_router?sslmode=disable ROUTER_REDIS_ADDR: redis:6379 # The usage service below. While it is down the rows wait in Postgres to be shipped. ROUTER_USAGE_URL: http://usage:8070 ROUTER_USAGE_TOKEN: ${USAGE_INGEST_TOKEN:-local-usage-token} # The Redis the usage service mirrors spend to, which spend limits read every second. ROUTER_USAGE_REDIS_URL: redis://redis:6379 # Seals the secrets the router holds. The router refuses to start without it in the # default api_key auth mode or with connectors on. Any random string works. Make it once and keep it, since changing it leaves the stored ones # unreadable: echo "ROUTER_DEV_KEK=$(openssl rand -hex 32)" >> .env ROUTER_DEV_KEK: "${ROUTER_DEV_KEK:-}" # Off: an organization starts with no credit in the usage service above, and a voice # session's hosted models (speech, voice, the flow controller) are priced, so enforcing # would answer every one 402 until somebody grants credit to themselves. Usage is still # priced and shipped. This variable wins over limits.mode in a mounted config file, so # set ROUTER_LIMITS_MODE=enforce (or shadow) in .env to test limits. ROUTER_LIMITS_MODE: "${ROUTER_LIMITS_MODE:-off}" ports: - "${ROUTER_PUBLISH_ADDRESS:-127.0.0.1}:${ROUTER_PUBLISH_PORT:-8080}:8080" depends_on: postgres: condition: service_healthy redis: condition: service_healthy # The usage service, from the router's image, on a database of its own. The router ships # the usage it records here. usage-db: image: postgres:19-alpine environment: PGPASSWORD: postgres command: >- sh -c "psql -h postgres -U postgres -tAc \"SELECT 1 FROM pg_database WHERE datname = 'usage'\" | grep -q 1 || psql -h postgres -U postgres -c 'CREATE DATABASE usage'" depends_on: postgres: condition: service_healthy # Runs this project's router image, which only the router builds: `docker compose build router`. usage: image: ${COMPOSE_PROJECT_NAME:-vision-agents}-router pull_policy: never entrypoint: ["usage"] environment: USAGE_POSTGRES_DSN: postgres://postgres:postgres@postgres:5432/usage?sslmode=disable USAGE_REDIS_URL: redis://redis:6379 USAGE_INGEST_TOKEN: ${USAGE_INGEST_TOKEN:-local-usage-token} USAGE_MANAGE_KEY: ${USAGE_MANAGE_KEY:-local-usage-manage-key} # Made-up tiers for the local stack; the start adds the ones the database lacks. USAGE_TIERS_FILE: /etc/usage/tiers.json volumes: - ./acceleration/tiers/dev.json:/etc/usage/tiers.json:ro ports: - "127.0.0.1:${USAGE_PUBLISH_PORT:-8070}:8070" healthcheck: test: ["CMD", "usage", "healthcheck"] interval: 5s retries: 10 depends_on: usage-db: condition: service_completed_successfully redis: condition: service_healthy volumes: pgdata19: