Currency Converter API: The Complete Guide

Need to convert currencies in your application? This guide covers everything you need to know about currency conversion via API, including exchange rates, supported currencies, and implementation examples in multiple languages.

What is Currency Conversion?

Currency conversion is the process of exchanging one currency for another based on the current exchange rate. Exchange rates fluctuate constantly based on market conditions, making real-time conversion APIs essential for accurate pricing.

Currency conversion is crucial for international e-commerce, travel apps, financial services, and any application serving a global audience.

Understanding Exchange Rates

Exchange rates can be expressed in two ways:

Direct Quote

How much domestic currency is needed to buy one unit of foreign currency. Example: 1 EUR = 1.10 USD.

Indirect Quote

How much foreign currency can be bought with one unit of domestic currency. Example: 1 USD = 0.91 EUR.

Note: Exchange rates from TinyFn are updated regularly and suitable for informational and e-commerce purposes. For financial trading, use specialized forex APIs.

Using the Currency Converter API

TinyFn provides a comprehensive endpoint for currency conversion:

API Request
GET https://api.tinyfn.io/v1/convert/currency
Headers: X-API-Key: your-api-key
Response
{
  "from": "USD",
  "to": "EUR",
  "amount": 100,
  "rate": 0.92,
  "result": 92,
  "timestamp": "2024-01-15T12:00:00Z"
}

Parameters

Parameter Type Description
from string Source currency code (e.g., "USD")
to string Target currency code (e.g., "EUR")
amount number Amount to convert

Supported Currencies

The API supports 150+ currencies including USD, EUR, GBP, JPY, CNY, INR, AUD, CAD, CHF, and many more.

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/convert/currency?from=USD&to=EUR&amount=100',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.result); // 92
console.log(data.rate); // 0.92

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/convert/currency',
    params={'from': 'USD', 'to': 'EUR', 'amount': 100},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['result'])  # 92

cURL

curl "https://api.tinyfn.io/v1/convert/currency?from=USD&to=EUR&amount=100" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • E-commerce: Display prices in customer's local currency
  • Travel Apps: Convert expenses between currencies
  • Financial Dashboards: Show portfolio values in different currencies
  • Invoicing: Generate invoices in multiple currencies
  • Price Comparison: Compare prices across international markets

Best Practices

  1. Cache rates: Cache exchange rates for short periods to reduce API calls
  2. Show timestamps: Display when rates were last updated
  3. Handle rounding: Use appropriate decimal places for each currency
  4. Validate codes: Verify currency codes before making requests

Try the Currency Converter API

Get your free API key and start converting currencies in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key