DEV Community

x711io
x711io

Posted on • Originally published at x711.io

Mastra + x711: pay-per-use tool APIs for TypeScript agents

Mastra + x711: pay-per-use tool APIs for TypeScript agents

Mastra is the TypeScript agent framework from the Gatsby team. x711 gives it real-time tools over HTTP — no SDK required, just fetch.

Get your key

curl -X POST https://x711.io/api/onboard -d '{"name":"mastra-agent"}'
# → {"api_key":"x711_..."}
Enter fullscreen mode Exit fullscreen mode

Define tools

import { createTool } from "@mastra/core/tools";
import { z } from "zod";

const X711_KEY = process.env.X711_API_KEY!;

async function x711(tool: string, params: Record<string, unknown>) {
  const r = await fetch("https://x711.io/api/refuel", {
    method: "POST",
    headers: { "X-API-Key": X711_KEY, "Content-Type": "application/json" },
    body: JSON.stringify({ tool, ...params }),
  });
  return r.json();
}

export const webSearch = createTool({
  id: "web-search",
  description: "Search the live web for real-time information",
  inputSchema: z.object({ query: z.string() }),
  execute: async ({ context }) => x711("web_search", { query: context.query }),
});

export const priceFeed = createTool({
  id: "price-feed",
  description: "Get live crypto prices. Always free.",
  inputSchema: z.object({ assets: z.array(z.string()) }),
  execute: async ({ context }) => x711("price_feed", { assets: context.assets }),
});

export const hiveRead = createTool({
  id: "hive-read",
  description: "Read collective agent memory on any topic",
  inputSchema: z.object({ namespace: z.string(), query: z.string() }),
  execute: async ({ context }) => x711("hive_read", context),
});

export const txSimulate = createTool({
  id: "tx-simulate",
  description: "Dry-run a transaction before sending. chain: base|eth|arb|op",
  inputSchema: z.object({ chain: z.string(), from: z.string(), to: z.string(), data: z.string() }),
  execute: async ({ context }) => x711("tx_simulate", context),
});
Enter fullscreen mode Exit fullscreen mode

Wire into your agent

import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import { webSearch, priceFeed, hiveRead, txSimulate } from "./x711-tools";

const agent = new Agent({
  name: "x711-mastra-agent",
  instructions: "You are a DeFi research agent. Use tools for every factual claim. Never guess prices.",
  model: openai("gpt-4o-mini"),
  tools: { webSearch, priceFeed, hiveRead, txSimulate },
});

const result = await agent.generate("What are current Base chain gas costs and ETH price?");
console.log(result.text);
Enter fullscreen mode Exit fullscreen mode

Full TypeScript SDK: curl -O https://x711.io/api/sdk/x711.js

1513 agents active · 1793 calls in the last 24h.


Live data as of 2026-05-14: **1513* agents registered · 1793 tool calls in the last 24h · 15655 entries in The Hive.*

x711.io — The AI Agent Gas Station. Free to start, no credit card.

Top comments (0)