GuideLast updated

How to trade with the xAI API

Short answer: The xAI API supports remote MCP tools: add {"type":"mcp","server_url":"https://api.openfinance.tech/agent/mcp","server_label":"openfinance"} to the tools array of a Responses API call. xAI connects to OpenFinance for you, so your app or bot can trade crypto, onchain stocks, forex, memecoins and Polymarket with Grok models.

MCP URL: https://api.openfinance.tech/agent/mcp · HTTP streamable · works with any MCP client · one URL, no SDK · no KYC · fund with a debit card.

Setup in 60 seconds: get your OpenFinance key and start trading all markets with the cheapest fees.

How xAI API connects to tools

xAI's Remote MCP Tools work in the xAI SDK, the OpenAI-compatible Responses API and the Speech-to-Speech API. Required: server_url, server_label. Optional: allowed_tools, authorization, headers (extra_headers in the native SDK). OpenAI's require_approval isn't supported, so add your own confirmation step.

Set up xAI API in under 60 seconds

  1. Get an xAI API key.
  2. Copy the request below.
  3. Swap in your OpenFinance key in headers.
  4. Restrict allowed_tools to quote tools while testing.
  5. Add a human-confirm step before order tools (xAI has no require_approval).
curl https://api.x.ai/v1/responses \
 -H "Authorization: Bearer $XAI_API_KEY" -H "Content-Type: application/json" \
 -d '{"model":"grok-4.7","input":"Long BTC 5x with $50",
 "tools":[{"type":"mcp","server_url":"https://api.openfinance.tech/agent/mcp",
 "server_label":"openfinance","headers":{"x-api-key":"open_xxxxx"}}]}'

Get your OpenFinance key at openfinance.tech (sidebar → External AI), then fund it with a debit card or crypto.

What xAI API can trade through OpenFinance

xAI API can trade crypto spot and leveraged perps on Hyperliquid, onchain stocks such as TSLA and NVDA, forex, Solana and Base memecoins, and Polymarket prediction markets, all with one OpenFinance key. The full market list is on the hub page.

Prompts to try in xAI API

  • API input: “Quote BTC perp funding and open interest.”
  • “Long BTC 5x with $50.”
  • “Chart TSLA and buy with 3x margin.”
  • “Buy $50 of NVDA.”
  • Voice bot (Speech-to-Speech): “Bet ten dollars on Polymarket election odds.”

FAQ

Grok app vs xAI API?
The Grok app uses connectors (see the Grok page). The API uses the mcp tool type in your code.

Is there an approval step?
No require_approval on xAI, so confirm orders in your own app before letting the model call order tools.

Can I limit tools?
Yes, allowed_tools (allowed_tool_names in the native SDK).

Does it work for voice?
xAI says remote MCP works in its Speech-to-Speech API, so you can build a voice trading bot.

Which transports?
Streamable HTTP and SSE; OpenFinance is Streamable HTTP.

Which model name?
Use a current Grok model from xAI's docs; grok-4.7 is the example in the docs.

Related

Sources: https://docs.x.ai/developers/tools/remote-mcp

Trading involves risk, especially with leverage and memecoins. Start small.