automaticai-gateway-ops
When to Use
Use when a task requires mutating or debugging the AutomaticAI gateway at api.automaticai.io (Go new-api fork, remote aai-gateway host, Postgres newapi-postgres + redis newapi-redis reachable via ssh aai-gateway docker exec …): minting scoped tokens, adding provider channels, exposing new automaticai/* models, repointing the auto-router classifier, or diagnosing 403/400 on gateway models. Covers the catalog gate, cache/restart rules, and verification patterns.
Admin session
- The admin API session token expires fast. Re-login with curl and a browser User-Agent — Cloudflare 403s the plain urllib UA:
curl -s -X POST https://api.automaticai.io/api/user/login -H 'Content-Type: application/json' -d '{"username":…,"password":…}' (creds op://DeLoSecrets/n6g3t4ljymbexmjm3x43pu6bc4/*). Send admin calls with New-Api-User: 1 and the browser UA.
Minting a scoped token
POST /api/token/ with {name, group, model_limits_enabled, model_limits, unlimited_quota, expired_time:-1, user_id}. It returns success with an empty key — the key never comes back over the API. Fetch it from the DB: SELECT key FROM tokens WHERE name='<name>' and prefix sk-.
- Set
user_id to a user whose group setup admits the token's group — a token minted under the root session but left with a mismatched owner 403s with 无权访问 <group> 分组. Fleet tokens live under user 5 (delo-relay) with group aai-personal.
model_limits must list the auto family AND each free route explicitly — automaticai/auto grants the auto family, but automaticai/free alone does NOT grant the individual free routes; copy a working fleet token's limits when in doubt.
- Redis caches token rows. After any DB edit to a token (limits, user_id, group), run
docker exec newapi-redis redis-cli FLUSHALL (or restart new-api) before re-testing — the old row serves 403s long after the edit.
Adding a provider channel
- Insert the
channels row directly (API create is validation-quirky): type 58 for custom OAuth-style upstreams, base_url without /v1, models as comma-separated automaticai/<account>/<model> names, model_mapping JSON route→upstream-model, "group" quoted (reserved word), auto_ban is bigint (use 1 not true).
- Restart
new-api — channel rows are cached too.
- The catalog gate is the real gate.
Normalize() validates EVERY automaticai/* model name against the catalog embedded in the Go binary (generated from ops/routes.json in ~/code/client-portal/gateway by brand/apply-gateway.py). A DB channel with no routes.json entry serves 400 unknown AutomaticAI model forever. Exposing models fleet-wide = routes.json edit → apply-gateway.py → Go rebuild → deploy (bash ops/compose.sh up -d new-api).
- Deploy env changes flow through
.env.op (op:// refs) with a gitignored .env.ingress-style overlay for raw keys the vault can't take; ops/compose.sh chains both env files (multiple op run --env-file args are legal).
Classifier options (hot)
automaticai_auto.classifier_url / .classifier_model are hot-reloaded NewAPI options — PUT /api/option/ takes effect immediately, no restart. The classifier's API key comes from the AAI_JEV_API_KEY env var, which DOES need a container recreate. Classifier path (Jev/SystemOne) is governed by the typesafe-ai skill.
Verifying
- Live call through the new token/route:
POST /v1/chat/completions with model: automaticai/auto/fast etc.
- Ledger proof of who served:
SELECT model_name, to_timestamp(created_at) FROM logs WHERE token_name='<n>' ORDER BY created_at DESC LIMIT 5.
- Auto-router internals: the operator API
GET /api/automaticai/{overview,accounts,decisions,ratchet,pins,guards} (admin PAT; tokies auto, tokies auto accounts, tokies auto decisions). The token-scoped /v1/automaticai/auto/state was retired on 2026-11-05.
1---2name: automaticai-gateway-ops3description: Operate the AutomaticAI gateway — tokens, channels, catalog.4version: 1.0.05author: grolf6license: MIT7metadata:8 source: https://skillmd.com/skills/delorenj/automaticai-gateway-ops9 hermes:10 tags: [gateway, llm-routing, devops]11 related_skills: [typesafe-ai, litellm-fallback-ladders]12---1314# automaticai-gateway-ops1516## When to Use1718Use when a task requires mutating or debugging the AutomaticAI gateway at `api.automaticai.io` (Go new-api fork, remote `aai-gateway` host, Postgres `newapi-postgres` + redis `newapi-redis` reachable via `ssh aai-gateway docker exec …`): minting scoped tokens, adding provider channels, exposing new `automaticai/*` models, repointing the auto-router classifier, or diagnosing 403/400 on gateway models. Covers the catalog gate, cache/restart rules, and verification patterns.1920## Admin session2122- The admin API session token expires fast. Re-login with curl and a browser User-Agent — Cloudflare 403s the plain urllib UA: `curl -s -X POST https://api.automaticai.io/api/user/login -H 'Content-Type: application/json' -d '{"username":…,"password":…}'` (creds `op://DeLoSecrets/n6g3t4ljymbexmjm3x43pu6bc4/*`). Send admin calls with `New-Api-User: 1` and the browser UA.2324## Minting a scoped token25261. `POST /api/token/` with `{name, group, model_limits_enabled, model_limits, unlimited_quota, expired_time:-1, user_id}`. **It returns success with an empty key** — the key never comes back over the API. Fetch it from the DB: `SELECT key FROM tokens WHERE name='<name>'` and prefix `sk-`.272. Set `user_id` to a user whose group setup admits the token's group — a token minted under the root session but left with a mismatched owner 403s with `无权访问 <group> 分组`. Fleet tokens live under user 5 (delo-relay) with group `aai-personal`.283. `model_limits` must list the auto family AND each free route explicitly — `automaticai/auto` grants the auto family, but `automaticai/free` alone does NOT grant the individual free routes; copy a working fleet token's limits when in doubt.294. **Redis caches token rows.** After any DB edit to a token (limits, user_id, group), run `docker exec newapi-redis redis-cli FLUSHALL` (or restart `new-api`) before re-testing — the old row serves 403s long after the edit.3031## Adding a provider channel32331. Insert the `channels` row directly (API create is validation-quirky): type 58 for custom OAuth-style upstreams, `base_url` without `/v1`, `models` as comma-separated `automaticai/<account>/<model>` names, `model_mapping` JSON route→upstream-model, `"group"` quoted (reserved word), `auto_ban` is bigint (use 1 not true).342. Restart `new-api` — channel rows are cached too.353. **The catalog gate is the real gate.** `Normalize()` validates EVERY `automaticai/*` model name against the catalog embedded in the Go binary (generated from `ops/routes.json` in `~/code/client-portal/gateway` by `brand/apply-gateway.py`). A DB channel with no routes.json entry serves 400 `unknown AutomaticAI model` forever. Exposing models fleet-wide = routes.json edit → apply-gateway.py → Go rebuild → deploy (`bash ops/compose.sh up -d new-api`).364. Deploy env changes flow through `.env.op` (op:// refs) with a gitignored `.env.ingress`-style overlay for raw keys the vault can't take; `ops/compose.sh` chains both env files (multiple `op run --env-file` args are legal).3738## Classifier options (hot)3940`automaticai_auto.classifier_url` / `.classifier_model` are hot-reloaded NewAPI options — `PUT /api/option/` takes effect immediately, no restart. The classifier's API key comes from the `AAI_JEV_API_KEY` env var, which DOES need a container recreate. Classifier path (Jev/SystemOne) is governed by the typesafe-ai skill.4142## Verifying4344- Live call through the new token/route: `POST /v1/chat/completions` with `model: automaticai/auto/fast` etc.45- Ledger proof of who served: `SELECT model_name, to_timestamp(created_at) FROM logs WHERE token_name='<n>' ORDER BY created_at DESC LIMIT 5`.46- Auto-router internals: the operator API `GET /api/automaticai/{overview,accounts,decisions,ratchet,pins,guards}` (admin PAT; `tokies auto`, `tokies auto accounts`, `tokies auto decisions`). The token-scoped `/v1/automaticai/auto/state` was retired on 2026-11-05.