# Ringing Bytes API: access for AI agents

Ringing Bytes checks images for signs of AI generation. This guide gets an agent an API key with a person's approval, then shows how to check images, read the account, and handle payment.

Rules: a person approves every agent; the API key is shown once; only a person can pay; agents cannot change or cancel plans.

## 1. Ask for access (device authorization, RFC 8628)

```sh
curl -s -X POST https://api.ringingbytes.com/v1/agent/device/code \
  -H 'content-type: application/json' \
  -d '{"client_name": "My research agent", "requested_scopes": ["checks:create","account:read"], "requested_monthly_cap_usd": 20}'
```

The answer has `device_code` (keep it secret), `user_code`, `verification_uri_complete`, `expires_in` (900 seconds) and `interval` (5 seconds).

Show the person `verification_uri_complete` and the `user_code`. They sign in (or sign up), check the code and the permissions, choose a monthly spending cap, and approve.

Permissions (`requested_scopes`; default: `checks:create`, `account:read`):
- `checks:create`: Check images and read the results of this organization's checks (uses the organization's image checks and may be billed).
- `account:read`: Read the organization's plan, remaining free and included image checks, and this key's spending.
- `billing:checkout`: Ask for a checkout link for a paid plan. The link is also emailed to the organization's owners; only a person can pay.

`client_name` is shown to the person: a short plain name (no links or email addresses, at most 60 characters). Limits: 10 requests per hour and 3 waiting requests per IP address.

## 2. Poll for the key

```sh
curl -s -X POST https://api.ringingbytes.com/v1/agent/device/token \
  -H 'content-type: application/json' \
  -d '{"grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": "<device_code>"}'
```

Poll no faster than `interval` seconds. Until the person decides, the answer is HTTP 400 with `error`:
- `authorization_pending`: keep polling.
- `slow_down`: add 5 seconds to your interval.
- `access_denied`: the person said no. Stop.
- `expired_token`: start again at step 1.
- `invalid_grant`: unknown code, or the key was already returned (it is returned once).

On approval (HTTP 200) you get `access_token` (the API key, also as `api_key`), `key_id`, `organization_id`, `scopes`, `free_checks_remaining` and `monthly_cap_usd`. Store the key now: it is never shown again.

## 3. Check an image

```sh
curl -s -X POST https://api.ringingbytes.com/v1/detect \
  -H 'authorization: Bearer <api key>' \
  -H 'content-type: application/json' \
  -d '{"url": "https://example.com/photo.jpg"}'
```

The result has `verdict` (`likely_ai`, `uncertain` or `likely_human`; `likely_human` means no AI signs were found, not proof the image is authentic), `confidence`, `signals` and `detector` (the detector release that produced it, today `tell-1`). Upload a file with multipart `file` instead of `url`. `localize: true` adds edited-region analysis and counts as 3 image checks; its heatmap comes inline in this response (`heatmap_png_base64` on the `edit_localization` signal).

Keep the result from this response: nothing is kept once the result is delivered. `GET /v1/detections/{id}` and `get_check` return the check as a usage entry (id, status, timestamps, what it was charged), never the verdict, signals, file name or image. The full rules: https://ringingbytes.com/docs/data-retention.

## 4. Read the account

```sh
curl -s https://api.ringingbytes.com/v1/account -H 'authorization: Bearer <api key>'
```

It returns the plan, `free_checks_remaining`, `included_checks`, the billing period, `can_run_checks`, this key's cap and spend (`api_key`), and the organization's cap and spend. Needs `account:read`.

## 5. When a check returns 402

Errors have one shape: `{ "code", "status", "message", "data" }`. A 402 has `code: "PAYMENT_REQUIRED"` and `data`:
- `reason`: `free_checks_exhausted`, `payment_failed`, `key_cap_reached` or `org_cap_reached`.
- `free_checks_remaining`, and `cap` for a cap.
- `next`: `action`, `who` (`agent_or_human` or `human`), `checkout_url`, `plans`, `pricing_url`, `dashboard_url`, `account_url`.

Only `free_checks_exhausted` can be solved with a checkout. The others need a person at `next.dashboard_url`. Prices: https://api.ringingbytes.com/pricing.md.

## 6. Ask for a checkout link

```sh
curl -s -X POST https://api.ringingbytes.com/v1/billing/checkout \
  -H 'authorization: Bearer <api key>' \
  -H 'content-type: application/json' \
  -d '{"plan": "payg"}'
```

Plan ids: `payg`, `pro`, `business`, `helpdesk_starter`, `helpdesk_growth`, `helpdesk_scale`. Needs `billing:checkout`. The answer is `{ "url", "expires_at", "plan", "emailed_to_owners", "owner_emails": { "owners", "sent" } }`; the same link is emailed to the organization's owners. `emailed_to_owners` is true only when every owner's email went out; failed emails are not retried. Give the link to your person either way; when they have paid, `GET https://api.ringingbytes.com/v1/account` shows the new plan. At most 5 links an hour. An organization that already has a plan gets 409 `SUBSCRIPTION_EXISTS`: plan changes are for a person in the dashboard.

## 7. MCP

The MCP server is at `https://api.ringingbytes.com/mcp` (Streamable HTTP). Send the same API key as `Authorization: Bearer <api key>`. Tools: `check_image`, `get_check`, `get_account`, `create_checkout_link`, with the same permissions, limits and errors as above.

With `localize: true`, `check_image` returns the edited-region heatmap in that same response as an image (MCP image content), and only there: it is not kept, and `get_check` never returns it.

```json
{
  "mcpServers": {
    "company": {
      "type": "http",
      "url": "https://api.ringingbytes.com/mcp",
      "headers": {
        "Authorization": "Bearer <api key>"
      }
    }
  }
}
```

## Errors without a key

A request without a valid key gets 401 with `WWW-Authenticate: Bearer resource_metadata="https://api.ringingbytes.com/.well-known/oauth-protected-resource"`. That document points to https://api.ringingbytes.com/.well-known/oauth-authorization-server, which lists the device authorization endpoint above. A key without the needed permission gets 403 `INSUFFICIENT_SCOPE`.

Rate limit: 120 requests per 60 seconds per organization (429 with `Retry-After`).
