Give a Mastra agent every BlockRun model through an OpenAI-compatible provider
Point an OpenAI-compatible AI SDK provider at the blockrun-litellm sidecar and a Mastra agent runs on any catalog model, with typed tools for images and search.
How it works
Mastra builds agents, workflows and tools on the Vercel AI SDK's model abstraction, so anything that yields an AI SDK model works as an agent's brain. An OpenAI-compatible provider created with a base URL pointing at the blockrun-litellm sidecar does, and the sidecar signs an x402 payment for each request from the server's wallet.
For tools, the @blockrun/llm TypeScript client is the shorter path: a Mastra tool that generates an image, runs a neural search or reads a prediction market is a typed call on the client, paid the same way. Agents and tools can mix — a frontier model for the agent, cheap calls for the tools.
Behind it is the BlockRun catalog: 78 chat models plus image, video, music and speech generation, search, market data and multi-chain RPC, priced per call. 6 open-weight models are free and need no wallet.
Setup
1. Start the sidecar
pip install 'blockrun-litellm[proxy]'\nexport BLOCKRUN_WALLET_KEY=0x<base wallet key>\nblockrun-litellm-proxy --port 40012. An OpenAI-compatible provider for the agent
import { createOpenAI } from "@ai-sdk/openai";
import { Agent } from "@mastra/core/agent";
const blockrun = createOpenAI({ baseURL: "http://127.0.0.1:4001/v1", apiKey: "dummy" });
export const agent = new Agent({ name: "researcher", instructions: "...", model: blockrun("openai/gpt-5.4") });Questions
- How do I use BlockRun models in a Mastra agent?
- Create an OpenAI-compatible AI SDK provider with the sidecar as its base URL and hand agent.model any catalog id, as in the setup. Mastra's agent loop, memory and workflows are unchanged.
- Can a Mastra tool call BlockRun for images or search?
- Yes. Call the @blockrun/llm client inside the tool's execute function; image, video, speech, neural search and market data are typed calls on the client.
- Does streaming work through the sidecar?
- Yes. The sidecar passes server-sent events through unchanged, so Mastra's streaming responses behave as they do against any OpenAI-compatible endpoint.
- Can different agents in one Mastra app use different models?
- Yes — each agent names its own catalog id through the same provider, and each call is priced for the model it used.
- Mastra on BlockRun vs Mastra with provider keys?
- Same framework. One wallet on the server replaces a key per provider, and a model switch is a string change rather than a new credential.
- What does a call cost through this integration?
- The provider's published token rate with no markup on tokens, plus a flat per-call fee, quoted in dollars in the 402 before the call runs. Image, video and speech calls are priced per unit the same way. The live rate card is on the models page.
- Do I need an API key or an account?
- No. On the pay-per-call door the request carries its own payment from a wallet the SDK or MCP server creates on first run; there is nothing to sign up for. Teams that prefer keys get an API key and a monthly invoice instead.