# Projects and tokens

The life of a server project: registration, named tokens, and in the end its deletion.

## Projects and tokens

Whoever registers a project on the server is its admin and hands out named tokens (one per person or CI job). The server coordinates (ids, claims, Team AI); the tickets live in the repo's store, or with `store: server` on the server ([A store on the server](/en/docs/guides/team/server-store.md#team-server-store)).

```console
$ tkt project register https://tkt.ideathon.me --name Payments
```

- Roles: `admin` ⊇ `write` ⊇ `read`; `--llm` is a separate grant. The last valid admin token cannot be revoked, demoted or given an expiry (`ERR_LAST_ADMIN`).
- A token (`atk_…`) is shown once: share it only over a secure channel, never in a ticket, a commit, a chat or an argument (`tkt doctor` reports one in a store file: `TOKEN_IN_STORE`).
- `tkt login` reads the token you were given from stdin or a hidden prompt and stores it; `AITODO_TOKEN` overrides the file (CI). `ERR_AUTH_REQUIRED` (401): no or unknown token; `ERR_AUTH_FORBIDDEN` (403): expired, revoked, role too low, or another project's.

### Details

- `tkt project register <url> --name N --as alice --force`: `--as` defaults to `$USER` (`USERNAME` on Windows; required without both). It writes the pin (`.aitodo/server.yaml`, `{url, project}`, no secret: commit it) and the admin token to the credentials file ([Server pin and credentials](/en/docs/guides/team/credentials.md#team-pin)). An existing pin needs `--force` (else `ERR_ID_DUPLICATE`).
- `tkt token create ci --role write --llm --expires 90d` prints just the token (pipeable); `--json`: `{name, role, llm, created, expires, lastUsed, revoked, token}`. `--expires 2027-01-31`: through that day (UTC). `tkt token list --json`: never a token value. `tkt token update ci --role read --no-llm --no-expires`. `tkt token revoke ci` (name stays reserved). `tkt logout` drops the stored token.
- `tkt login` takes the server from the pin, in a `store: server` folder from its `.aitodo.yaml`, else `tkt login <url> --project <id>`; it checks the token (`/whoami`) and prints `Saved in <path> (from …)`.
- All admin tokens lost: the operator runs `tkt operator admin-token` (HTTP) or `tkt server admin-token` (on the host).
- HTTP client: 30 s timeout, system TLS trust plus `AITODO_CA_BUNDLE`; plain `http://` only to localhost. Header: `Authorization: Bearer atk_…`. It follows a redirect only for a read (GET) and only to the same scheme, host and port, with the token; any other redirect (another host or port, https to http, a redirected write) stops with `ERR_COORDINATOR_UNREACHABLE` naming only the target's origin, and the token goes nowhere. Then set the server URL to the address the server really answers at. The credentials file: `servers: {<url>: {projects: {<id>: {name, token}}}}` (URL: scheme + host lower case, no trailing slash).

## Deleting a project

An admin deletes a project and everything the server keeps for it (tokens, LLM usage and caps, id counters, claim leases) in one step: `tkt project delete --confirm Payments`. The tickets in the store are never touched, and the id is never reused. Without a matching `--confirm` it asks you to type the name; with no terminal: `ERR_CONFIRM_REQUIRED`, nothing deleted.

### Details

Then it removes your stored token and the `.aitodo/server.yaml` that points at the project: commit that, the store works locally again. Admin tokens lost: the operator runs `tkt operator project-delete` (HTTP) or `tkt server project-delete` (on the host).

## Commands on this page

- [`tkt project register`](/en/docs/reference/commands/projects.md#tkt-project-register): Register a project on the server; you become its admin
- [`tkt token create`](/en/docs/reference/commands/projects.md#tkt-token-create): Create a named token and print it once
- [`tkt token list`](/en/docs/reference/commands/projects.md#tkt-token-list): The project's tokens: name, role, llm, created, expires, last used: never the token
- [`tkt token update`](/en/docs/reference/commands/projects.md#tkt-token-update): Change a token's role, LLM grant or expiry
- [`tkt token revoke`](/en/docs/reference/commands/projects.md#tkt-token-revoke): Revoke a token
- [`tkt login`](/en/docs/reference/commands/projects.md#tkt-login): Store a token your project admin gave you
- [`tkt logout`](/en/docs/reference/commands/projects.md#tkt-logout): Forget the stored token of this project (the server keeps it: ask the admin to revoke)
- [`tkt project delete`](/en/docs/reference/commands/projects.md#tkt-project-delete): Delete the project on the server (admin): its tokens, LLM usage and caps, id counters and claim leases

## Related

- Guide: [A store on the server](/en/docs/guides/team/server-store.md): A project's store can live on the server instead of the repo; the repo then holds only .aitodo.yaml (store: server, server, project).
- Guide: [Server pin and credentials](/en/docs/guides/team/credentials.md): Where tkt finds the server and the project, and where your token is.
- Error code · 401: [`ERR_AUTH_REQUIRED`](/en/docs/reference/errors.md#ERR_AUTH_REQUIRED): No token, or one the server does not know
- Error code · 403: [`ERR_AUTH_FORBIDDEN`](/en/docs/reference/errors.md#ERR_AUTH_FORBIDDEN): The token is expired, revoked, of another project, or its role is too low
- Error code · 409: [`ERR_LAST_ADMIN`](/en/docs/reference/errors.md#ERR_LAST_ADMIN): The project would lose its last valid admin token
- Doctor · error: [`TOKEN_IN_STORE`](/en/docs/reference/doctor.md#doctor-TOKEN_IN_STORE): A token (atk\_…) written into a store file
- Env var: [`AITODO_TOKEN`](/en/docs/reference/env.md#AITODO_TOKEN): A project token; beats the credentials file
- Error code · 422: [`ERR_CONFIRM_REQUIRED`](/en/docs/reference/errors.md#ERR_CONFIRM_REQUIRED): A deletion without a matching --confirm and no terminal to ask on; nothing deleted
