TutorialsCode

How to get live gold prices in Copper price in Python

Fetch the copper spot price per pound in Python, then calculate prices per gram and kilogram.

23 Oct 2026 · 3 min read

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:

Shell
export GOLDPRICE_API_KEY=replace_with_your_key

Free 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.

shell
python -m pip install requests

Fetch 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.

copper_price.py
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.

shell
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:00

Control 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.

quota.py
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

JSON
{"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

CodeWhat you seeFix
401The request returns 401.Check GOLDPRICE_API_KEY and send it as Authorization: Bearer .... For spot without a key, omit the Authorization header.
429The 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.

Questions

Is copper available on Free, and what are the quotas?

Yes. Free includes copper spot, 5,000 calls a month and 10 requests a minute, with no credit card. Free quotes are fifteen minutes late. Display a visible link to goldprice.dev near the prices.

How many calls does the Python example make?

One call per run, for copper spot. It sends your key when one is set and works without a key.

Why use Decimal for copper prices?

The API returns copper prices as strings. Python's Decimal preserves those decimal inputs and avoids binary floating point representation errors. Division still uses the configured precision, so choose a rounding policy before displaying calculated prices.

How do I detect an old copper quote?

Check is_stale and retain computed_at with the price. Free and keyless quotes are fifteen minutes late even when they are not marked stale. Set an acceptable age for your application that accounts for your plan's delay.

Can Claude or another AI tool fetch copper through MCP?

Yes. Connect an MCP capable AI tool such as Claude to https://api.goldprice.dev/v1/mcp/. Without a key, get_spot_price returns copper. The server also supports list_commodities, get_carat, search_docs, get_metadata and get_historical, with 30 days of history.

Do I need to display a link beside copper prices?

Free requires a visible link to goldprice.dev near the prices you display. Paid plans need no link. Keep your API key on your server when building a website or application.

How do I calculate copper prices per gram or kilogram?

Copper spot is quoted in US dollars per pound. Divide the pound price by 453.59237 for the price per gram, or multiply it by 2.20462262 for the price per kilogram. Both results remain in USD.

Keep reading

Start with a free API key

5,000 requests a month on the free plan. No credit card.

Get a free key