{% extends "base.html" %} {% import "_ui.html" as ui %} {% block title %}AI settings{% endblock %} {% block crumbs %}AI provider{% endblock %} {% block content %}

AI provider

Which provider and model ti2dac uses, its API keys, how much it has used, and whether requests are currently allowed.

{% if ai.state != 'ok' and role == 'admin' %}
{% endif %}
{% if just_blocked %}
{{ ui.icon("pause") }}
That action needs the AI, which is paused right now.
No request was sent. Details below.
{% endif %} {%- set pct = ([100, (ai.requests_today * 100 / ai.limit)|round|int]|min) if ai.limit else 0 -%}
{%- set no_key = ai.enabled and ai.key == 'not configured' and ai.state == 'ok' %}
{{ ui.icon("ai", "sm") }}Status
{{ 'no key' if no_key else ai.state.replace('_', ' ') if ai.enabled else 'disabled' }}
{% if not ai.enabled %}Deterministic mode{% elif ai.retry_at %}resets at {{ ai.retry_at }} UTC{% if ai.wait %} (about {{ ai.wait }}){% endif %}{% else %}{{ ai.provider }}{% endif %}
{{ ui.icon("zap", "sm") }}Requests today
{{ ai.requests_today }}{% if ai.limit %} of {{ ai.limit }}{% endif %}
{% if ai.limit %}
{% else %}
No cap set: ai.daily_request_limit
{% endif %}
{{ ui.stat("Tokens today", (ai.in_today + ai.out_today)|tok, "cpu", hint="{:,}".format(ai.in_today) ~ " input · " ~ "{:,}".format(ai.out_today) ~ " output") }} {{ ui.stat("Spend, all time", "$" ~ ("%.2f"|format(ai.cost_total or 0)), "dollar", hint=((ai.in_total + ai.out_total)|tok) ~ " tokens · list-price estimate") }}

{{ ui.icon("key") }}API keys

Stored in the server's {{ env_path }} (git-ignored, owner-only), never in the database, and never shown again. A new key is used by the next job; no restart needed.

{% if insecure %}
{{ ui.icon("alert") }}
This page is not encrypted
You reached ti2dac over plain HTTP on a network address, so a key typed here would cross the network in clear text. Put it behind HTTPS (a reverse proxy) or set the key on the server instead.
{% endif %}
{% for k in keys %}
{{ k.label }}{% if k.active %}active provider{% endif %}
{% if k.source %}{{ ui.status("set " ~ k.tail, "ok") }}from {{ k.source }} {% else %}{{ ui.status("not set", "bad" if k.active else "muted") }}{% endif %} {{ k.var }}
{% if k.check %}
{{ ui.icon("check-circle" if k.check.ok else "x" if k.check.ok is sameas false else "info") }}
{{ k.check.message }} · {{ k.check.by }} at {{ k.check.at }}
{% endif %} {% if role == "admin" %}
{% if k.source %}{% endif %} {% if k.source == ".env" %}{% endif %}
{% if k.source == "environment" %}

This key comes from the server's environment. Saving here overrides it until the next restart, when the environment value wins again; change it where ti2dac is started to make it permanent.

{% endif %} {% endif %}
{% endfor %} {% if role != "admin" %}

Only admins can add or change keys.

{% endif %}

{{ ui.icon("ai") }}Model

Which provider and model ti2dac uses. Saved in the server's .ti2dac/ai_models.json (overrides ti2dac.yaml); jobs started after saving use it, no restart needed.{% if model_choice.updated_by %} Last changed by {{ model_choice.updated_by }}, {{ model_choice.updated_at[:16]|replace("T", " ") }} UTC.{% endif %}

{% if model_locks %}
{{ ui.icon("alert") }}
{{ model_locks|join(" and ") }} {{ "is" if model_locks|length == 1 else "are" }} set in the server environment
That overrides the choice here. Remove it where ti2dac is started (or from .env) to manage the model on this page.
{% endif %}
{% for b in model_blocks %}
{{ b.label }}{% if b.active %}active provider{% endif %}
{% if b.fetched_at %}Models this key can use, listed {{ b.fetched_at }} UTC{% else %}Built-in model list{% endif %}
{% if b.msg %}
{{ ui.icon("check-circle" if b.msg.ok else "x") }}
{{ b.msg.message }} · {{ b.msg.by }} at {{ b.msg.at }}
{% endif %} {% if role == "admin" %}
{{ ui.icon("chevron-right", "sm chev") }}Different model per stage
{% for st in stages %}{% endfor %}

Analyse reads the report once; generate writes each rule, where quality matters most; repair and translate are small follow-up calls that a cheaper model often handles well. Review is the default for a run's AI review (any model can be picked per review); a model other than generate's gives a more independent second opinion.

{% if b.key_set %} {% else %}No key for {{ b.label }} yet: add one under API keys.{% endif %}
{% else %}

{% if b.active %}Uses {{ b.main }}{% for st, m in b.stages.items() if m %}; {{ st }}: {{ m }}{% endfor %}. {% endif %}Only admins can change the model.

