Live exchange rates in Google Sheets
Paste one Apps Script function into Google Sheets, then use =FXRATE("USD","EUR") to fetch a pair from exchangerate.dev. The example uses anonymous access, a ten-minute cache, and no secret stored in the spreadsheet.
Paste the function below into Extensions → Apps Script and enter =FXRATE("USD","EUR") in a cell. It calls the anonymous latest-rate endpoint and caches each pair for ten minutes. Anonymous access is capped at 12 requests a minute and 100 an hour per IP. That is enough for a private workbook, but Google egress can be shared. If other people can edit the sheet, do not put an API key in its bound script; use a server-side proxy that holds the key instead.
=FXRATE("USD","JPY") in any cell without an add-on.CacheService usually reuses one response for ten minutes, but Google may evict cached values early.Start without putting a key in the sheet
The latest-rate endpoint accepts an anonymous request, capped at 12 requests a minute and 100 an hour per IP. Use that for this private-sheet example. A bound Apps Script project is visible to every spreadsheet editor, so it is not a safe place for a bearer token. If the workbook is shared or feeds a product, send the request through a server-side proxy that stores the key outside Google Sheets.
Open Apps Script from your sheet
Open the sheet that will hold the rates. Choose Extensions → Apps Script. Delete the starter myFunction and replace it with the code below. The script is bound to this spreadsheet, which makes the function available without an add-on and also makes the code visible to other editors.
Paste the FXRATE function
This version calls exchangerate.dev without an Authorization header, caches each pair for ten minutes, and returns a readable marker when access, quota, or pair validation fails. The cache is script-wide, so cells requesting the same pair can usually share one response. CacheService is best-effort: Google may discard an entry before its requested expiry.
Use =FXRATE() in any cell
Back in the sheet, type =FXRATE("USD","EUR") in an empty cell. The first uncached call may take a few seconds because Sheets has to run Apps Script and make the external request. The same function works for any supported pair; swap the two currency codes:
The API response includes the base, requested pair, timestamp, and freshness fields such as source and market_session. The values below illustrate the response shape; a live call returns current values and timestamps. Keep the metadata when you need to explain when a number was observed:
Refresh and free-tier fit
A custom function recalculates when Sheets decides its inputs changed; it is not a live streaming feed, and a time-driven trigger does not automatically refresh every formula cell. For a dashboard that must refresh on a schedule, use a separate trigger function that fetches the required pairs and writes values into a range. For ordinary models, recalculate the sheet or edit an input when you need a fresh uncached value. The ten-minute cache and free quota are usually enough for a small workbook:
- Anonymous access: 12 requests a minute and 100 an hour per IP
CacheServiceusually reuses the rate for ten minutes, though Google may evict it early- Google may route multiple users through shared egress, so the effective anonymous capacity can vary
- Use a server-side proxy with a free key when a shared workbook needs a quota that belongs to your account