> ## Documentation Index
>
> Fetch the complete documentation index at: https://conciergeprotocol.org/llms.txt
> Use this file to discover all available pages before exploring further.
>
> Full text of every page: https://conciergeprotocol.org/llms-full.txt
> This page: https://conciergeprotocol.org/usage.md

# Usage

How to call CAP. The [specification](https://conciergeprotocol.org/spec.md) is the contract.

## 1. Find the agent

```
GET https://harborgoods.example/agent.txt
```

Use the file only if it has a `CAP` line.

```text
Protocol: CAP/1.0
Name: Harbor Goods
Chat: https://harborgoods.example/chat
CAP: https://harborgoods.example/cap/v1
OAuth: https://harborgoods.example/oauth
```

`CAP` is the base URL. A person uses `Chat` instead.

Point at the door from the homepage, including when `/agent.txt` is already valid:

```html
<link rel="agent" href="https://harborgoods.example/agent.txt">
```

In `llms.txt`, add one line: ask the company's agent at `/agent.txt`. A site may also list that file in `/.well-known/ai-catalog.json` with `type` `text/plain`, and repeat the entry in `/.well-known/ard.json` when it publishes that catalog.

A caller tries `/agent.txt` first and reads the homepage link only when that file is not a door. If the host cannot serve a file at the root, redirect `/agent.txt` to an https URL. The [specification](https://conciergeprotocol.org/spec.md#front-door) has the order.

## 2. Send a message

Every request carries:

```
CAP-Version: 1.0
CAP-From: agent:your-agent-id
```

```
POST /cap/v1/messages

{
  "message": "Running shoes in size 12, black sweatpants, and a black hoodie",
  "context": { "style": "minimal, no logos", "sizes": { "bottoms": "L", "tops": "L" } }
}
```

`context` is a short brief from what your agent knows about the person. Not their profile, and not the company's API payload.

To also get typed results, add `"accept": ["items"]`. A door that supports it adds `items` and `as_of` next to `reply`. The reply stays a complete answer without them. A price in `items` is what the page showed at `as_of`. It is not a hold. Checkout still uses a confirmation. The fields are in the [specification](https://conciergeprotocol.org/spec.md#structured-results).

If the answer is ready, the response is `200`:

```json
{
  "id": "msg_c1fac527668c6694",
  "status": "done",
  "reply": "Here is what fits:\n- Running shoes: Stride Runner, black, size 12 in stock, $120. https://harborgoods.example/p/stride-runner\n...",
  "created_at": "2026-10-15T17:09:09.620Z",
  "finished_at": "2026-10-15T17:09:09.621Z"
}
```

## 3. Follow up

To continue the conversation, send only the new text and the id of the last message:

```
POST /cap/v1/messages

{ "message": "Something cheaper?", "previous_message_id": "msg_c1fac527668c6694" }
```

The owner answers with every earlier turn in mind, including the brief you sent with them. Do not resend earlier turns. Keep the newest id and pass it on the next follow-up. Leave `previous_message_id` off to start a new conversation.

`404` means the previous message is gone or not yours. `409` means it is still `working`, or the thread is too long. Wait for it to finish, or start a new conversation.

## 4. Wait when it is still working

If the answer is not ready, the response is `202`:

```
202 Accepted
Location: /cap/v1/messages/msg_22eec828b542bf17
Retry-After: 5
```

```json
{ "id": "msg_22eec828b542bf17", "status": "working", "created_at": "2026-10-15T17:09:09.631Z", "finished_at": null }
```

Tell the person the company is still answering. Wait `Retry-After` seconds, then read it:

```
GET /cap/v1/messages/msg_22eec828b542bf17
```

Each `working` read sets a new `Retry-After`. Keep going until `done` or `failed`.

`Location` is always on the CAP URL's origin. If it, or any redirect, points at another origin, do not send your token or `CAP-From` there. Read `{CAP}/messages/{id}` instead.

Send `Idempotency-Key` when a resend after a dropped connection must not ask twice. The same key from the same `CAP-From`, with the same token or none, returns the original message.

## 5. Log in for account questions

Without a token, an account question fails:

```json
{
  "id": "msg_16dcccae07e01cce",
  "status": "failed",
  "error": { "code": "login_required", "message": "Log in to Harbor Goods to ask about your order." }
}
```

Your agent logs in with a code. It needs only HTTP: no browser, no callback URL, no secret, and no registration with the company.

1. Read the server's metadata. For `OAuth: https://harborgoods.example/oauth`, that is `GET https://harborgoods.example/.well-known/oauth-authorization-server/oauth`. Check that `issuer` equals the `OAuth` line and that `protected_resources` lists the `CAP` line exactly. If either check fails, stop: that server does not log people in for this door, and a token from it must never go to this CAP URL.
2. Start the login at its `device_authorization_endpoint`:

```
POST https://harborgoods.example/oauth/device
Content-Type: application/x-www-form-urlencoded

client_id=agent:your-agent-id&client_name=Example Assistant
```

The login reads by default. If the person wants changes made and the metadata lists `write` in `scopes_supported`, add `&scope=write`. The person can still allow read only.

```json
{
  "device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS",
  "user_code": "WDJB-MJHT",
  "verification_uri": "https://harborgoods.example/device",
  "verification_uri_complete": "https://harborgoods.example/device?user_code=WDJB-MJHT",
  "expires_in": 600,
  "interval": 5
}
```

3. Tell the person: "Open https://harborgoods.example/device?user_code=WDJB-MJHT and allow access. The code is WDJB-MJHT." Never show the `device_code`.
4. Every `interval` seconds, poll the token endpoint:

```
POST https://harborgoods.example/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=<device_code>&client_id=agent:your-agent-id
```

`authorization_pending` means keep polling. `slow_down` means add 5 seconds to the interval. `access_denied` and `expired_token` end the login. When the person allows it, the response is the token:

```json
{ "access_token": "cap_at_...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "cap_rt_...", "scope": "read" }
```

`scope` is what the person granted: `read`, or `read write`.

The token is bound to that account and to your `CAP-From`. The company's page shows your name as not verified, because anyone can claim a name. To show a verified name, use the URL of a client document, described below, as the `client_id` instead.

Store the token, and send the message again:

```
POST /cap/v1/messages
Authorization: Bearer <access token>
CAP-Version: 1.0
CAP-From: agent:your-agent-id

{ "message": "Where's my order?", "previous_message_id": "msg_16dcccae07e01cce" }
```

`previous_message_id` is optional here. It keeps the thread going after the login. A thread can gain a token, but it cannot continue without one or on another account.

Only the same `CAP-From` and the same token can read that message later.

When the access token expires, the request is `401`. Renew it with `grant_type=refresh_token&refresh_token=<refresh>&client_id=<client_id>` at the same token endpoint, using the same `client_id` you logged in with. You get a new refresh token, and the old one stops working. To log out, post `token=<token>&client_id=<client_id>` to the `revocation_endpoint`.

### Log in with a redirect

An owner may also offer a redirect login, when its metadata lists an `authorization_endpoint`. It suits agents that can open a browser and receive a callback.

**Once, for your agent:** host a client document at an https URL you control. That URL is your `client_id`.

```json
{
  "client_id": "https://assistant.example/cap-client.json",
  "client_name": "Example Assistant",
  "redirect_uris": ["https://assistant.example/cap/callback"],
  "cap_from": "agent:your-agent-id"
}
```

An agent that runs on the person's device can list `http://127.0.0.1/callback`. The company accepts it on any port.

**Each login:**

1. Read the server's metadata, as above.
2. Make a random `code_verifier`, and its `code_challenge`: base64url of its SHA-256.
3. Open the `authorization_endpoint` for the person:

```
https://harborgoods.example/oauth/authorize?response_type=code
  &client_id=https://assistant.example/cap-client.json
  &redirect_uri=https://assistant.example/cap/callback
  &state=<random>&code_challenge=<challenge>&code_challenge_method=S256
```

4. The person logs in on the company's page and allows access. The company redirects to your `redirect_uri` with `code`, `state`, and `iss`. Check that `state` is the one you sent.
5. Exchange the code:

```
POST https://harborgoods.example/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&client_id=<client_id>&code_verifier=<verifier>
```

The response is the same token, bound to the `cap_from` in your document. Send the message again, refresh, and log out as above.

## 6. Make changes, and confirm the risky ones

With a `read write` token, the company's agent can make changes for the person, within what the person could do themselves. With a `read` token, a change fails with a code such as `write_required`. Ask the person to log in again and allow changes.

An action that is hard to undo, such as a cancel, a delete, or a payment, does not run on the token alone. The message is `done`, and it carries a `confirmation`:

```json
{
  "id": "msg_5d0b8a1c2e7f4a90",
  "status": "done",
  "reply": "Cancel order hg_1042 (Stride Runner, $120). This needs your OK first: https://harborgoods.example/oauth/confirm?id=cfm_4kq...",
  "confirmation": {
    "id": "cfm_4kq...",
    "status": "pending",
    "url": "https://harborgoods.example/oauth/confirm?id=cfm_4kq...",
    "summary": "Cancel order hg_1042 (Stride Runner, $120).",
    "authorization_details": [{ "type": "cancel_order", "order": "hg_1042" }],
    "expires_at": "2026-10-17T18:10:00.000Z"
  }
}
```

1. Give the person `summary` and `url` as they are. Never say the action is done.
2. The person approves or denies on the company's page.
3. Read `GET /cap/v1/confirmations/{id}` with the same token and `CAP-From`, waiting `Retry-After` between reads, until `status` is `done`, `failed`, `denied`, or `expired`. `done` and `failed` carry `result.message`, written for the person.

```json
{ "id": "cfm_4kq...", "status": "done", "summary": "Cancel order hg_1042 (Stride Runner, $120).", "authorization_details": [{ "type": "cancel_order", "order": "hg_1042" }], "expires_at": "2026-10-17T18:10:00.000Z", "result": { "message": "Order hg_1042 is cancelled. The $120 refund goes back to your card in 3 to 5 days." } }
```

A request expires within 10 minutes if no one decides. To try again, send a new message.

A purchase works the same way. Its `authorization_details` entry has `type: "purchase"`, with `items`, `total`, and `currency`, so you can show the order as a checkout card. The person pays on the company's page. When it is `done`, `result.reference` is the order number. See [Purchases](https://conciergeprotocol.org/spec.md#purchases).

## Errors

A request the owner will not accept returns an HTTP error:

```json
{ "error": { "code": "rate_limited", "message": "Too many messages from this agent today." } }
```

`400` is a bad request or version. `401` is an invalid, expired, or revoked token. `403` is a token issued to a different agent. `404` is a message that does not exist, has expired, or is not yours. `409` is a follow-up to a message still `working`, or a thread that is too long. `429` and `503` set `Retry-After`.

## Client algorithm

```
res = POST {cap}/messages { message, context, previous_message_id: last_id }
if res is 409 or 404:
  res = POST {cap}/messages { message, context }   # start a new conversation
last_id = res.id
while res.status == working:
  tell the person the company is still answering
  wait res.retry_after
  res = GET {cap}/messages/{id}

if res.status == done and res.confirmation:
  give the person res.confirmation.summary and res.confirmation.url
  read {cap}/confirmations/{id} until it is no longer pending or working
  tell the person the result
elif res.status == done:
  use(res.reply)
elif res.error.code == login_required:
  ask the person to log in, then send again with the token
elif res.error.code == write_required:
  ask the person to log in again and allow changes
else:
  stop                     # failed is final for this message
```

## Conformance checklist

An **owner** conforms if it:

- [ ] Publishes `/agent.txt` starting with `Protocol: CAP/1.0`, with `Name`, `Ask`, `Chat`, `CAP`, and `OAuth` when it answers account questions
- [ ] Answers a `GET` on the CAP URL and on `{CAP}/messages` with `200` and the plain-text help, with no headers required
- [ ] Accepts a public question as `GET {CAP}/messages?from=agent:{id}&message=...`, reads it back with `?from=`, refuses a token on a `GET`, and asks a repeated `GET` once
- [ ] Returns `200` when it finished within its wait, otherwise `202` with `Location` on the CAP URL's origin and `Retry-After`
- [ ] Returns only `id`, `status`, `reply` or `error`, `created_at`, and `finished_at`, plus `confirmation` when it holds an action
- [ ] Answers account questions only with a token for that account. Returns `login_required` without one
- [ ] Returns `401` for a bad token, and `403` for a token used by a different agent
- [ ] Publishes OAuth metadata that lists its CAP URL in `protected_resources`, supports the code login with a `device_authorization_endpoint`, and binds each token to the `CAP-From` that logged in
- [ ] If it offers the redirect login, accepts a client id document in place of registration and requires PKCE with `S256`
- [ ] Shows a message only to the agent and token that sent it
- [ ] Returns the original message for a repeated `Idempotency-Key`
- [ ] Keeps its limits private, and returns `429` with `Retry-After`
- [ ] Keeps finished messages for at least 24 hours
- [ ] Answers a follow-up from its own record of the thread, and never from turns the caller sends
- [ ] Returns `404` for a `previous_message_id` the caller cannot read, or on a different account, and `409` while it is `working`

A **caller** conforms if it:

- [ ] Fetches `/agent.txt` and uses it only if it has a `CAP` line
- [ ] Never calls the owner's tools, MCP servers, or APIs
- [ ] Uses `reply` only when `done`
- [ ] Never invents a reply while `working`
- [ ] Waits at least `Retry-After` between reads
- [ ] Treats `failed` as final for that message
- [ ] Sends a short brief, never a password or another company's data
- [ ] Sets `previous_message_id` only to continue the same conversation
- [ ] Logs in only through the company's page, with the code login or the redirect login, never asks for the person's password, and never shows the `device_code`
- [ ] Gives the person a `confirmation` link as it is, and never reports a confirmed action as done until its status is `done`
- [ ] Logs in, and sends a token, only when the issuer's `protected_resources` lists the door's CAP URL, and never sends a token to a `Location` or redirect on another origin
