# Chronary auth.md

How an AI agent gets credentials for Chronary, the calendar API for agents. You can use every path here with no human in the loop, except where a step says a person must act.

- API base: `https://api.chronary.ai`
- OpenAPI 3.1: `https://api.chronary.ai/openapi.json`
- Full reference: `https://docs.chronary.ai/api-reference/agent/`
- LLM context: `https://chronary.ai/llms.txt`

## Credentials

Every call except sign-up sends `Authorization: Bearer <key>`.

| Key | Prefix | Scope |
| --- | --- | --- |
| Organization key | `chr_sk_` | The whole organization: agents, calendars, events, webhooks, keys, usage |
| Agent key | `chr_ak_` | One agent's calendars, events and availability. Minted with an Organization key (`POST /v1/keys`) on a Developer or Pro plan |

Keys are opaque strings of up to 64 characters. Store them as secrets, and never put one in a URL, a log or a commit.

## Before any sign-up: the Terms version

`GET /v1/auth/terms/current` (no auth) returns `{ "version": "...", ... }`. Send that exact `version` as `tos_version`.

Sending it accepts the Terms of Service (https://chronary.ai/terms) for the person or organization you act for. If the Terms change between the two calls, sign-up answers `409 tos_version_stale` with `current_version`; retry once with it.

## Path 1: sign up with an email

Use this when you can read a person's inbox or ask them for a code. The account belongs to whoever owns the email.

1. `POST /v1/agent/sign-up` with `{ "email", "agent_name", "tos_version" }`.
   - The response is `200 { org_id, agent_id, api_key }`.
   - The key works at once on the Sandbox plan.
2. Get the 6-digit code from that inbox.
3. `POST /v1/agent/verify` with `{ "otp" }` and the key as Bearer. The organization moves to the Free plan, and the same key keeps working.

Other responses:
- An email that is already registered gets the same `200 { message }` with no key, so the API never reveals which emails have accounts.
- While sign-ups are paused, the response is `202 { waitlisted: true, message }`, with no key.

One-liner: `npx -y @chronary/agent-init@latest --email you@example.com`.

## Path 2: sign up with no email (claimable)

Use this when no inbox is available. It can be switched off at times: where it is off, the response is `503 anonymous_signup_disabled`, and you use Path 1.

1. `POST /v1/agent/sign-up/anonymous` with `{ "agent_name", "tos_version" }`. The response is `201`:
   ```json
   {
     "org_id": "...",
     "agent_id": "agt_...",
     "api_key": "chr_sk_...",
     "claim_url": "https://console.chronary.ai/claim/anonymous#token=...",
     "expires_at": "2026-11-21T12:00:00.000Z",
     "plan": "free-agent-unverified"
   }
   ```
2. Use `api_key` right away and book events. The Sandbox plan holds one calendar:
   - After a sign-up through the API, an SDK, the CLI or the MCP tool, create it: `POST /v1/agents/{agent_id}/calendars`.
   - `agent-init --anonymous` has already created it ("Welcome to Chronary"). Its id is `calendar_id` in the `--json` line, or `GET /v1/calendars` lists it. Don't create another one: the plan's calendar limit refuses it.
3. Give `claim_url` to the person who should own the calendar. It is shown once and works once.
   - The person opens it while signed in to the console, or signs in or creates an account first.
   - Everything moves into their account.
   - The anonymous key then returns `401`, so ask them for a new key.

Restrictions until claimed:
- Sandbox plan limits.
- No email, and no webhook endpoints.
- No email change and no OTP verify. These return `403 anonymous_org_restricted`.

If nobody claims it by `expires_at` (72 hours after sign-up):
- the key returns `401 key_expired`;
- the claim link stops working;
- the organization and its data are deleted, with no export.

Limits on this path:
- 5 requests a minute per IP;
- 3 an hour and 10 a day per network (`429 rate_limit_error` with `Retry-After`);
- a global daily cap (`503 anonymous_signup_capacity`).

Other ways to run the same sign-up:
- `npx -y @chronary/agent-init@latest --anonymous` (add `--json` for one JSON line that includes `claim_url`).
- `chronary auth signup --anonymous --agent-name <name> --tos-version <version>`.
- The stdio MCP server (`npx -y @chronary/mcp@latest`) started with no `CHRONARY_API_KEY`. It offers only the `sign_up_anonymous` tool, then loads every tool with the new key.

Guide: https://docs.chronary.ai/guides/claimable-calendars/

## Path 3: a person gives you a key

A person signs in at https://console.chronary.ai and creates a key on the API keys page. You receive it as `CHRONARY_API_KEY`.

## MCP

- Hosted: `https://api.chronary.ai/mcp`, with `Authorization: Bearer <key>`. Every tool call needs a key. Tool discovery (`tools/list`) works without one.
- Stdio: `npx -y @chronary/mcp@latest`, with `CHRONARY_API_KEY` in its environment, or no key at all for Path 2.

## Errors you may see

| Status | `error.type` | What to do |
| --- | --- | --- |
| 401 | `authentication_error` | Missing, wrong or revoked key |
| 401 | `key_expired` | A claimable organization expired unclaimed; sign up again |
| 403 | `anonymous_org_restricted` | Not available before a claim |
| 403 | `plan_required` | The feature needs a higher plan; see `upgrade_url` |
| 409 | `tos_version_stale` | Retry once with `current_version` |
| 429 | `rate_limit_error` | Wait for `Retry-After` |
| 429 | `quota_exceeded` | Monthly limit; don't retry in a loop |
| 503 | `anonymous_signup_disabled` | Use Path 1 |
| 503 | `anonymous_signup_capacity`, `signups_paused` | Try later; see `Retry-After` if present |
