agents icon indicating copy to clipboard operation
agents copied to clipboard

Add BlockRun integration for x402 USDC micropayments

Open 1bcMax opened this issue 2 weeks ago • 1 comments

Summary

This PR adds BlockRun as an alternative LLM provider, enabling Polymarket agents to pay for AI inference with USDC micropayments via the x402 protocol on Base.

What is BlockRun?

BlockRun is a crypto-native AI gateway that provides:

  • 31+ AI models - GPT-4, Claude, Gemini, and more through a single endpoint
  • No API keys - Agents pay directly with their wallet via x402
  • Pay-per-use - USDC micropayments on Base network
  • 0% markup - Same pricing as official APIs during beta

Changes

  • agents/connectors/blockrun.py - New connector with LangChain-compatible LLM provider
  • agents/application/executor.py - Updated to support BlockRun as alternative to OpenAI
  • .env.example - Added BlockRun configuration options
  • README.md - Added documentation for BlockRun setup and usage

Usage

from agents.application.executor import Executor

# Enable BlockRun via environment variable
# BLOCKRUN_ENABLED=true

# Or programmatically
executor = Executor(default_model='gpt-4o', use_blockrun=True)

# Use Claude instead of GPT
executor = Executor(default_model='claude-3-5-sonnet', use_blockrun=True)

Why This Matters for Polymarket Agents

  1. True Agent Autonomy - Agents pay for their own AI with their trading wallet
  2. No API Key Management - Eliminates credential handling for LLM access
  3. Model Flexibility - Switch between GPT-4, Claude, Gemini without changing providers
  4. Same Wallet - Use the same wallet for trading AND AI payments

Testing

The integration uses the existing LangChain ChatOpenAI class with BlockRun's OpenAI-compatible API, ensuring compatibility with all existing code paths.


Learn more: blockrun.ai | x402 Protocol


[!NOTE] Introduces BlockRun as an alternative LLM backend using x402 USDC micropayments and integrates it into the agent runtime.

  • New agents/connectors/blockrun.py: BlockRun client and LangChain-compatible BlockRunLLM, model mappings, and token limits
  • agents/application/executor.py: Adds use_blockrun flag (or BLOCKRUN_ENABLED) to switch between OpenAI and BlockRun; sets token limits via BlockRun helpers
  • .env.example: Adds BLOCKRUN_ENABLED, BLOCKRUN_WALLET_KEY, and BLOCKRUN_API_URL configuration
  • README.md: Setup/usage docs for BlockRun, model list, and examples
  • requirements.txt: Adds blockrun-llm dependency

Written by Cursor Bugbot for commit 183441d9be491601fd955808d0009fd0713468fb. This will update automatically on new commits. Configure here.

1bcMax avatar Dec 29 '25 03:12 1bcMax