• Welcome
  • API Reference
OverviewGetting StartedPay-per-use (x402)Data FormatsExamples
powered by Zudoku
Welcome

Pay-per-use (x402)

Overview

Most endpoints support pay per use through the x402 protocol. Pricing is dynamic based on the nubmer of days and locations in your request. For example, one day of hourly precipitation data for a single location is $0.002. The actual cost is determined by your request parameters and will be shown in the 402 Payment Required response before processing.

Authentication

Include the payment header with your requests:

Code
X-Payment: {{paymentHeader}}

The payment is automatically processed and verified before your request is fulfilled.


How x402 Works

The payment flow is handled automatically by the x402 SDK:

  1. Make Request - Send a request to the endpoint
  2. Payment Required - Server responds with payment requirements (402 status)
  3. Auto-Payment - SDK automatically creates and submits payment
  4. Get Response - Receive your API response

Getting Started

Install the x402 SDK for your language:

TerminalCode
# Node.js npm install x402-fetch viem # Python pip install x402 eth-account

Example Usage

Node.js

Code
import { wrapFetchWithPayment } from "x402-fetch"; import { privateKeyToAccount } from "viem/accounts"; const account = privateKeyToAccount(process.env.PRIVATE_KEY); const fetchWithPayment = wrapFetchWithPayment(fetch, account); // Make a paid request - payment is automatic const response = await fetchWithPayment( "https://api.precip.ai/x402/api/v1/last-48?longitude=-122.4194&latitude=37.7749", { method: "GET", } ); const result = await response.json(); console.log(result);

Python

Code
import requests from eth_account import Account from x402.clients.requests import x402_http_adapter account = Account.from_key(os.getenv("PRIVATE_KEY")) session = requests.Session() adapter = x402_http_adapter(account) session.mount("https://", adapter) # Make a paid request - payment is automatic response = session.get( "https://api.precip.ai/x402/api/v1/last-48?longitude=-122.4194&latitude=37.7749" ) print(response.json())

Learn More

  • x402 Protocol Docs
  • Coinbase x402 Guide

Powered by Orthogonal

Last modified on January 8, 2026
Getting StartedData Formats
On this page
  • Overview
  • Authentication
  • How x402 Works
  • Getting Started
  • Example Usage
  • Learn More
Javascript