Files
cortiq-gateway/config/gateway.example.toml
T
infosave2007 95e560dc72 feat: per-key spend accounting and per-task complexity pinning
API keys page: the table now answers "which department spends what" — per-key
requests, tokens in/out and cost for a selectable window (24h/7d/30d) plus a
cumulative all-time cost column, joined from stats by the key's account.

The stats log stays bounded while the accounting survives: once stats.jsonl
exceeds max_file_mb (default 16, 0 disables), records older than the
retention window fold into cumulative per-account totals in a small sidecar
file (tmp+rename on both) and leave the log. alltime = folded + in-file, a
record is never counted twice, verified end-to-end on synthetic data
(1.2 MB → 301 KB, totals identical before/after compaction and restarts).

Routing: a task rule can now PIN the complexity tier —
`[routing.tasks.legal] models=[...] tier="high"` (old plain-array rules parse
unchanged). The pinned tier replaces the router's verdict before the
escalation check and reports itself as route_source "router+task-rule@high".
The Routing page grows a per-task «Complexity» selector (Auto/low/medium/
high); verified live: a code prompt with a pinned high went
router+task-rule@high → the expensive model.

13 new strings in all 7 languages; docs/ROUTING(.ru) updated.
2026-08-08 08:42:11 +03:00

156 lines
7.5 KiB
TOML

# ============================================================================
# Cortiq Gateway — example configuration
# Copy to gateway.toml and edit for your own model pool.
# Do NOT store secrets here — provide them via *_env (environment variables)
# or set them from the admin console (stored in config/secrets.toml).
# ============================================================================
listen = "0.0.0.0:9000"
# --- connection to cortiq-router (decides task type / complexity) -----------
# Hosted allaigate router: url = "https://138.226.222.209", verify_tls = false
# (cert is bound to an IP), taxonomy_id = "data-assistant", a cortiq_… key in
# CORTIQ_ROUTER_KEY.
# NOTE: on hard prompts the router escalates to an oracle LLM (~10 s) — for the
# hosted router set timeout_ms = 12000+, otherwise the gateway degrades to default.
[router]
url = "https://138.226.222.209" # hosted allaigate router (or your own cortiq-router URL)
api_key_env = "CORTIQ_ROUTER_KEY" # name of the env var holding the router key
timeout_ms = 12000 # hard prompts escalate to an oracle (~10 s)
taxonomy_id = "data-assistant" # the hosted router's task taxonomy
verify_tls = false # the hosted endpoint is IP-bound; true for your own domain
# --- how to pick the text to classify from the conversation -----------------
[route]
text_strategy = "last_user" # last_user | last_user_plus_system | concat_all
max_chars = 4000
cache_ttl = "60s"
profile = "balanced" # cost-saver | balanced | quality-first
# ============================================================================
# Model pool — EMPTY by default. A fresh gateway starts with no models and an
# empty pool; add them in the admin console (/admin → Models), or run a local
# .cmf via the [cmf] section below. To add one by hand, copy this shape:
#
# [[models]]
# id = "my-model"
# provider = "openai" # openai | anthropic (openai also covers
# base_url = "http://127.0.0.1:8081/v1" # OpenRouter/Together/Groq/vLLM/Ollama)
# model = "my-model"
# # api_key_env = "OPENAI_API_KEY" # for hosted providers (never inline a key)
# cost_tier = "local"
# caps = ["tools"]
# ============================================================================
# ============================================================================
# Routing table: complexity tier → ordered pool (priority = fallback chain).
# Leave default empty for a fresh install; set it to a model id once you add one.
# ============================================================================
[routing]
low = []
medium = []
high = []
default = "" # set to a model id once you add one
[routing.policy]
mode = "fixed_table" # fixed_table | cost_aware
# for cost_aware:
# min_class = { low = "cheap", medium = "mid", high = "expensive" }
# max_cost_usd_per_request = 0.50
# --- resilience -------------------------------------------------------------
[breaker]
threshold = 5
cooldown = "30s"
# ============================================================================
# Inbound protocols — enable only what you need (toggles apply live in the UI)
# ============================================================================
[protocols]
openai_chat = true
openai_completions = true
openai_embeddings = true
openai_models = true
anthropic_messages = true
mcp = false
native_passthrough = true
# --- response routing metadata ----------------------------------------------
[cortiq]
echo = true # add a "cortiq" field to the response body (X-Cortiq-* headers are always sent)
# ============================================================================
# Authentication: virtual gateway keys (agents get these, not provider keys).
# If this section is empty, the gateway runs in open mode (local development).
# ============================================================================
[[api_keys]]
key = "sk-gw-team-a"
account = "team-a"
rate_per_min = 600
# allow_models = ["cortiq-auto", "cmf-local"] # restrict available models (optional)
# --- idempotency and logging ------------------------------------------------
[idempotency]
ttl = "10m"
[log]
bodies = false # do NOT log message bodies (privacy) — default
level = "info"
[telemetry]
metrics = true # GET /metrics (Prometheus)
otlp_endpoint_env = "OTEL_EXPORTER_OTLP_ENDPOINT" # optional
# ============================================================================
# Admin web console — embedded in the binary, served at /admin
# ============================================================================
[admin]
enabled = true
# Name of the env var holding the admin token. If unset (or empty), a token is
# generated at startup and printed to the log (see also the --admin-token flag).
token_env = "CORTIQ_ADMIN_TOKEN"
# listen = "127.0.0.1:9001" # optional: separate bind for admin (default: main listen)
# ============================================================================
# Request statistics (dashboard + /metrics). Kept in memory + appended to JSONL.
# ============================================================================
[stats]
enabled = true
file = "config/stats.jsonl" # empty = in-memory only
ring_size = 500 # how many recent requests to keep in the feed
retention = "7d" # aggregate/series depth (replayed on startup)
# stats.jsonl is compacted once it exceeds this size: old records fold into
# cumulative per-account totals (sidecar file), so per-key accounting survives
# while the disk stays bounded. 0 disables.
max_file_mb = 16
# ============================================================================
# Semantic cache — returns a cached answer for prompts semantically near a
# previous one, skipping the model call. Requires an embedding model in the pool.
# Disabled by default. (Cache settings take effect on restart.)
# ============================================================================
[cache]
enabled = false
threshold = 0.92 # cosine similarity for a hit (0..1)
ttl = "1h"
max_entries = 1000
# embed_model = "local-embed" # defaults to the first kind = "embedding" model
# ============================================================================
# Local CMF model server. The gateway can install/run a local .cmf via cortiq
# (github.com/infosave2007/cmf) and register it as the "cmf-local" model above,
# so it works even when the router and cloud providers are unavailable.
# Changes to manage_server / local_model / threads / gpu apply on restart.
# ============================================================================
[cmf]
manage_server = false # true → gateway spawns `cortiq serve` at startup
local_model = "models/model.cmf" # path to the .cmf to serve
local_host = "127.0.0.1"
local_port = 8081 # confirm it's free in Settings → "Check port" (8081 often clashes with Docker/Apache)
model_id = "cmf-local" # id it registers under (matches [[models]])
threads = 8 # decode worker threads (CMF_THREADS); ~3x vs serial
gpu = false # offload matvecs to GPU (Metal/wgpu); mainly a prefill win
cortiq_bin = "cortiq" # the cortiq CLI (cargo install cortiq-cli)
auto_install = false # install cortiq-cli from crates.io if the binary is missing
local_only = false # true → route every request to the local model