# For AI agents: run the free scan
The complete flow for an AI agent preparing and following a SiBear free scan for a person. If you are an AI agent, read the rules first.

## Rules

- **Three things are the person's, always:** pressing "Approve and start" (the authorization), passing the bot check, and confirming their email. Never do, simulate or try to work around any of them. The terms say scripts, bots and AI agents must not accept for the person or tick the box.
- The person gets **exactly one link** to open. Hand them that link and nothing else to open, except what the ownership step needs when you cannot do it yourself (see step 5).
- **Test key:** use a key made only for the test. Read it from an environment variable or a file (`$SIBEAR_TEST_KEY` below); never type it into a prompt, print it or log it. SiBear stores it encrypted, deletes it when the person submits, and never returns it.
- Send a descriptive `User-Agent` on every request, for example `sibear-client/1.0 (+https://sibearsecurity.com/docs)`. The default Python `urllib` user agent is blocked by Cloudflare (error 1010); see [Limits and errors](/docs/limits-and-errors).
- Base URL: `https://sibearsecurity.com/v1`. Machine-readable description: [/openapi.json](/openapi.json).
- Never put the prefill `token` or the `owner_token` in a URL. Never retry a 422 blindly: invalid requests spend the rate-limit budget.
- Use example.com style placeholders in anything you show or store; use the person's real details only in the requests.

## Set up

```sh
BASE=https://sibearsecurity.com/v1
UA='sibear-client/1.0 (+https://sibearsecurity.com/docs)'
# SIBEAR_TEST_KEY is already in the environment; do not echo it.
```

## The flow

| Step | Who | What |
| --- | --- | --- |
| 1 | agent | Read the form wording (optional) |
| 2 | agent | Prepare the form, get the link and token |
| 3 | person | Opens the link: Approve and start, bot check, confirm email |
| 4 | agent | Poll the lookup until the email is confirmed |
| 5 | agent (or person) | Get the ownership proof and publish it |
| 6 | agent | Check the proof; the scan is queued |
| 7 | agent | Follow progress |
| 8 | agent | Fetch the results |

### 1. Read the form (optional)

```sh
curl -sS -A "$UA" "$BASE/intake/form"
```

Returns the form's wording and versions.

### 2. Prepare the form

`agent_url`, `test_key` and `email` are required; `name` and `company` are optional, and so is one API format (`api_preset`, `custom_json` or `api_sample`; see [API formats](/docs/api-formats)). Build the body from the environment so the key stays out of your command line history:

```sh
jq -n --arg key "$SIBEAR_TEST_KEY" \
  '{agent_url: "https://agent.example.com", test_key: $key, email: "you@example.com"}' |
curl -sS -A "$UA" -H 'Content-Type: application/json' -d @- "$BASE/prefilled-scan-requests"
```

Response `201`: `{"link": "...", "token": "...", "expires_at": "..."}`.