{% endif %}
{{ ui.icon("chevron-right", "sm chev") }}About these models
{% if b.provider == "anthropic" %}{% endif %}{% for m in b.models if m.note %} {% if b.provider == "anthropic" %}{% endif %}{% endfor %}
ModelPrice (input / output)Refusal fallbackNotes
{{ m.id }}{{ m.price }}{{ "yes" if m.fallback else "no" }}{{ m.note }}

List prices; cache reads and writes are priced separately. A fallback model answers when the chosen one declines a security report.

{% endfor %}

{{ ui.icon("cpu") }}Configuration

Provider
{{ ai.provider }} · AI {{ "enabled" if ai.enabled else "disabled (deterministic mode)" }}
Credentials
{{ ui.status(ai.key, 'bad' if ai.key == 'not configured' else 'ok') }} (the key itself is never shown)
Status
{{ ui.status(ai.state, 'ok' if ai.state == 'ok' else 'warn' if ai.state in ('refused', 'unavailable') else 'bad') }} {% if ai.retry_at %} resets at {{ ai.retry_at }} UTC{% if ai.wait %} (about {{ ai.wait }}){% endif %}{% endif %}
Requests today
{{ ai.requests_today }}{% if ai.limit %} of your cap {{ ai.limit }}{% else %} (no cap set: ai.daily_request_limit){% endif %}
Tokens today
{{ "{:,}".format(ai.in_today) }} input · {{ "{:,}".format(ai.out_today) }} output {% if ai.cache_today %}· {{ "{:,}".format(ai.cache_today) }} cache read{% endif %} · est. ${{ "%.4f"|format(ai.cost_today or 0) }}
Tokens all time
{{ "{:,}".format(ai.in_total) }} input · {{ "{:,}".format(ai.out_total) }} output · est. ${{ "%.4f"|format(ai.cost_total or 0) }}
Estimates from list prices; $0 for models without a price, e.g. Gemini.
{% if ai.last_success %}
Last success
{{ ai.last_success }}
{% endif %} {% if ai.message %}
Last error
{{ ai.message }}
{% endif %}
Models per stage
{% if role == "admin" %}Change per stage {{ ui.icon("arrow-right", "sm") }} {% else %}Only admins can change these{% endif %}
{% for k, v in ai.models.items() %}
{{ k }}
{{ v }}
{% endfor %}
{% if ai.blocked %}
{{ ui.icon("pause") }}
{{ ai.blocked }}
While paused, nothing is sent to the provider: repeated requests after a "quota exhausted" answer waste quota and can be treated as abuse by the provider. Everything that does not need the AI (conversion, replay, review, feedback with a corrected rule, export) keeps working.
{% endif %} {% if ai.state != 'ok' and role != 'admin' %}

An admin can clear the pause after the cause is fixed (new key, quota reset, billing).

{% endif %}

{{ ui.icon("info") }}What the states mean

How ti2dac protects your quota when the provider pushes back.

StateMeaningWhat happens
{{ ui.status("rate limited", "warn") }}Too many requests per minutePaused until the provider's retry time (usually seconds to a minute), then resumes by itself
{{ ui.status("quota exhausted", "bad") }}Daily/free-tier quota, credit balance or spend limit used upPaused until the reset time the provider gave; no retries
{{ ui.status("daily cap", "bad") }}Your own ai.daily_request_limit reachedPaused until local midnight
{{ ui.status("auth error", "bad") }}Key missing, invalid or without permissionPaused until fixed and cleared
{{ ui.status("refused", "warn") }}The model declined one request (safety filter)Not a pause; that rule is skipped with a warning
{{ ui.status("unavailable", "warn") }}Provider down or overloaded (connection error, timeout, 5xx/529) after retriesNot a pause; uses ai.failover_provider if set and the report's TLP allows it, otherwise that step fails with a retry command

Setting up a key

{{ ui.icon("key") }}Claude (Anthropic)

Recommended
  1. Sign in at console.anthropic.com with your company account, add billing, and create a key under API keys (one key per environment).
  2. Optional: set a monthly spend limit for the workspace in the Console.
  3. Paste it under API keys above, or put it in .env yourself, export it in your shell, or run ant auth login:
    {{ ui.code("ANTHROPIC_API_KEY=sk-ant-...") }}
  4. Check it with Test above or ti2dac ai-status.

A Claude.ai or Claude Code subscription is not an API key: API usage is billed separately in the Console.

{{ ui.icon("key") }}Gemini (Google AI Studio)

  1. Create a key at aistudio.google.com → Get API key, in a Google Cloud project with billing enabled (paid tier).
  2. Install the extra:
    {{ ui.code('pip install -e ".[gemini]"') }}
  3. Paste the key under API keys above, then click Use Gemini under Model. On a server without the web UI, run ti2dac model gemini-flash-latest --provider gemini.
  4. Optional, recommended on low quotas: ai.daily_request_limit in ti2dac.yaml a little under your quota.
{{ ui.icon("alert") }}
Free-tier keys: about 20 requests/day, prompts may be used by Google, and attack-simulation content can trip abuse filters. Use them only for public reports and light testing.

{{ ui.icon("shield", "sm") }} Keys set here go to the server's .env file, never to the database or the audit log (which records only who changed which provider's key, and its last 4 characters). Prefer HTTPS when the server is not on localhost.

{% endblock %}