Home Documentation Playground Pricing API Status Blog About FAQ Support

How to Use Exchange Rate APIs with AI Agents, LLMs, and Chatbots

Reviewed by Madhushan, Fintech Developer — May 2026

AI assistants are increasingly expected to answer questions about money: "How much is $500 in euros?", "What is the current GBP/JPY rate?", "Convert my invoice from CAD to USD." But large language models do not have access to live data. Their training data is frozen at a cutoff date, and exchange rates change every minute.

To give an AI agent accurate, real-time financial data, you need to connect it to a live exchange rate API. This article covers three practical approaches — MCP servers, function calling (tool use), and direct API integration — with working code examples using AllRatesToday.

Why AI Agents Need Live Exchange Rates

LLMs like Claude, GPT-4, and Gemini are trained on static datasets. When a user asks "What is the USD to EUR rate?", the model can only guess based on whatever rates appeared in its training data — which could be months or years out of date.

This is a problem for any application where accuracy matters:

The solution is to give the AI agent a tool it can call to fetch live rates from a reliable source. AllRatesToday provides real-time mid-market rates for 160+ currencies, updated every 60 seconds from Reuters/Refinitiv and interbank feeds.

Approach 1: MCP Servers

The Model Context Protocol (MCP) is an open standard that lets AI assistants discover and call external tools. Instead of writing custom glue code, you configure an MCP server and the AI assistant automatically gains access to its tools.

AllRatesToday provides an official MCP server: @allratestoday/mcp-server. It exposes exchange rate tools that Claude, Cursor, Windsurf, and other MCP-compatible clients can call directly.

Install the MCP server

npm install -g @allratestoday/mcp-server

Configure for Claude Code

Add the following to your Claude Code MCP configuration:

{
  "mcpServers": {
    "allratestoday": {
      "command": "npx",
      "args": ["-y", "@allratestoday/mcp-server"],
      "env": {
        "ALLRATESTODAY_API_KEY": "art_live_..."
      }
    }
  }
}

Configure for Cursor

In Cursor, open Settings and navigate to the MCP section. Add the server:

{
  "mcpServers": {
    "allratestoday": {
      "command": "npx",
      "args": ["-y", "@allratestoday/mcp-server"],
      "env": {
        "ALLRATESTODAY_API_KEY": "art_live_..."
      }
    }
  }
}

Once configured, you can ask Claude or Cursor questions like "What is the current EUR/USD rate?" or "Convert 5000 JPY to GBP" and the assistant will call the MCP server to fetch live data.

Available MCP tools

The AllRatesToday MCP server exposes the following tools:

Tool Description Parameters
get_rate Get the current exchange rate between two currencies source, target
convert Convert an amount from one currency to another source, target, amount
get_rates Get all available rates for a base currency source
get_historical_rates Get historical exchange rates for a date range source, target, from, to

npm: @allratestoday/mcp-serverView on GitHub

Approach 2: Function Calling (Tool Use)

If you are building with the OpenAI or Anthropic API directly, you can define exchange rate tools using function calling. The LLM decides when to call the tool, your code executes the API call, and the result is fed back into the conversation.

OpenAI function calling example

import openai
from allratestoday import AllRatesToday

art = AllRatesToday("art_live_...")
client = openai.OpenAI()

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_exchange_rate",
            "description": "Get the current exchange rate between two currencies. Use this whenever a user asks about currency conversion or exchange rates.",
            "parameters": {
                "type": "object",
                "properties": {
                    "source": {
                        "type": "string",
                        "description": "The source currency code (e.g. USD, EUR, GBP)"
                    },
                    "target": {
                        "type": "string",
                        "description": "The target currency code (e.g. EUR, JPY, CAD)"
                    }
                },
                "required": ["source", "target"]
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "convert_currency",
            "description": "Convert a specific amount from one currency to another using live exchange rates.",
            "parameters": {
                "type": "object",
                "properties": {
                    "source": {
                        "type": "string",
                        "description": "The source currency code"
                    },
                    "target": {
                        "type": "string",
                        "description": "The target currency code"
                    },
                    "amount": {
                        "type": "number",
                        "description": "The amount to convert"
                    }
                },
                "required": ["source", "target", "amount"]
            }
        }
    }
]

def handle_tool_call(tool_call):
    import json
    args = json.loads(tool_call.function.arguments)
    if tool_call.function.name == "get_exchange_rate":
        rate = art.get_rate(args["source"], args["target"])
        return json.dumps({"source": args["source"], "target": args["target"], "rate": rate})
    elif tool_call.function.name == "convert_currency":
        result = art.convert(args["source"], args["target"], args["amount"])
        return json.dumps(result)

# Send a message with tools
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "How much is 1000 USD in Japanese yen?"}],
    tools=tools,
)

# Process tool calls
if response.choices[0].message.tool_calls:
    tool_call = response.choices[0].message.tool_calls[0]
    result = handle_tool_call(tool_call)
    print(result)

Anthropic tool use example

import anthropic
from allratestoday import AllRatesToday

art = AllRatesToday("art_live_...")
client = anthropic.Anthropic()

