# Waffari auth.md

You are an agent. Waffari (https://waffari.com) supports **agentic registration** for its public read-only API: discover → register (anonymous) → exchange for an access_token → call the API → revoke when done. You can also skip all of this: the API works without any credential at a lower rate limit.

- Resource server: `https://waffari.com/api/public/v1` (prices from Egyptian online stores; GET only; no personal data)
- Authorization server: `https://waffari.com`
- Supported registration method: **anonymous** only. There is no user identity, no account, no email and no claim ceremony.

## Rate limits

| Access | Limit |
| --- | --- |
| No credential | 60 requests/minute per IP |
| With a bearer key | 300 requests/minute per key |
| Registration | 3 per hour per IP, plus a daily cap |

Above a limit you get HTTP 429. Please cache responses.

## Step 1 — Discover

```http
GET https://waffari.com/.well-known/oauth-protected-resource
GET https://waffari.com/.well-known/oauth-authorization-server
```

The authorization server metadata has an `agent_auth` block: `identity_endpoint` (= `register_uri`) is `https://waffari.com/agent/identity`, `identity_types_supported` is `["anonymous"]`, and `anonymous.credential_types_supported` is `["bearer"]`. A request with a bad or revoked key gets `401` with `WWW-Authenticate: Bearer resource_metadata="https://waffari.com/.well-known/oauth-protected-resource/api/public/v1"` (the API-specific copy of the metadata; its `resource` is the API base, while the root document's `resource` is the origin).

## Step 2 — Register (anonymous)

```http
POST https://waffari.com/agent/identity
Content-Type: application/json

{ "type": "anonymous", "name": "optional short agent name" }
```

Response (200):

```json
{
  "registration_id": "reg_...",
  "registration_type": "anonymous",
  "identity_assertion": "<service-signed JWT>",
  "assertion_expires": "<ISO date, 90 days>",
  "pre_claim_scopes": ["api.read"]
}
```

`identity_assertion` and `service_auth` registration types are not enabled (`400 identity_assertion_not_enabled` / `service_auth_not_enabled`). There is no claim step.

## Step 3 — Exchange the assertion

```http
POST https://waffari.com/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<identity_assertion>
```

```json
{ "access_token": "wfk_...", "token_type": "Bearer", "expires_in": 2592000, "scope": "api.read" }
```

The access_token lasts 30 days. When it expires, exchange the same assertion again; when the assertion expires (or you get `invalid_grant`), register again.

**Shortcut:** `POST https://waffari.com/api/public/v1/keys` with optional `{"name": "..."}` returns a non-expiring API key (`api_key`) in one step. It is shown once; Waffari stores only its hash.

## Step 4 — Use the access_token

```http
GET https://waffari.com/api/public/v1/search?q=washing%20machine
Authorization: Bearer wfk_...
```

Endpoints: `/search`, `/products/{id}`, `/prices`, `/prices/{type}`, `/gold`, `/health`. Full description: https://waffari.com/api/public/v1/openapi.json. Docs (Arabic and English): https://waffari.com/developers.

## Errors

| Error | Where | What to do |
| --- | --- | --- |
| `401 invalid_token` | API | Key is wrong, expired or revoked. Drop the header (anonymous) or get a new one. |
| `429` / `slow_down` | API, registration | Wait (`Retry-After`) and retry less often. |
| `invalid_grant` | `/oauth2/token` | Assertion invalid, expired or revoked: register again. |
| `unsupported_grant_type` | `/oauth2/token` | Only `urn:ietf:params:oauth:grant-type:jwt-bearer`. |

## Revocation

- Revoke an access_token or API key ([RFC 7009](https://datatracker.ietf.org/doc/html/rfc7009)): `POST https://waffari.com/oauth2/revoke` with `token=<key>` (always 200).
- Or: `DELETE https://waffari.com/api/public/v1/keys/self` with `Authorization: Bearer <key>`.
- A revoked key stops working within a minute. Waffari can also revoke keys that abuse the limits.

## Also

- API catalog (RFC 9727): https://waffari.com/.well-known/api-catalog
- Site guide for language models: https://waffari.com/llms.txt
- Every page is available as Markdown with `Accept: text/markdown`.
