AgentFlare

Guides · For agent developers · Beginner

Getting Started with HTTP 402 Pay-Per-Crawl

An HTTP 402 from an AISA-protected site means the content is for sale, not blocked. Register, get a crawler token, retry the original URL with X-Crawler-Token, then branch on 200, 402 or 403.

LevelBeginner
Reading time6 min
Steps55 with code
Sources5primary docs
✓ Open accessFree

You're reading the full report — free for humans. The machine-readable dataset for this section is open to all agents too — no payment required.

⚡ Agents: fetch .data.json → agents: allowed (no charge) · verify at https://esa.aisa.one/api/v1/access/verify

This guide is for developers building crawlers or AI agents that hit a paywalled URL and receive HTTP 402 Payment Required. You will learn what that response means, how to register an AISA crawler account, where the crawler token comes from, how to retry the original URL with the right header, and how to read the outcome. By the end you can run one complete paid fetch and handle a 200, a 402 or a 403 in code without guessing what to do next.

How the flow works

For agent developersDrawn from the AISA agent and publisher documentation
Pay-per-crawl request flow: 1. Your agent to Publisher edge: GET file + X-Crawler-Token; 2. Publisher edge to AISA: authorize token against price rule; 3. AISA to Publisher edge: grant: deduct price once; 4. Publisher edge to Your agent: 200 content (+ charge receipt); 5. Publisher edge to Your agent: or 402 JSON: error + guidance; 6. Publisher edge to Your agent: or 403 access_blockedYour agentcrawler tokenPublisher edgeCDN gatewayAISAverify + balance1. GET file + X-Crawler-Token2. authorize token against price rule3. grant: deduct price once4. 200 content (+ charge receipt)5. or 402 JSON: error + guidance6. or 403 access_blocked

Before you start

  • curl and Python with the requests library installed
  • An email address and password for a crawler account
  • A paywalled publisher URL that returned HTTP 402

Step by step

  1. Recognize what the 402 means

    A 402 from an AISA-protected site is a standard payment signal, not a block. The edge found no valid crawler token, so it answered instead of serving the content. The JSON body carries error set to invalid_token and an onboarding link. The credential you need is sent in the X-Crawler-Token header, which replaces the earlier name X-AISA-Crawler-Token.

    http
    GET https://agentflare.org/markets/index.data.json
    
    HTTP/1.1 402 Payment Required
    Content-Type: application/json
    Cache-Control: no-cache, no-store
    X-Tengine-Error: payment required by http_crawler
  2. Register and save the crawler token

    Call POST /api/agent/auth/register with email, password, and optionally name and crawlerType (custom by default). The response holds crawler.crawlerToken, in the format aisa_crawler_ followed by 64 hex characters, plus a session token in token. Keep the two apart: the crawler token is for crawling, the session token is only for account APIs. Never log the full token.

    python
    import requests
    
    BASE = 'https://cdn.aisa.one'
    r = requests.post(BASE + '/api/agent/auth/register', json={
        'email': 'mybot@example.com',
        'password': 'AtLeast8Chars',
        'name': 'My Crawler',
        'crawlerType': 'custom',
    })
    data = r.json()
    token = data['crawler']['crawlerToken']
    session = data['token']
    print(token[:18] + '...')
    print(data['crawler']['balance'])
    print(data.get('signupBonus'))
  3. Check the balance and top up

    New accounts may receive a trial credit, shown in signupBonus; if present, go straight to the fetch. Otherwise read the live balance with GET /api/agent/balance using your crawler token, then request a Stripe checkout URL with POST /api/agent/topup/create-session. The minimum is 0.50 USD. A person must open checkout_url and pay; an agent should hand the link to its user.

    python
    import requests
    
    BASE = 'https://cdn.aisa.one'
    token = 'YOUR_CRAWLER_TOKEN'
    session = 'YOUR_SESSION_TOKEN'
    
    bal = requests.get(BASE + '/api/agent/balance',
                       headers={'X-Crawler-Token': token})
    print(bal.json()['crawler']['balance'])
    
    r = requests.post(BASE + '/api/agent/topup/create-session',
                      headers={'Authorization': 'Bearer ' + session},
                      json={'amount': 5.00})
    print(r.json()['checkout_url'])
  4. Retry the original URL with your token

    Repeat the exact request that returned 402 and add one header, X-Crawler-Token. Also send your genuine User-Agent, because the gateway passes it through for crawler identification. The edge verifies the token, deducts the per-request price from your balance, and serves the content. Do not put the crawler token in Authorization: Bearer; that header is reserved for the gateway layer.

    bash
    curl 'https://PUBLISHER-SITE/research/report.data.json' \
      -H 'X-Crawler-Token: YOUR_CRAWLER_TOKEN' \
      -A 'MyBot/1.0 (+https://example.com/bot)'
  5. Read the outcome: 200, 402 or 403

    A 200 means content was delivered; on a paid resource the gateway may attach X-AISA-Charged and X-AISA-Charge-Amount receipt headers. A 402 carries an error code in the JSON body telling you what to fix, then retry. A 403 with access_blocked is a publisher policy: paying does not unlock it, so check the site's /pricing.json for purchasable directories instead.

    python
    import requests
    
    r = requests.get('https://PUBLISHER-SITE/research/report.data.json',
                     headers={'X-Crawler-Token': 'YOUR_CRAWLER_TOKEN',
                              'User-Agent': 'MyBot/1.0 (+https://example.com/bot)'})
    if r.status_code == 200:
        print(r.headers.get('X-AISA-Charged'),
              r.headers.get('X-AISA-Charge-Amount'))
    elif r.status_code == 402:
        body = r.json()
        print(body['error'], body.get('crawler'))
    elif r.status_code == 403:
        print('Blocked by publisher policy; try the pricing.json directories')

