# Team AI

Team AI: the server provides the LLM, with no key of your own. Here is how to use it and how to run it.

## Team AI: the server LLM

**On this server: the LLM is not configured (no `ANTHROPIC_API_KEY`); projects cannot enable it.** LLM features (`--summary`, `tkt suggest refs`, `tkt suggest value`, `tkt plan from-docs`) use a local command by default (`claude -p` or `AITODO_LLM_CMD`). A project can use this server instead: it holds the Anthropic key, and the commands pick it on their own when the project enabled it and your token has the `llm` grant.

- **Then never ask the user for an AI key or a `claude` login.**
- Prefer `--llm-provider server` when `AITODO_LLM_CMD` is set (it beats the project default) or no local `claude` is logged in.
- A server failure never fails the command: stderr shows `ERR_LLM_PROVIDER` with the server's slug, the command falls back, exit 0. `ERR_LLM_QUOTA`: report it, do not retry before the reset; `ERR_RATE_LIMITED`: the project runs too many calls, wait and retry once; `ERR_PAYLOAD_TOO_LARGE`: narrow the input; `ERR_LLM_UPSTREAM`: retry later once; `ERR_LLM_NOT_CONFIGURED`: for the operator; `ERR_AUTH_FORBIDDEN`: no `llm` grant or it is off: for the admin.

### Details

