Use goldprice.dev to fetch copper with GET https://api.goldprice.dev/v1/spot/HG-USD-SPOT. The price is US dollars per pound. Spot works without a key, and Free includes access with a key. Both are fifteen minutes late; paid plans are live. Parse the price string with Decimal, check freshness, and calculate prices per gram or kilogram locally.
Optional: create an API key
Copper spot works without a key. A free key raises your allowance; create one through onboarding and store it outside your code:
export GOLDPRICE_API_KEY=replace_with_your_keyFree includes 5,000 calls a month and 10 requests a minute, with no credit card.
Keep your key on your server and out of committed notebooks. Free requires a visible link to goldprice.dev near displayed prices.
Install the HTTP client
Install requests. Python's standard library includes decimal. It preserves decimal price strings without introducing binary floating point errors; division still uses the configured precision.
python -m pip install requestsFetch the copper spot price
Save this as copper_price.py. It sends your key when GOLDPRICE_API_KEY is set and works without one.
Copper is quoted in US dollars per pound. Multiply by 2.20462262 for a price per kilogram, or divide by 453.59237 for a price per gram. These calculations change the weight unit; the currency stays USD.
The script rejects quotes marked stale.
import osfrom decimal import Decimalimport requestsBASE = "https://api.goldprice.dev"KEY = os.environ.get("GOLDPRICE_API_KEY", "").strip()HEADERS = {"Authorization": f"Bearer {KEY}"} if KEY else {}GRAMS_PER_POUND = Decimal("453.59237")POUNDS_PER_KILOGRAM = Decimal("2.20462262")def get_json(path, params=None): response = requests.get( BASE + path, headers=HEADERS, params=params, timeout=10 ) if response.status_code == 401: raise RuntimeError("401: check GOLDPRICE_API_KEY") if response.status_code == 429: retry_after = response.headers.get("Retry-After") detail = f"; Retry-After: {retry_after}" if retry_after else "" raise RuntimeError("429: pause requests before retrying" + detail) response.raise_for_status() return response.json()def copper_spot(): data = get_json("/v1/spot/HG-USD-SPOT") if (data["symbol"], data["quote_currency"], data["unit"], data["contract_type"]) != ( "HG", "USD", "pound", "spot" ): raise RuntimeError("unexpected copper quote format") if data["is_stale"]: raise RuntimeError("the API marked this quote stale") price_per_pound = Decimal(data["price"]) return { "price_per_pound": price_per_pound, "price_per_gram": price_per_pound / GRAMS_PER_POUND, "price_per_kilogram": price_per_pound * POUNDS_PER_KILOGRAM, "computed_at": data["computed_at"], }if __name__ == "__main__": quote = copper_spot() print(f"Copper USD per pound: {quote['price_per_pound']}") print(f"Copper USD per gram: {quote['price_per_gram']:.8f}") print(f"Copper USD per kilogram: {quote['price_per_kilogram']:.8f}") print(f"Computed: {quote['computed_at']}")Run the client
Run python copper_price.py. The comments below show calculated output for the sample spot response. The live response may differ.
Keep computed_at with stored prices. Check both that timestamp and is_stale. Free and keyless quotes are fifteen minutes late even when the stale flag is false; paid plans are live.
python copper_price.py# Sample price output:# Copper USD per pound: 6.4410# Copper USD per gram: 0.01419997# Copper USD per kilogram: 14.19997430# Computed: 2026-10-23T16:18:02.599973+00:00Control request volume
A run makes one spot request. Cache repeated spot reads when possible.
Free allows 5,000 calls a month and 10 requests a minute. Keyless access allows 10 requests a minute and 100 an hour per IP. Leave room for retries and other clients using the same allowance.
monthly_call_limit = 5000calls_per_run = 1 # One spot requestmaximum_runs = monthly_call_limit // calls_per_runprint(f"Maximum runs before retries or other API use: {maximum_runs}")Expected output
{"symbol":"HG","quote_currency":"USD","unit":"pound","contract_type":"spot","price":"6.4410","is_stale":false,"computed_at":"2026-10-23T16:18:02.599973+00:00"}The sample shows the spot response shape. The script prints prices in USD per pound, gram and kilogram, followed by the computed timestamp.
Common errors
| Code | What you see | Fix |
|---|---|---|
| 401 | The request returns 401. | Check GOLDPRICE_API_KEY and send it as Authorization: Bearer .... For spot without a key, omit the Authorization header. |
| 429 | The request returns 429. | Honor Retry-After when supplied, cache repeated requests and reduce request frequency. Check the minute, hour or monthly limit that applies to your access. |
Going further
- Store raw responses alongside calculated prices and their computed timestamps.
- Calculate the value of copper holdings by multiplying their weight by the price in the matching unit.