tools = [
    {
        "name": "get_exchange_rate",
        "description": "Get the current exchange rate between two currencies. Use this whenever a user asks about currency conversion or exchange rates.",
        "input_schema": {
            "type": "object",
            "properties": {
                "source": {
                    "type": "string",
                    "description": "The source currency code (e.g. USD, EUR, GBP)"
                },
                "target": {
                    "type": "string",
                    "description": "The target currency code (e.g. EUR, JPY, CAD)"
                }
            },
            "required": ["source", "target"]
        }
    },
    {
        "name": "convert_currency",
        "description": "Convert a specific amount from one currency to another using live exchange rates.",
        "input_schema": {
            "type": "object",
            "properties": {
                "source": {
                    "type": "string",
                    "description": "The source currency code"
                },
                "target": {
                    "type": "string",
                    "description": "The target currency code"
                },
                "amount": {
                    "type": "number",
                    "description": "The amount to convert"
                }
            },
            "required": ["source", "target", "amount"]
        }
    }
]

response = client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Convert 2500 EUR to USD"}],
    tools=tools,
)

# Process tool use blocks
for block in response.content:
    if block.type == "tool_use":
        if block.name == "get_exchange_rate":
            rate = art.get_rate(block.input["source"], block.input["target"])
            print(f"Rate: {rate}")
        elif block.name == "convert_currency":
            result = art.convert(
                block.input["source"],
                block.input["target"],
                block.input["amount"]
            )
            print(f"Result: {result}")

Tip: Write clear, specific tool descriptions. Instead of "get rate", use "Get the current exchange rate between two currencies. Use this whenever a user asks about currency conversion or exchange rates." Better descriptions lead to more accurate tool invocations.

Approach 3: Direct API Calls for Custom Chatbots

If you are building a custom chatbot without a function-calling framework, you can call the AllRatesToday API directly in your application logic. This works well for rule-based bots, Slack/Discord integrations, or any backend service that needs exchange rate data.

JavaScript (Node.js)

import AllRatesToday from '@allratestoday/sdk';

const client = new AllRatesToday('art_live_...');

// In your chatbot message handler
async function handleCurrencyQuery(source, target, amount) {
  if (amount) {
    const result = await client.convert(source, target, amount);
    return `${amount} ${source} = ${result.result} ${target} (rate: ${result.rate})`;
  }

  const rate = await client.getRate(source, target);
  return `1 ${source} = ${rate} ${target}`;
}

// Example usage
const reply = await handleCurrencyQuery('USD', 'EUR', 1000);
console.log(reply);
// Output: 1000 USD = 923.40 EUR (rate: 0.9234)

Python

from allratestoday import AllRatesToday

client = AllRatesToday("art_live_...")

def handle_currency_query(source, target, amount=None):
    if amount:
        result = client.convert(source, target, amount)
        return f"{amount} {source} = {result['result']} {target} (rate: {result['rate']})"

    rate = client.get_rate(source, target)
    return f"1 {source} = {rate} {target}"

# Example usage
reply = handle_currency_query("GBP", "JPY", 500)
print(reply)
# Output: 500 GBP = 95250.00 JPY (rate: 190.50)

Raw API call

curl -X GET "https://allratestoday.com/api/v1/rates?source=USD&target=EUR" \
  -H "Authorization: Bearer art_live_..."
{
  "source": "USD",
  "target": "EUR",
  "rate": 0.9234,
  "time": "2026-05-25T12:00:00Z"
}

Use Cases

Customer support bots

An e-commerce support bot can automatically convert prices to a customer's local currency. When a user asks "How much does the Pro plan cost in BRL?", the bot fetches the live USD/BRL rate from AllRatesToday and responds with an accurate, up-to-the-minute conversion.

Financial analysis agents

AI-powered financial tools can pull historical and real-time exchange rates for portfolio analysis, FX exposure reports, and multi-currency reconciliation. The AllRatesToday API provides both current rates and historical data for trend analysis.

Travel planning assistants

A travel chatbot can calculate trip budgets across multiple currencies. "I have $3,000 for two weeks in Japan and Thailand" requires live USD/JPY and USD/THB rates to give a meaningful answer.

E-commerce price localization

AI agents embedded in e-commerce platforms can dynamically display prices in a visitor's currency. Combined with AllRatesToday's real-time rates, this ensures prices reflect current market conditions rather than stale daily snapshots.

Best Practices

Integration Comparison

Approach Best For Setup Effort LLM Required
MCP Server Claude Code, Cursor, AI IDEs Minimal (config only) MCP-compatible client
Function Calling Custom AI agents (OpenAI, Anthropic) Moderate (tool definitions) Yes (with tool use)
Direct API Rule-based bots, Slack/Discord, backends Minimal (SDK or HTTP) No

Quick Reference

Give Your AI Agent Real-Time Exchange Rates

Get your free API key and start integrating AllRatesToday with your AI agents, LLMs, and chatbots. 160+ currencies, real-time mid-market rates, official MCP server and SDKs.

Get Your Free API Key