Precious metals have their own ISO 4217 codes – XAU for gold, XAG for silver, XPT for platinum and XPD for palladium – and in the fxapi foreign exchange rates API they work exactly like currencies. That makes fxapi a compact gold and silver price API: get the price of an ounce of gold in rupees, the monthly average silver price in euros, or the value of a bullion holding in your reporting currency, with the same endpoints and API key you use for FX rates.
Metals and units
| Code | Metal | Unit |
|---|---|---|
| XAU | Gold | 1 troy ounce |
| XAG | Silver | 1 troy ounce |
| XPT | Platinum | 1 troy ounce |
| XPD | Palladium | 1 troy ounce |
One troy ounce is 31.1034768 grams. For per-gram or per-kilogram prices, convert in your code.
Two ways to quote metals
- Metal as base –
base_currency=XAU¤cies=USD,EURreturns the price of one ounce in each currency. This is the format most people expect. - Metal as target –
base_currency=USD¤cies=XAUreturns how many ounces one dollar buys (a small number). Invert it to get the price.
Use type=metal to return only XAU, XAG, XPT and XPD.
PHP: gold price per gram in the visitor’s currency
<?php
$currency = "EUR";
$query = http_build_query(["base_currency" => "XAU", "currencies" => $currency]);
$ch = curl_init("https://api.fxapi.com/v1/latest?$query");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["apikey: " . getenv("FXAPI_KEY")],
CURLOPT_TIMEOUT => 10,
]);
$response = json_decode(curl_exec($ch), true);
$perOunce = $response["data"][$currency]["value"];
$perGram = $perOunce / 31.1034768;
printf("Gold: %.2f %s per gram (%s)\n", $perGram, $currency, $response["meta"]["last_updated_at"]);
History, averages and change
| Need | Request |
|---|---|
| Gold price on a past date | /v1/historical?date=2008-10-24&base_currency=XAU¤cies=USD |
| Gold price time series | /v1/range with base_currency=XAU |
| Monthly average silver price | /v1/average with base_currency=XAG |
| Change in platinum since January | /v1/fluctuation with base_currency=XPT |
Who uses metal prices from an FX API
- Jewelry and bullion shops – show indicative metal values in the shopper’s currency and add your own premium.
- Wealth and portfolio apps – value metal holdings next to cash and crypto.
- Accounting – revalue metal inventory at period end with historical and average prices.
- Content and dashboards – daily gold and silver widgets without a separate commodities subscription.
Metals follow your plan’s update interval – daily on Free, hourly on Basic and every 60 seconds on Professional and Enterprise. See pricing.
Frequently asked questions
Which precious metals are available?
How do I get the gold price in USD per ounce?
/v1/latest?base_currency=XAU¤cies=USD. The value is the price of one troy ounce of gold in US dollars.Can I get the gold price per gram?
Is historical gold price data available?
/v1/historical, time series via /v1/range (Professional+), and monthly or yearly averages via /v1/average on every plan.