Pay-per-request access to GPT-4o, Claude 4, Gemini 2.5, and more via x402 micropayments on Base and Solana.
Networks:
- Base Mainnet: Chain ID 8453 - Production with real USDC
- Base Sepolia (Testnet): Chain ID 84532 - Developer testing with testnet USDC
- Solana Mainnet - Production with real USDC
Payment: USDC Protocol: x402 v2 (CDP Facilitator)
# Base and Solana support (optional Solana deps auto-installed) npm install @blockrun/llm # or pnpm add @blockrun/llm # or yarn add @blockrun/llm
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient(); // Uses BASE_CHAIN_WALLET_KEY (never sent to server) const response = await client.chat('openai/gpt-4o', 'Hello!');
That's it. The SDK handles x402 payment automatically.
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient({ network: 'solana' }); // Uses BLOCKRUN_SOLANA_KEY const response = await client.chat('openai/gpt-4o', 'Hello!');
For Solana, set BLOCKRUN_SOLANA_KEY environment variable with your base58-encoded Solana secret key.
- You send a request to BlockRun's API
- The API returns a 402 Payment Required with the price
- The SDK automatically signs a USDC payment on Base
- The request is retried with the payment proof
- You receive the AI response
Your private key never leaves your machine - it's only used for local signing.
| Model | Input Price | Output Price |
|---|---|---|
openai/gpt-5.2 |
1ドル.75/M | 14ドル.00/M |
openai/gpt-5 |
1ドル.25/M | 10ドル.00/M |
openai/gpt-5-mini |
0ドル.25/M | 2ドル.00/M |
openai/gpt-5-nano |
0ドル.05/M | 0ドル.40/M |
openai/gpt-5.2-pro |
21ドル.00/M | 168ドル.00/M |
| Model | Input Price | Output Price |
|---|---|---|
openai/gpt-4.1 |
2ドル.00/M | 8ドル.00/M |
openai/gpt-4.1-mini |
0ドル.40/M | 1ドル.60/M |
openai/gpt-4.1-nano |
0ドル.10/M | 0ドル.40/M |
openai/gpt-4o |
2ドル.50/M | 10ドル.00/M |
openai/gpt-4o-mini |
0ドル.15/M | 0ドル.60/M |
| Model | Input Price | Output Price |
|---|---|---|
openai/o1 |
15ドル.00/M | 60ドル.00/M |
openai/o1-mini |
1ドル.10/M | 4ドル.40/M |
openai/o3 |
2ドル.00/M | 8ドル.00/M |
openai/o3-mini |
1ドル.10/M | 4ドル.40/M |
openai/o4-mini |
1ドル.10/M | 4ドル.40/M |
| Model | Input Price | Output Price |
|---|---|---|
anthropic/claude-opus-4.5 |
5ドル.00/M | 25ドル.00/M |
anthropic/claude-opus-4 |
15ドル.00/M | 75ドル.00/M |
anthropic/claude-sonnet-4 |
3ドル.00/M | 15ドル.00/M |
anthropic/claude-haiku-4.5 |
1ドル.00/M | 5ドル.00/M |
| Model | Input Price | Output Price |
|---|---|---|
google/gemini-3-pro-preview |
2ドル.00/M | 12ドル.00/M |
google/gemini-2.5-pro |
1ドル.25/M | 10ドル.00/M |
google/gemini-2.5-flash |
0ドル.15/M | 0ドル.60/M |
| Model | Input Price | Output Price |
|---|---|---|
deepseek/deepseek-chat |
0ドル.28/M | 0ドル.42/M |
deepseek/deepseek-reasoner |
0ドル.28/M | 0ドル.42/M |
| Model | Input Price | Output Price | Context | Notes |
|---|---|---|---|---|
xai/grok-3 |
3ドル.00/M | 15ドル.00/M | 131K | Flagship |
xai/grok-3-fast |
5ドル.00/M | 25ドル.00/M | 131K | Tool calling optimized |
xai/grok-3-mini |
0ドル.30/M | 0ドル.50/M | 131K | Fast & affordable |
xai/grok-4-1-fast-reasoning |
0ドル.20/M | 0ドル.50/M | 2M | Latest, chain-of-thought |
xai/grok-4-1-fast-non-reasoning |
0ドル.20/M | 0ドル.50/M | 2M | Latest, direct response |
xai/grok-4-fast-reasoning |
0ドル.20/M | 0ドル.50/M | 2M | Step-by-step reasoning |
xai/grok-4-fast-non-reasoning |
0ドル.20/M | 0ドル.50/M | 2M | Quick responses |
xai/grok-code-fast-1 |
0ドル.20/M | 1ドル.50/M | 256K | Code generation |
xai/grok-4-0709 |
0ドル.20/M | 1ドル.50/M | 256K | Premium quality |
xai/grok-2-vision |
2ドル.00/M | 10ドル.00/M | 32K | Vision capabilities |
| Model | Input Price | Output Price |
|---|---|---|
moonshot/kimi-k2.5 |
0ドル.55/M | 2ドル.50/M |
| Model | Input Price | Output Price | Notes |
|---|---|---|---|
nvidia/gpt-oss-120b |
FREE | FREE | OpenAI open-weight 120B (Apache 2.0) |
nvidia/kimi-k2.5 |
0ドル.55/M | 2ドル.50/M | Moonshot 1T MoE with vision |
All models below have been tested end-to-end via the TypeScript SDK (Feb 2026):
| Provider | Model | Status |
|---|---|---|
| OpenAI | openai/gpt-4o-mini |
Passed |
| Anthropic | anthropic/claude-sonnet-4 |
Passed |
google/gemini-2.5-flash |
Passed | |
| DeepSeek | deepseek/deepseek-chat |
Passed |
| xAI | xai/grok-3-fast |
Passed |
| Moonshot | moonshot/kimi-k2.5 |
Passed |
| Model | Price |
|---|---|
openai/dall-e-3 |
0ドル.04-0.08/image |
openai/gpt-image-1 |
0ドル.02-0.04/image |
google/nano-banana |
0ドル.05/image |
google/nano-banana-pro |
0ドル.10-0.15/image |
black-forest/flux-1.1-pro |
0ドル.04/image |
| Model | Price |
|---|---|
openai/gpt-oss-20b |
0ドル.001/request |
openai/gpt-oss-120b |
0ドル.002/request |
Testnet models use flat pricing (no token counting) for simplicity.
For development and testing without real USDC, use the testnet:
import { testnetClient } from '@blockrun/llm'; // Create testnet client (uses Base Sepolia) const client = testnetClient({ privateKey: '0x...' }); // Chat with testnet model const response = await client.chat('openai/gpt-oss-20b', 'Hello!'); console.log(response); // Check if client is on testnet console.log(client.isTestnet()); // true
- Get testnet ETH from Alchemy Base Sepolia Faucet
- Get testnet USDC from Circle USDC Faucet
- Set your wallet key:
export BASE_CHAIN_WALLET_KEY=0x...
openai/gpt-oss-20b- 0ドル.001/request (flat price)openai/gpt-oss-120b- 0ドル.002/request (flat price)
import { LLMClient } from '@blockrun/llm'; // Or configure manually const client = new LLMClient({ privateKey: '0x...', apiUrl: 'https://testnet.blockrun.ai/api' }); const response = await client.chat('openai/gpt-oss-20b', 'Hello!');
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient(); // Uses BASE_CHAIN_WALLET_KEY (never sent to server) const response = await client.chat('openai/gpt-4o', 'Explain quantum computing'); console.log(response); // With system prompt const response2 = await client.chat('anthropic/claude-sonnet-4', 'Write a haiku', { system: 'You are a creative poet.', });
Save up to 78% on inference costs with intelligent model routing. ClawRouter uses a 14-dimension rule-based scoring algorithm to select the cheapest model that can handle your request (<1ms, 100% local).
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient(); // Auto-route to cheapest capable model const result = await client.smartChat('What is 2+2?'); console.log(result.response); // '4' console.log(result.model); // 'google/gemini-2.5-flash' console.log(result.routing.tier); // 'SIMPLE' console.log(`Saved ${(result.routing.savings * 100).toFixed(0)}%`); // 'Saved 78%' // Routing profiles const free = await client.smartChat('Hello!', { routingProfile: 'free' }); // Zero cost const eco = await client.smartChat('Explain AI', { routingProfile: 'eco' }); // Budget optimized const auto = await client.smartChat('Code review', { routingProfile: 'auto' }); // Balanced (default) const premium = await client.smartChat('Write a legal brief', { routingProfile: 'premium' }); // Best quality
Routing Profiles:
| Profile | Description | Best For |
|---|---|---|
free |
NVIDIA free models only | Testing, simple queries |
eco |
Budget-optimized | Cost-sensitive workloads |
auto |
Intelligent routing (default) | General use |
premium |
Best quality models | Critical tasks |
Tiers:
| Tier | Example Tasks | Typical Models |
|---|---|---|
| SIMPLE | Greetings, math, lookups | Gemini Flash, GPT-4o-mini |
| MEDIUM | Explanations, summaries | GPT-4o, Claude Sonnet |
| COMPLEX | Analysis, code generation | GPT-5.2, Claude Opus |
| REASONING | Multi-step logic, planning | o3, DeepSeek Reasoner |
import { LLMClient, type ChatMessage } from '@blockrun/llm'; const client = new LLMClient(); // Uses BASE_CHAIN_WALLET_KEY (never sent to server) const messages: ChatMessage[] = [ { role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'How do I read a file in Node.js?' }, ]; const result = await client.chatCompletion('openai/gpt-4o', messages); console.log(result.choices[0].message.content);
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient(); // Uses BASE_CHAIN_WALLET_KEY (never sent to server) const models = await client.listModels(); for (const model of models) { console.log(`${model.id}: $${model.inputPrice}/M input`); }
import { LLMClient } from '@blockrun/llm'; const client = new LLMClient(); // Uses BASE_CHAIN_WALLET_KEY (never sent to server) const [gpt, claude, gemini] = await Promise.all([ client.chat('openai/gpt-4o', 'What is 2+2?'), client.chat('anthropic/claude-sonnet-4', 'What is 3+3?'), client.chat('google/gemini-2.5-flash', 'What is 4+4?'), ]);
// Default: reads BASE_CHAIN_WALLET_KEY from environment const client = new LLMClient(); // Or pass options explicitly const client = new LLMClient({ privateKey: '0x...', // Your wallet key (never sent to server) apiUrl: 'https://blockrun.ai/api', // Optional timeout: 60000, // Optional (ms) });
| Variable | Description |
|---|---|
BASE_CHAIN_WALLET_KEY |
Your Base chain wallet private key (for Base) |
BLOCKRUN_SOLANA_KEY |
Your Solana wallet secret key - base58 (for Solana) |
BLOCKRUN_NETWORK |
Default network: base or solana (optional, default: base) |
BLOCKRUN_API_URL |
API endpoint (optional, default: https://blockrun.ai/api) |
import { LLMClient, APIError, PaymentError } from '@blockrun/llm'; const client = new LLMClient(); try { const response = await client.chat('openai/gpt-4o', 'Hello!'); } catch (error) { if (error instanceof PaymentError) { console.error('Payment failed - check USDC balance'); } else if (error instanceof APIError) { console.error(`API error: ${error.message}`); } }
Unit tests do not require API access or funded wallets:
npm test # Run tests in watch mode npm test run # Run tests once npm test -- --coverage # Run with coverage report
Integration tests call the production API and require:
- A funded Base wallet with USDC (1ドル+ recommended)
BASE_CHAIN_WALLET_KEYenvironment variable set- Estimated cost: ~0ドル.05 per test run
export BASE_CHAIN_WALLET_KEY=0x... npm test -- test/integration # Run integration tests only
Integration tests are automatically skipped if BASE_CHAIN_WALLET_KEY is not set.
- Create a wallet on Base (Coinbase Wallet, MetaMask, etc.)
- Get USDC on Base for API payments
- Export your private key and set as
BASE_CHAIN_WALLET_KEY
# .env
BASE_CHAIN_WALLET_KEY=0x...- Create a Solana wallet (Phantom, Backpack, Solflare, etc.)
- Get USDC on Solana for API payments
- Export your secret key and set as
BLOCKRUN_SOLANA_KEY
# .env
BLOCKRUN_SOLANA_KEY=...your_base58_secret_keyNote: Solana transactions are gasless for the user - the CDP facilitator pays for transaction fees.
- Private key stays local: Your key is only used for signing on your machine
- No custody: BlockRun never holds your funds
- Verify transactions: All payments are on-chain and verifiable
Private Key Management:
- Use environment variables, never hard-code keys
- Use dedicated wallets for API payments (separate from main holdings)
- Set spending limits by only funding payment wallets with small amounts
- Never commit
.envfiles to version control - Rotate keys periodically
Input Validation: The SDK validates all inputs before API requests:
- Private keys (format, length, valid hex)
- API URLs (HTTPS required for production, HTTP allowed for localhost)
- Model names and parameters (ranges for max_tokens, temperature, top_p)
Error Sanitization: API errors are automatically sanitized to prevent sensitive information leaks.
Monitoring:
const address = client.getWalletAddress(); console.log(`View transactions: https://basescan.org/address/${address}`);
Keep Updated:
npm update @blockrun/llm # Get security patchesFull TypeScript support with exported types:
import { LLMClient, testnetClient, type ChatMessage, type ChatResponse, type ChatOptions, type Model, // Smart routing types type SmartChatOptions, type SmartChatResponse, type RoutingDecision, type RoutingProfile, type RoutingTier, APIError, PaymentError, } from '@blockrun/llm';
MIT