SDKs

cURL

Drive the x402 flow with raw HTTP — no SDK required.

Tael is just HTTP. Any client that can set a header can pay for a call, which makes it easy to test endpoints from the terminal.

1. Get the challenge

Call the resource with no payment. You get a 402 whose accepts[0] tells you exactly what to pay and to whom.

›_terminal
curl -i -X POST https://api.example.com/v1/ocr

HTTP/1.1 402 Payment Required
content-type: application/json

{
  "x402Version": 1,
  "accepts": [
    {
      "scheme": "exact",
      "network": "stellar-testnet",
      "maxAmountRequired": "0.02",
      "payTo": "G...",
      "asset": { "code": "USDC", "issuer": "G..." },
      "resource": "/v1/ocr"
    }
  ]
}

2. Build the proof

Sign a Stellar payment of maxAmountRequired USDC to payTo, put its XDR into the payment envelope, and base64-encode the JSON:

{ }X-PAYMENT (before encoding)
{
  "x402Version": 1,
  "scheme": "exact",
  "network": "stellar-testnet",
  "payload": { "transaction": "<signed XDR>" }
}
›_terminal
PAYMENT=$(printf '%s' "$ENVELOPE_JSON" | base64)
The signed transaction is produced with a Stellar wallet or the Stellar SDK. Tael verifies and settles it — it never holds your keys.

3. Send the payment

Retry the request with the X-PAYMENT header. Tael verifies it, runs the handler, and returns your result.

›_terminal
curl -i -X POST https://api.example.com/v1/ocr \
  -H "X-PAYMENT: $PAYMENT" \
  -H "content-type: application/json" \
  -d '{ "document_url": "https://example.com/invoice.pdf" }'

HTTP/1.1 200 OK
x-payment-response: <base64 receipt>

{ "text": "INVOICE #1042 ..." }

4. Read the receipt

The X-PAYMENT-RESPONSE header is a base64 receipt proving the payment settled — decode it to confirm the amount, payer, and transaction.

Building a real integration in code instead? The Node.js SDK handles the encoding and verification for you.