Guidance for AI coding agents working with the BlockRun TypeScript SDK.
@blockrun/llm is a TypeScript SDK for pay-per-request access to AI models (GPT, Claude, Gemini, Grok) via x402 micropayments on Base and Solana.
Package: @blockrun/llm (npm)
Node: >=20
Networks: Base (EVM) and Solana
Payment: USDC via x402 v2
blockrun-llm-ts/
├── src/
│ ├── index.ts # Package exports
│ ├── client.ts # LLMClient class
│ ├── image.ts # Image generation
│ ├── openai-compat.ts # OpenAI-compatible client wrapper
│ ├── types.ts # TypeScript interfaces
│ ├── validation.ts # Input validation
│ ├── wallet.ts # Wallet operations (Base + Solana)
│ └── x402.ts # x402 payment protocol
├── test/ # Vitest tests
├── dist/ # Build output (generated)
├── package.json
├── tsconfig.json
└── README.md
# Install
pnpm install
# Build
pnpm build # Build with tsup (CJS + ESM + types)
pnpm dev # Build in watch mode
# Testing
pnpm test # Run tests in watch mode
pnpm test run # Run tests once
pnpm test -- --coverage # With coverage
# Code Quality
pnpm lint # ESLint
pnpm typecheck # TypeScript check- Strict mode enabled
- Export types explicitly from
index.ts - Use
interfacefor objects,typefor unions - Full JSDoc comments for public APIs
- tsup bundler (CJS, ESM, and .d.ts output)
- Tree-shakeable exports
- Solana dependencies are optional
LLMClient- Main client classchat()- Simple chat methodchatCompletion()- Full OpenAI-compatible response- Automatic x402 payment handling
| File | Purpose |
|---|---|
client.ts |
Main LLMClient with chat(), chatCompletion(), listModels() |
x402.ts |
x402 payment protocol implementation |
wallet.ts |
Multi-network wallet support (Base via viem, Solana via @solana/web3.js) |
validation.ts |
Input validation for keys, URLs, parameters |
types.ts |
TypeScript interfaces for API |
openai-compat.ts |
OpenAI SDK compatible wrapper |
- Uses
viemfor signing - Environment:
BASE_CHAIN_WALLET_KEY
- Uses
@solana/web3.js(optional dependency) - Environment:
BLOCKRUN_SOLANA_KEY(base58) - Gasless transactions (facilitator pays fees)
pnpm test runRequires funded wallet:
export BASE_CHAIN_WALLET_KEY=0x...
pnpm test -- test/integrationpnpm build
npm publish --access public- Private keys never leave the machine
- HTTPS required for production
- Solana keys are base58 encoded
- Error messages are sanitized