| Crates.io | x402-reqwest |
| lib.rs | x402-reqwest |
| version | 0.2.0 |
| created_at | 2025-06-17 20:44:50.195935+00 |
| updated_at | 2025-08-23 13:38:00.788395+00 |
| description | Wrapper for reqwest for transparent x402 payments |
| homepage | https://x402.rs |
| repository | https://github.com/x402-rs/x402-rs |
| max_upload_size | |
| id | 1716271 |
| size | 279,864 |
Wrapper around reqwest that transparently handles HTTP 402 Payment Required responses using the x402 protocol.
This crate enables your reqwest or reqwest-middleware-based HTTP clients to:
402 Payment Required responsesX-Payment header attachedAll in all: automatically pay for resources using the x402 protocol.
Built with reqwest-middleware and compatible with any alloy::Signer.
reqwest middlewarealloytelemetry feature)Add the dependency:
# Cargo.toml
x402-reqwest = "0.2"
To enable tracing:
x402-reqwest = { version = "0.2", features = ["telemetry"] }
use reqwest::Client;
use x402_reqwest::{ReqwestWithPayments, ReqwestWithPaymentsBuild, MaxTokenAmountFromAmount};
use alloy::signers::local::PrivateKeySigner;
use x402_rs::network::{Network, USDCDeployment};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let signer: PrivateKeySigner = "0x...".parse()?; // never hardcode real keys!
let client = Client::new()
.with_payments(signer)
.prefer(USDCDeployment::by_network(Network::Base))
.max(USDCDeployment::by_network(Network::Base).amount("1.00")?)
.build();
let res = client
.get("https://example.com/protected")
.send()
.await?;
println!("Status: {}", res.status());
Ok(())
}
See more examples on docs.rs
TransferWithAuthorization).X-Payment header.telemetry: Enables tracing annotations for richer observability.Enable it via:
x402-reqwest = { version = "0.2", features = ["telemetry"] }