Denial responses and what to do

HTTPerrorMeaningYour action
402invalid_tokenNo, unknown or inactive crawler tokenRegister or fix the X-Crawler-Token header, retry the same URL
402insufficient_balanceBalance too low; crawler.shortfall gives the amount neededTop up, then retry
402price_requiredPrice discovery; quote is in price and currencyRetry with crawlerAutoPrice set to true (gateways usually do this)
402price_mismatchYour exact price intent did not match the quoteAdjust to the quoted price, or skip
402price_too_highYour maximum price was below the quoteAdjust to the quoted price, or skip
403access_blockedPublisher withholds this resource from crawlersDo not retry or top up; use the pay-mode directories in /pricing.json

Common pitfalls

  • Sending the crawler token in Authorization: Bearer makes the request count as unauthenticated and returns 402 invalid_token. Use X-Crawler-Token only.
  • Topping up or retrying a 403 access_blocked URL wastes effort: paying does not unlock it. Pivot to the site's pay-mode directories listed in /pricing.json.
  • Do not quote a remembered balance. Fetch it from GET /api/agent/balance before reporting, since spending makes any earlier value stale.
  • Never print the full crawler token in logs or reports; show only a prefix such as aisa_crawler_9a4d...

Key takeaways

  • A 402 is a price signal, not a block: register, fund, and retry the same URL with X-Crawler-Token.
  • Keep two credentials apart: the crawler token for crawling, the session token only for account APIs like top-up.
  • Branch on the status: 200 delivers content, 402 names a fixable error, 403 access_blocked cannot be bought.

FAQ

What does an HTTP 402 response mean for my crawler?

The content exists and is for sale. The edge found no valid crawler token or not enough balance, so it returned 402 instead of the content. Register, fund your balance, and retry with X-Crawler-Token.

Which header carries the crawler token?

X-Crawler-Token. It replaces the earlier name X-AISA-Crawler-Token, so new integrations should send X-Crawler-Token. Never send the token in Authorization: Bearer, which is reserved for the gateway layer.

Am I charged when a request is denied?

No. Denials never charge, and price discovery is free. A charge happens only on a granted fetch of a priced resource, at most once per request, and the price shows in rule.price of a 402.

How do I pay if I have no balance?

Use the signupBonus trial credit if the register response includes one. Otherwise call POST /api/agent/topup/create-session with your session token, minimum 0.50 USD, and give the checkout_url to a person to pay.

How this page is made. Written from 5 primary sources — the AISA agent and publisher documentation and AgentFlare's own files (pricing.json, robots.txt, llms.txt, live responses, .data.json field lists). Each step links the sources it relies on; steps naming a header, endpoint, error code or figure that the sources do not contain are removed. Refreshed weekly.

Sources & citations

  1. Header name: X-Crawler-Token esa.aisa.one
  2. AISA onboarding: HTTP 402 Payment Required esa.aisa.one
  3. AISA Agent Integration Guide — API reference esa.aisa.one
  4. Live capture: anonymous request to a paid AgentFlare file agentflare.org
  5. AISA pay-per-crawl platform overview (llms.txt) esa.aisa.one