- `link` is for the person. **Nothing is emailed**: you hand it over.
- `token` is for you. Keep it (in memory or a private file), never in a URL, never show it to the person.
- The link is valid for 24 hours and works once.
- Each email address can have 3 forms prepared a day, and the route has a per-network limit; invalid requests count. See [Limits and errors](/docs/limits-and-errors#rate-limits).

### 3. Hand the person the link

Tell them, in plain words: open this one link; read the permission statement and press "Approve and start"; pass the bot check; then open the confirmation email sent to the address they typed and confirm it. Then keep going. You do not do any of those three things.

### 4. Wait for the person

```sh
curl -sS -A "$UA" -H 'Content-Type: application/json' \
  -d "{\"token\": \"$PREFILL_TOKEN\"}" "$BASE/prefilled-scan-requests/lookup"
```

Poll every 10 to 15 seconds, up to the link's 24 hours. Responses:

- `{"state": "pending", ...}`: the person has not submitted yet.
- `{"state": "submitted", "request_id": "...", "scan": {...}}`. `scan.state` is one of `awaiting_email_confirmation`, `awaiting_ownership_proof`, `ownership_verified` or `scan_started`; `scan.job_status` and, once the scan is queued, `scan.owner_token` come with it.
- `410 prefill_gone`: the link is unknown or expired. Prepare a new form.

Keep waiting while `scan.state` is `awaiting_email_confirmation`. You can also read `GET $BASE/scan-requests/{request_id}` for the request's state. Calling the ownership route before the email is confirmed returns `409 email_not_confirmed`.

### 5. Get the ownership proof

Once `scan.state` is `awaiting_ownership_proof`:

```sh
curl -sS -X POST -A "$UA" "$BASE/scan-requests/$REQUEST_ID/ownership"
```

The response carries an ownership token with two ways to prove the agent is the person's:

- `dns`: a TXT record to add to the agent's domain.
- `file`: a file to serve at a given path on the agent's host.

`recommended_method` says which to try first: `file` where the host has no DNS you could edit (a temporary tunnel such as `*.trycloudflare.com`, or an IP address), `dns` everywhere else. Either one still verifies.

If you control the host, publish the proof yourself (that is a write to the person's own system: do it only if they asked you to run the scan end to end). Otherwise tell the person exactly what to add. If `ownership.attestation` is non-null, the agent runs on a named platform, and the person's security team has to attest that testing is allowed. That is a person-only step: tell them and wait.

### 6. Check the proof

```sh
curl -sS -X POST -A "$UA" -H 'Content-Type: application/json' \
  -d '{"method": "dns"}' "$BASE/scan-requests/$REQUEST_ID/ownership/check"
```

`method` is `dns`, `file`, or `attestation` for platform agents. Response `200`: `{verified, reason, method, scan, owner_token, refusal, token_expires_at}`; `method` is the method that was checked (the one that proved it, when `verified`).

- `verified: false` with `reason: "not_found"`: the proof is not visible yet (DNS can take a while). Keep waiting and check again, with **at least 5 seconds between checks**, or you get `429 check_throttled`.
- `agent_redirects`: the agent's address redirects elsewhere; use the final address.
- `scan: "started"`: the scan is queued and the response carries `owner_token`. **This is the only time the response carries it.** Store it privately now.
- `scan: "not_allowed"` with `refusal.limit` (`domain`, `email` or `network`) and `refusal.next_free_scan`: a free scan was already used this month. Tell the person when the next one is free.

### Owner token and replay

The owner token opens the scan's status and results. Treat it like a password: send it only as `Authorization: Bearer <owner_token>`, never in a URL, never in the chat. If the check response was lost, the same token comes back for 24 hours after the scan was queued from the prefill lookup (`scan.owner_token`), to whoever holds the prefill token.

### 7. Follow progress

```sh
curl -sS -A "$UA" -H "Authorization: Bearer $OWNER_TOKEN" \
  "$BASE/scans/$REQUEST_ID/status?wait=20"
```

`state` is `queued`, `running`, `paused`, `succeeded` or `failed`. `result_id` appears when the results are ready; `resume_at` says when a paused scan continues. While queued, `queue` gives the scans `ahead` and an `estimated_wait_s`. `waiting_for_target` means another run against the same host is going: runs against one host take turns. A failed scan carries `failure_code` and `failure_detail`.

**Long-poll:** `?wait=N` (0 to 25 seconds) holds the request until the scan has succeeded, failed or paused, or N seconds pass. Loop with `wait=20` instead of polling fast. Without `wait`, poll about every 15 seconds.

If `awaiting_credential` is set, the scan needs a fresh test key. Ask the person for one made for the test, then:

```sh
jq -n --arg key "$SIBEAR_TEST_KEY" '{test_key: $key}' |
curl -sS -X POST -A "$UA" -H "Authorization: Bearer $OWNER_TOKEN" \
  -H 'Content-Type: application/json' -d @- "$BASE/scans/$REQUEST_ID/credential"
```

The body is just `test_key`.

### 8. Fetch the results

```sh
curl -sS -A "$UA" -H "Authorization: Bearer $OWNER_TOKEN" "$BASE/results/$RESULT_ID"
curl -sS -A "$UA" -H "Authorization: Bearer $OWNER_TOKEN" -o report.pdf "$BASE/results/$RESULT_ID/export.pdf"
```

`/export.json` is the same data as a download. Summarize the findings for the person; do not paste the owner token into the summary. [Read the report](/docs/reading-the-report) explains the score, the check states and each finding's severity.

## Retry-After

Every `429` carries `Retry-After` in seconds. Wait at least that long before the same request; for a daily or monthly limit, tell the person instead of looping. All limits: [Limits and errors](/docs/limits-and-errors#rate-limits).

## What never to do

- Never accept the authorization, pass the bot check or confirm the email for the person; never ask them to hand those to you.
- Never post to the scan form route yourself: it answers `403 bot_check_failed` for anything but the person's browser. Use prepare and lookup.
- Never put tokens or the test key in URLs, logs or the chat.
- Never use a production key; never keep polling after a `410` or a refusal.
- Never run the scan against an agent the person does not own.

## If you are asked to run a paid Review

Ask the person for access once, with their email and the agent's address: one email, one press of Approve, and you get a scoped token ([Agent access](/docs/agent-access)). Then follow [Run a paid Review](/docs/paid-review). The three person-only steps of the free scan above are unchanged: a token never does them for the person.

Errors and fixes: [Limits and errors](/docs/limits-and-errors). Routes: [API reference](/docs/api).
