Skip to content

feat(providers): add BlockRun x402 micropayment provider#1294

Open
1bcMax wants to merge 6 commits into0xPlaygrounds:mainfrom
1bcMax:feat/blockrun-provider
Open

feat(providers): add BlockRun x402 micropayment provider#1294
1bcMax wants to merge 6 commits into0xPlaygrounds:mainfrom
1bcMax:feat/blockrun-provider

Conversation

@1bcMax
Copy link

@1bcMax 1bcMax commented Jan 21, 2026

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

  • No API keys: Uses wallet signatures for payment instead of traditional API keys
  • x402 Protocol: Implements HTTP 402 Payment Required flow with EIP-712 signed USDC authorizations
  • Multi-model access: Supports Claude, GPT-4o, Gemini, DeepSeek, Grok, and more through a single provider
  • Tool calling support: Full compatibility with Rig's tool/agent system

Files Changed

  • rig-core/src/providers/blockrun.rs - Main provider implementation (~1400 lines)
  • rig-core/src/providers/mod.rs - Added blockrun module export
  • rig-core/Cargo.toml - Added blockrun feature with crypto dependencies (sha3, k256, hex, rand)
  • rig-core/examples/agent_with_blockrun.rs - Example demonstrating usage

Usage Example

use rig::providers::blockrun::{self, CLAUDE_SONNET_4, GPT_4O, DEEPSEEK_CHAT};

// Create client from wallet private key (for signing payments)
let client = blockrun::Client::from_env(); // reads BLOCKRUN_WALLET_KEY

// Use any supported model
let agent = client
    .agent(CLAUDE_SONNET_4)
    .preamble("You are a helpful assistant.")
    .build();

let response = agent.prompt("Hello!").await?;

Alternative: If this PR is not merged, you can use BlockRun's fork directly:

[dependencies]
rig-core = { git = "https://github.com/BlockRunAI/rig", features = ["blockrun"] }

Test Results

Tested end-to-end with real x402 payments on Base mainnet:

Wallet address: 0x4069560641ec74acfc74ddec64181f588c64e3a7
Fund this address with USDC on Base to use BlockRun

=== Using Claude Sonnet 4 ===
Claude: X402 is a designation that could refer to various things depending on context...

=== Using GPT-4o ===
GPT-4o: The term "x402" does not have a universally recognized meaning...

=== Using DeepSeek (cost-effective) ===
DeepSeek: x402 is a proposed extension to the email protocol designed to enhance security...

=== Calculator Agent with Tools ===
Calculator: I'll calculate (15 + 7) * 3 step by step.
Therefore, (15 + 7) * 3 = 66.

On-Chain Transaction Proof (Base Mainnet)

All payments settled on Base via TransferWithAuthorization (x402 protocol):

Model Amount Transaction
Claude Sonnet 4 0.016239 USDC 0x6b2e42f5341...
GPT-4o 0.010821 USDC 0x2ebec29ef5b...
DeepSeek 0.001 USDC 0xb960c54e34...
Calculator (tools) 0.01621 USDC 0xf1a5c8318c1...

Wallet: 0x4069560641ec74acfc74ddec64181f588c64e3a7

Test plan

  • Unit tests pass (address derivation, payment parsing, response parsing)
  • End-to-end test with Claude Sonnet 4
  • End-to-end test with GPT-4o
  • End-to-end test with DeepSeek
  • Tool calling test with calculator agent
  • On-chain payment verification on Base
  • Streaming test (implemented but not tested in this run)

Breaking Changes

None - this is an additive change behind a feature flag.

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
1bcMax added a commit to 1bcMax/rig that referenced this pull request Jan 21, 2026
- 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
@1bcMax 1bcMax force-pushed the feat/blockrun-provider branch from c2caf45 to 129d389 Compare January 21, 2026 19:15
- 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
1bcMax added a commit to BlockRunAI/rig that referenced this pull request Jan 21, 2026
- 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
@joshua-mo-143
Copy link
Collaborator

Hi, please add this as an integration under rig-integrations rather than adding it to rig-core - we're looking to keep the primary crate lean at the moment and it looks like there are extra dependency requirements required for this to work

Copy link
Collaborator

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@1bcMax
Copy link
Author

1bcMax commented Jan 22, 2026

Thanks for the review feedback! I've addressed both items:

  1. Removed rig/README.md - Deleted as requested

  2. Moved BlockRun provider to rig-integrations - Restructured as a standalone crate at rig-integrations/rig-blockrun/, following the pattern of other integration crates like rig-eternalai

The new structure:

rig-integrations/rig-blockrun/
├── Cargo.toml
├── README.md
├── src/
│   ├── lib.rs
│   └── json_utils.rs
└── examples/
    └── agent_with_blockrun.rs

All changes to rig-core have been reverted to keep the primary crate lean. The code compiles cleanly.

@1bcMax
Copy link
Author

1bcMax commented Jan 22, 2026

@joshua-mo-143 Please let me know what else you want me to do, love to this get into the main branch.. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants