# apifare for Mastra One prepaid, capped key for every API your agent needs, under hard caps and a kill switch. 1. Get a token: https://apifare.com/start?origin=page:integrations-mastra (shown once). 2. In your Mastra project, connect with MCPClient from @mastra/mcp and give its tools to an agent. The token is read from the APIPAY_TOKEN environment variable and sent as an Authorization header. ``` npm install @mastra/mcp@latest ``` ``` import { MCPClient } from '@mastra/mcp'; import { Agent } from '@mastra/core/agent'; const mcpClient = new MCPClient({ id: 'apifare', servers: { apifare: { url: new URL('https://apifare.com/mcp'), requestInit: { headers: { Authorization: `Bearer ${process.env.APIPAY_TOKEN}` }, }, }, }, }); const agent = new Agent({ id: 'assistant', name: 'Assistant', instructions: 'Use the available MCP tools to answer questions.', model: 'openai/gpt-5.6-sol', tools: await mcpClient.listTools(), }); const response = await agent.generate("What's the weather in London?"); console.log(response.text); await mcpClient.disconnect(); ``` Set APIPAY_TOKEN, then run it. Mastra prefixes tool names with the server name, so the tools appear as apifare_…. 3. Try it: "search the web for X", then "fetch a URL", then "what's the weather in London". 4. Caps and the kill switch are checked before dispatch. An empty balance returns HTTP 402 with a top-up link (see /errors.md). Prices: https://apifare.com/capabilities. Config checked against https://mastra.ai/docs/connections/mcp on 2026-09-13.