feat(providers): add BlockRun x402 micropayment provider#1294
feat(providers): add BlockRun x402 micropayment provider#12941bcMax wants to merge 6 commits into0xPlaygrounds:mainfrom
Conversation
BlockRun enables pay-per-request access to 30+ AI models via x402 micropayments.
Users pay with USDC on Base - no API keys needed, just a funded wallet.
Features:
- Full x402 v2 protocol implementation with EIP-712 signing
- Support for all major model providers via BlockRun:
- Anthropic (Claude Sonnet 4, Opus 4, Haiku 3.5)
- OpenAI (GPT-4o, GPT-4o-mini, o1, o3-mini)
- Google (Gemini 2.0 Flash, Gemini 2.5 Pro)
- DeepSeek (Chat, Reasoner)
- xAI (Grok 2, Grok 3)
- Streaming support
- Tool calling support
- Complete test coverage
Usage:
```rust
use rig::providers::blockrun;
let client = blockrun::Client::from_env(); // reads BLOCKRUN_PRIVATE_KEY
let agent = client.agent(blockrun::CLAUDE_SONNET_4).build();
let response = agent.prompt("Hello!").await?;
```
Rig's HTTP client abstraction treats 402 responses as errors before the x402 payment flow can intercept them. Fixed by using reqwest directly for the initial request to properly handle the 402 response and extract payment headers. Changes: - Use reqwest::Client for initial request to handle 402 status - Parse payment requirements from x-payment-required header - Sign EIP-712 authorization and retry with payment header - Removed unused bytes::Bytes import Tested end-to-end with real x402 payments: - Claude Sonnet 4: ✓ - GPT-4o: ✓ - DeepSeek: ✓ - Tool calling: ✓
…ider feat(providers): add BlockRun x402 micropayment provider
- Add comprehensive documentation for BlockRun x402 micropayment provider - Include on-chain transaction proof with Base mainnet transactions - Add latency benchmarks for Claude, GPT-4o, DeepSeek - Document all available models (30+ across providers) - Add quick start guide and tool usage examples - Reference upstream PR 0xPlaygrounds#1294
- Add comprehensive documentation for BlockRun x402 micropayment provider - Include on-chain transaction proof with Base mainnet transactions - Add latency benchmarks for Claude, GPT-4o, DeepSeek - Document all available models (30+ across providers) - Add quick start guide and tool usage examples - Reference upstream PR 0xPlaygrounds#1294
c2caf45 to
129d389
Compare
- Feature BlockRun pay-per-request at top of README - Add on-chain transaction proof table (Base mainnet) - Include latency benchmarks (~3-5s per model) - Document 30+ available models across providers - Link to upstream PR 0xPlaygrounds#1294
- Add BlockRun pay-per-request section at top of README - Include on-chain transaction proof table (Base mainnet) - Add latency benchmarks (~3-5s per model) - Document 30+ available models across all providers - Link to upstream PR 0xPlaygrounds#1294
|
Hi, please add this as an integration under |
joshua-mo-143
left a comment
There was a problem hiding this comment.
please remove the newly created README file
Addresses PR review feedback: - Moved BlockRun provider to rig-integrations/rig-blockrun crate - Removed BlockRun additions from rig-core (keeps primary crate lean) - Deleted rig/README.md as requested - Restructured as standalone integration crate (like rig-eternalai) - Added local json_utils module to avoid private dependencies
|
Thanks for the review feedback! I've addressed both items:
The new structure: All changes to |
|
@joshua-mo-143 Please let me know what else you want me to do, love to this get into the main branch.. Thank you |
Summary
Add BlockRun as a new provider for Rig. BlockRun offers pay-per-request access to 30+ AI models via x402 micropayments - no API keys needed, just a funded wallet with USDC on Base.
Key Features
Files Changed
rig-core/src/providers/blockrun.rs- Main provider implementation (~1400 lines)rig-core/src/providers/mod.rs- Added blockrun module exportrig-core/Cargo.toml- Addedblockrunfeature with crypto dependencies (sha3, k256, hex, rand)rig-core/examples/agent_with_blockrun.rs- Example demonstrating usageUsage Example
Alternative: If this PR is not merged, you can use BlockRun's fork directly:
Test Results
Tested end-to-end with real x402 payments on Base mainnet:
On-Chain Transaction Proof (Base Mainnet)
All payments settled on Base via TransferWithAuthorization (x402 protocol):
Wallet: 0x4069560641ec74acfc74ddec64181f588c64e3a7
Test plan
Breaking Changes
None - this is an additive change behind a feature flag.