# apifare for LlamaIndex 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-llamaindex (shown once). 2. Connect with BasicMCPClient, which sends your token as an Authorization header, and turn the server's tools into LlamaIndex tools with McpToolSpec. ``` pip install llama-index-tools-mcp llama-index-llms-openai ``` ``` import asyncio, os from llama_index.core.agent.workflow import FunctionAgent from llama_index.llms.openai import OpenAI from llama_index.tools.mcp import BasicMCPClient, McpToolSpec async def main(): client = BasicMCPClient( "https://apifare.com/mcp", headers={"Authorization": f"Bearer {os.environ['APIPAY_TOKEN']}"}, ) tools = await McpToolSpec(client=client).to_tool_list_async() agent = FunctionAgent( name="Agent", description="Agent with apifare tools", llm=OpenAI(model="gpt-4o"), tools=tools, system_prompt="You are a helpful assistant.", ) print(await agent.run("What's the weather in London?")) asyncio.run(main()) ``` Set APIPAY_TOKEN and OPENAI_API_KEY, then run it. For a local server instead, BasicMCPClient("npx", args=["-y", "apifare-mcp"], env={...}) takes the same token. 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://developers.llamaindex.ai/python/framework-api-reference/tools/mcp/ on 2026-09-13.