> ## Documentation Index
> Fetch the complete documentation index at: https://haggles.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Spending Policies

> Server-enforced per-call, daily, monthly, host, and seller guardrails for autonomous AI agents.

Every buyer agent key (`hgk_<env>_...`) carries a server-enforced spending policy evaluated inside the same serializable transaction that locks `W_AVAIL`.

```mermaid theme={null}
flowchart TD
    REQ["POST /v1/payments (Bearer hgk_...)"] --> K1{"1. Key active & not expired?"}
    K1 -->|No| E1["401 key_revoked"]
    K1 -->|Yes| K2{"2. seller_id in allowed_sellers?"}
    K2 -->|No| E2["403 policy_violation (seller_not_allowed)"]
    K2 -->|Yes| K3{"3. URL host in allowed_hosts?"}
    K3 -->|No| E3["403 policy_violation (host_not_allowed)"]
    K3 -->|Yes| K4{"4. amount <= per_call_max?"}
    K4 -->|No| E4["403 policy_violation (per_call_max_exceeded)"]
    K4 -->|Yes| K5{"5. spent_today + amount <= daily_max?"}
    K5 -->|No| E5["403 policy_violation (daily_max_exceeded)"]
    K5 -->|Yes| K6{"6. spent_month + amount <= monthly_max?"}
    K6 -->|No| E6["403 policy_violation (monthly_max_exceeded)"]
    K6 -->|Yes| OK["Lock W_AVAIL -> W_HELD & Issue Ed25519 JWS Token"]
```

## Policy Evaluation Order (`SPEC.md` § 5.3)

| Order | Rule | Default | Error Code & Detail |
| - | - | - | - |
| 1 | Key status & `expires_at` | `active`, no expiry | `401 key_revoked` |
| 2 | `allowed_sellers` | `null` (any seller) | `403 policy_violation` (`seller_not_allowed`) |
| 3 | `allowed_hosts` | `null` (any host) | `403 policy_violation` (`host_not_allowed`) |
| 4 | `per_call_max` | `$0.10` | `403 policy_violation` (`per_call_max_exceeded`) |
| 5 | `daily_max` (UTC day) | `$5.00` | `403 policy_violation` (`daily_max_exceeded`) |
| 6 | `monthly_max` (UTC month) | `null` (unlimited) | `403 policy_violation` (`monthly_max_exceeded`) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.