Ask a large language model “what is 500 euros in yen?” and it will answer confidently – with a rate from its training data, months or years old, or simply made up. An exchange rate API for AI agents fixes that by letting the model fetch the current rate as a tool call. fxapi offers two ways in: a hosted currency MCP server that MCP-compatible clients such as Claude Code connect to in one command, and the plain REST API with an OpenAPI spec for function calling in any agent framework.
Why LLMs need live exchange rates
- Training data is frozen. Rates move daily; a model’s knowledge does not.
- Hallucinated numbers look real. “1 EUR ≈ 1.07 USD” sounds plausible whether or not it is current. Users can’t tell.
- Arithmetic is unreliable. Even with a correct rate, models can make multiplication and rounding errors on long numbers.
- Finance questions need provenance. “According to which rate, as of when?” is a fair question for any agent that touches money.
A tool call solves all four: the agent asks fxapi, gets a value with meta.last_updated_at, and – with /v1/convert – even gets the converted amount calculated server-side.
Option 1: the fxapi currency MCP server
The Model Context Protocol lets AI clients discover and call external tools in a standard way. fxapi runs a hosted MCP server – nothing to install or deploy:
- Endpoint:
https://api.fxapi.com/mcp(streamable HTTP) - Auth: your API key in the
apikeyheader. - Quota: each tool call counts like the equivalent REST request.
Claude Code setup
One command registers the server:
claude mcp add --transport http fxapi https://api.fxapi.com/mcp --header "apikey: YOUR_API_KEY"
JSON configuration
To share the server with your team through a project’s .mcp.json, reference the key from an environment variable instead of committing it:
{
"mcpServers": {
"fxapi": {
"type": "http",
"url": "https://api.fxapi.com/mcp",
"headers": {
"apikey": "${FXAPI_KEY}"
}
}
}
}
Claude Code expands ${FXAPI_KEY} from the environment. Other MCP clients that support remote HTTP servers with custom headers use a similar structure; check your client’s documentation. Full reference: MCP docs.
Available tools
| Tool | REST equivalent | Typical agent question | Plan |
|---|---|---|---|
getLatest | /v1/latest | “What’s the euro worth in dollars right now?” | All |
getHistorical | /v1/historical | “What was GBP/JPY on 2024-03-15?” | All |
getConvert | /v1/convert | “Convert 2,450 CHF to EUR.” | Basic+ |
getRange | /v1/range | “Chart USD/BRL over the last 6 months.” | Professional+ |
getFluctuation | /v1/fluctuation | “How much did the yen move last quarter?” | All |
getAverage | /v1/average | “Average EUR/USD for each month of 2025?” | All |
getCurrencies | /v1/currencies | “Which currency does Cabo Verde use?” | All |
getStatus | /v1/status | “How much quota is left?” | All |
More on the server on the fxapi MCP page.
Option 2: function calling with the REST API
If your agent framework doesn’t speak MCP, define the tools yourself. Most frameworks can also import tools from an OpenAPI document – fxapi publishes one at /docs/openapi.yaml.
Workflow
- Define a tool with a name, description and JSON schema for its parameters.
- Pass it to the model with the user’s message.
- Handle the tool call in your code: call fxapi with the
apikeyheader from your server. - Return the result – including
last_updated_at– to the model as the tool result. - Let the model answer, citing the rate and timestamp.
Example: tool definition and handler in Python
The tool definition below uses the name / description / input_schema shape of the Claude Messages API; other providers use a near-identical JSON schema format.
import os, requests
CONVERT_TOOL = {
"name": "convert_currency",
"description": (
"Convert an amount between currencies using fxapi mid-market reference rates. "
"Use for any question about current or past exchange rates. "
"Always report the rate timestamp in the answer."
),
"input_schema": {
"type": "object",
"properties": {
"amount": {"type": "number", "exclusiveMinimum": 0},
"from_currency": {"type": "string", "description": "ISO 4217 code, e.g. EUR"},
"to_currency": {"type": "string", "description": "ISO 4217 code, e.g. JPY"},
"date": {"type": "string", "description": "Optional past date, YYYY-MM-DD"},
},
"required": ["amount", "from_currency", "to_currency"],
},
}
def convert_currency(amount, from_currency, to_currency, date=None):
params = {
"base_currency": from_currency.upper(),
"currencies": to_currency.upper(),
"value": amount,
}
if date:
params["date"] = date
r = requests.get(
"https://api.fxapi.com/v1/convert",
headers={"apikey": os.environ["FXAPI_KEY"]},
params=params,
timeout=15,
)
if r.status_code != 200:
return {"error": f"fxapi HTTP {r.status_code}", "details": r.json().get("errors")}
body = r.json()
return {
"converted": body["data"][to_currency.upper()]["value"],
"rate_timestamp": body.get("meta", {}).get("last_updated_at", date),
"source": "fxapi.com mid-market reference rate",
}
/v1/convert requires Basic or higher. On the Free plan, call /v1/latest instead and do the multiplication in Python – not in the model. More in the Python guide.
Guardrails for currency answers
- Show the timestamp. Instruct the agent to state when the rate was taken: “1 EUR = 1.0850 USD (fxapi, 2026-10-08 09:31 UTC)”.
- Cite the rate, not just the result. Showing the rate used lets users verify the conversion.
- Compute in code, not in the model. Use
getConvertor your own handler for arithmetic; let the model explain. - Say what the rate is. fxapi returns mid-market reference rates. An agent should not present them as the price a bank or card will charge, and must not imply it can execute trades.
- Handle errors explicitly. Pass 422 validation messages back so the model can correct a currency code; on 429, tell the user instead of guessing a rate.
- Protect the key. Keep it in server-side environment variables. Paid plans support multiple keys, so give agents their own key and revoke it independently; Enterprise adds IP and URL whitelisting.
- Budget quota. Agents can loop. Check
getStatusor theX-RateLimit-Remaining-Quota-Monthheader and cap tool calls per conversation.
Connect your agent to live rates
The MCP server and the REST API work on every plan, so you can try both on the Free plan’s 300 monthly requests. Agents that convert amounts benefit from Basic’s getConvert; analysis agents that chart time series need Professional for getRange – see pricing. Create a free API key, run the claude mcp add command above, and ask your agent for today’s EUR/USD rate.
Everything on this page runs on the fxapi foreign exchange rates API: one key, 190+ currencies, data back to 1999.
Frequently asked questions
Why can't an LLM just answer exchange rate questions itself?
What is the fxapi MCP server?
https://api.fxapi.com/mcp (streamable HTTP). It exposes fxapi endpoints as tools such as getLatest, getHistorical and getConvert. Details on the MCP page.