Pay for Steel with x402
Beta
x402 lets you call Steel's Quick actions, Scrape, Screenshot and PDF, and pay for each request with USDC from a wallet. You need no Steel account and no API key. The x402 protocol uses the HTTP status 402 Payment Required to ask for a payment, and an x402 client library pays it for you.
Steel serves x402 requests at https://x402.steel.dev. Each request costs $0.01 in USDC (10000 base units), on the network that you pay from. There is no subscription and no charge for browser time. See Pricing for the other ways to pay.
Before you begin
- A wallet on Base or Solana that holds USDC.
- For the program on this page, Node.js and a Base wallet's private key in the
PRIVATE_KEYenvironment variable.
Steel accepts USDC on these networks:
| Network | USDC contract address |
|---|---|
| Base (mainnet) | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Solana (mainnet) | EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v |
Set up the integration
Payment flow
An x402 client library does steps 2 and 3 of a paid request for you:
- You send a request to an endpoint. Steel returns
402 Payment Required, with the amount, networks and recipient. - Your wallet signs a payment authorization for that amount.
- You send the request again with the signed payment in the
PAYMENT-SIGNATUREheader. Steel returns200 OKwith the result.
To see the payment details, send a request without a payment:
curl -i -X POST https://x402.steel.dev/v1/scrape \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "format": ["markdown"]}'The response has the status 402 Payment Required. Its JSON body lists the payment options in accepts, one on Base and one on Solana, each for 10000 base units of USDC. The PAYMENT-REQUIRED header has the same details, encoded in base64.
Pay for a request
This program pays for one scrape with x402 and prints the result.
import { ExactEvmScheme } from "@x402/evm";
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetchWithPay = wrapFetchWithPaymentFromConfig(fetch, {
schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
});
const response = await fetchWithPay("https://x402.steel.dev/v1/scrape", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: "https://example.com", format: ["markdown"] }),
});
console.log(response.status);
console.log(await response.json());It wraps fetch with @x402/fetch, so that it pays when Steel asks. Steel uses version 2 of the protocol. The older x402-fetch package is for version 1, and it cannot read Steel's response.
Install the libraries and run the program:
npm install @x402/fetch @x402/evm viem
npx tsx x402-scrape.mtsThe program prints 200, then the scrape result as JSON. Each run pays $0.01 in USDC from the wallet.
If the wallet does not hold enough USDC, the program prints 402 and a response with the error invalid_exact_evm_insufficient_balance.
Endpoints and parameters
Every endpoint takes a POST with a JSON body and returns JSON.
| Endpoint | What it does |
|---|---|
POST / | Loads a page and returns it as HTML, Markdown or readable text, with a screenshot or a PDF if you ask for one. |
POST / | Takes a screenshot of a page. |
POST / | Renders a page as a PDF. |
| Parameter | Type | Endpoints | Description |
|---|---|---|---|
url | string | All | The URL of the page to load. Required. |
format | string[] | Scrape | The output formats: html, readability, cleaned_html or markdown. The default is html. |
screenshot | boolean | Scrape | Adds a screenshot to the response. |
pdf | boolean | Scrape | Adds a PDF to the response. |
fullPage | boolean | Screenshot | Captures the full page, not only the visible part. |
delay | number | All | The time to wait before the action, in milliseconds. |
useProxy | boolean | All | Routes the request through a residential proxy from Steel. |