Overview: `https://tkt.ideathon.me/en#csapat-ai`. The prompt (ticket and doc text) goes from your machine via the server to Anthropic; the server never stores or logs it (SDK logs below `WARNING` are muted) and records per call project, token name, time, model and token counts. The project spends its plan's credits, which the server's operator grants ([AI plans and prices](/en/docs/guides/team/ai-plans.md#team-ai-plans)).

- **Check it:** `tkt login` (`as 'ci-bot' (write, llm)`); `GET /v1/projects/{p}`: `llmEnabled`; `/whoami`: `llm`; admins: `tkt project llm usage --by-token`. `tkt ticket get <ID> --summary --json`: `summarySource: llm|cache|fallback`, plus `setupHint` on fallback.
- **On a server-hosted store (`store: server`)** the command runs on the server and uses only the project's server LLM, with no switch: the server gives the run a temporary grant that acts as your token on the LLM calls only and is deleted when the run ends. Your `AITODO_LLM_CMD` does not apply; the client drops `--llm`, `--llm-cmd`, `--llm-provider` (`… is ignored on a server-hosted store`), `--no-llm` goes. With the project's LLM off (`tkt project llm enable`) or no `llm` on your token (`tkt token update <name> --llm`) the command runs without it, exit 0, and the notice names the reason.
- **Provider order** (flags > env, explicit > project default): `--no-llm`; `--llm-cmd`; `--llm-provider server|local|off`; `--llm` (local); `AITODO_LLM_CMD`; `AITODO_LLM_PROVIDER=server|local|off`; `llmProvider` in the user, then the store config; the project's server LLM (skipped if unreachable); else none, with a notice. Without pin or token `--llm-provider server` exits 2, naming `tkt project register` / `tkt login`.
- **Fallbacks:** e.g. `[ERR_LLM_QUOTA] Today's AI budget is used up (plan 'team'); it resets at 00:00 UTC.`; brief view instead of the summary, suggestions without LLM. Prompts are never split. A 403 is the admin's: `tkt token update <name> --llm` / `tkt project llm enable`.
- **The answer cache:** `--summary` and `suggest refs|value` answers are kept per project, keyed by the hash of the model's input (provider, model, prompt version, prompt, schema): an unchanged ticket (blockers, waiters, warnings) costs the team one call. A hit costs no credits (`cacheHits`). Stored: hash, answer, model, time, token counts; never the prompt. Entries: 30 days, at most 5000 per project (oldest dropped), deleted with it. `--refresh` asks again (for a poor answer). A local command caches in `.aitodo/cache/llm/` (gitignored); `AITODO_LLM_CACHE=0` uses neither.
- **Protocol:** `llm:complete` with `cacheable: true` (for `--summary`): lookup, then store; reply `{answer, cache: hit|miss|off, generatedAt}`. Batches: `POST /v1/projects/{p}/llm/cache:lookup` `{keys}` gives `{cache: on|off, entries: {key: {answer, generatedAt}}}`, then `cacheItems: [{key, slot}]` for misses, stored per key with its token share.

## Running Team AI

Team AI is off by default: an admin enables it per project and grants `llm` per token (admin does not imply it: `tkt token update ci --llm`). What it may spend is the project's plan, granted by the operator ([AI plans and prices](/en/docs/guides/team/ai-plans.md#team-ai-plans)); with your own or a local LLM tkt sets no limit. Model: `claude-opus-5-5`; timeout 300 s per Anthropic call, the CLI waits up to 600 s; one request is at most 2 MB.

```console
$ tkt project llm enable
```

### Details

Admin token (no options in a `store: server` folder):

- `tkt project llm enable` / `tkt project llm disable`: the project's one server-AI switch, for the LLM and the embedding together; with neither set up on the server, 503 `ERR_LLM_NOT_CONFIGURED`. `tkt project llm cache on|off`: on by default, off also deletes it.
- `tkt project llm usage --by-token --json`: the plan, the share of the monthly and the daily budget used and the resets, the calls today and this month (UTC); never tokens. The admin's own caps (`tkt project llm limit`) are not available yet: `ERR_FEATURE_POSTPONED` (501). When the plan grants no server AI, `enable` says so.
- The daily cap resets at 00:00 UTC, the monthly on day 1. At or over it: `ERR_LLM_QUOTA` (429); the call that crosses it completes and counts. Each call reserves its worst case (the prompt and the longest answer) before it starts and settles to its real cost: calls running at once start only up to the remaining budget, the rest get `ERR_LLM_QUOTA`. Per project at most 4 calls run at once and 60 start a minute (`AITODO_SERVER_LLM_MAX_INFLIGHT`, `AITODO_SERVER_LLM_RATE_LIMIT`), else 429 `ERR_RATE_LIMITED`. A short outage of the provider (HTTP 429, 500, 502, 503, 504, 529, no connection) is retried up to 2 times, each wait longer, or after its `retry-after` when that fits; no retry starts after 290 s, so the request ends inside the CLI's wait. A timeout or a refused request is not retried. The request holds one reservation and one rate-limit slot; only the answered attempt costs. When every attempt fails, `ERR_LLM_UPSTREAM` names the count and says the failure is transient. A larger request: `ERR_PAYLOAD_TOO_LARGE` (413).
- **Operator:** `ANTHROPIC_API_KEY` as a secret (without it nothing enables; it never reaches a record, reply, log or page); `AITODO_SERVER_LLM_MODEL` (default `claude-opus-5-5`); `AITODO_SERVER_LLM_MAX_BYTES` (default 2 MB); `AITODO_SERVER_LLM_CACHE_TTL` (e.g. `30d`, `12h`), `AITODO_SERVER_LLM_CACHE_MAX`, `AITODO_SERVER_LLM_MAX_INFLIGHT` and `AITODO_SERVER_LLM_RATE_LIMIT`; invalid values stop the server at startup. Needs the `aitodo[server]` extra (else `ERR_LLM_NOT_CONFIGURED`) and a proxy read timeout ≥ 600 s. On a server-hosted store a run's LLM calls go to the server's own port on `127.0.0.1` (listen there too), bounded by `AITODO_CLI_TIMEOUT` (default 30 s).
- REST: `PATCH /v1/projects/{p}` `{llmEnabled?, llmCache?}`; `llm:complete` `{prompt, schema, cacheable?, cacheSlot?, promptVersion?, refresh?, cacheItems?}` (read + `llm`); `…/llm/usage?byToken=true` (admin); `…/llm/status` (read): `budget`.

## Commands on this page

- [`tkt project llm enable`](/en/docs/reference/commands/projects.md#tkt-project-llm-enable): Make the server the project's default LLM
- [`tkt project llm disable`](/en/docs/reference/commands/projects.md#tkt-project-llm-disable): Switch the project's server LLM off; the CLI falls back to a local provider or none
- [`tkt project llm cache`](/en/docs/reference/commands/projects.md#tkt-project-llm-cache): Switch the server's cache of the project's LLM answers (on by default)
- [`tkt project llm usage`](/en/docs/reference/commands/projects.md#tkt-project-llm-usage): The project's AI budget as a share used (its plan's credits, never tokens), the calls made today and this month (UTC), and the answer cache's hits

## Related

- Guide: [AI plans and prices](/en/docs/guides/team/ai-plans.md): The operator pays for the server AI, so the operator grants it: every project spends its plan's credits.
- Error code · 429: [`ERR_LLM_QUOTA`](/en/docs/reference/errors.md#ERR_LLM_QUOTA): The project's server AI budget (its plan's daily or monthly credits) is used up or not granted
- Error code · 502: [`ERR_LLM_UPSTREAM`](/en/docs/reference/errors.md#ERR_LLM_UPSTREAM): The server LLM's upstream API failed
- Error code · 503: [`ERR_LLM_NOT_CONFIGURED`](/en/docs/reference/errors.md#ERR_LLM_NOT_CONFIGURED): The server has no LLM key or no price for the model, or the project has not enabled it
- Error code · 422: [`ERR_LLM_PROVIDER`](/en/docs/reference/errors.md#ERR_LLM_PROVIDER): The LLM provider (a local command or the server) failed
- Env var: [`AITODO_LLM_PROVIDER`](/en/docs/reference/env.md#AITODO_LLM_PROVIDER): server, local, endpoint or off: which LLM provider a command uses; beats llmProvider in the user and store config
- Env var: [`AITODO_LLM_CMD`](/en/docs/reference/env.md#AITODO_LLM_CMD): A local LLM command (reads a prompt on stdin, prints JSON); beats the server LLM
- Env var: [`AITODO_LLM_CACHE`](/en/docs/reference/env.md#AITODO_LLM_CACHE): 0: no reads from or writes to the local LLM answer cache
- Env var: [`ANTHROPIC_API_KEY`](/en/docs/reference/env.md#ANTHROPIC_API_KEY): The key of the server LLM (Team AI); a secret, never sent to a client
- Env var: [`AITODO_SERVER_LLM_MODEL`](/en/docs/reference/env.md#AITODO_SERVER_LLM_MODEL): The model of the server LLM
- Env var: [`AITODO_SERVER_LLM_MAX_BYTES`](/en/docs/reference/env.md#AITODO_SERVER_LLM_MAX_BYTES): The largest request (prompt and schema) the server LLM takes, in bytes
- Env var: [`AITODO_SERVER_LLM_CACHE_TTL`](/en/docs/reference/env.md#AITODO_SERVER_LLM_CACHE_TTL): How long a cached server LLM answer lives
