This guide uses Node.js 18 or later, which has fetch built in, so there is nothing to install. Run the code on a server: a key in browser code is visible to everyone who opens the page.
Get a key
Sign up for a free key. The Free plan has 50,000 calls a month and 100 calls a minute, needs no card, and every plan stops at its limit with no extra charge.
Put the key in an environment variable and save the code below as prices.mjs.
export COINPRICE_API_KEY="your key"node prices.mjsMake your first request
getJson sends the key in the Authorization header and throws the API message when the status is not 2xx. ids takes up to 250 coin ids separated by commas. An id the API does not know is left out of the answer, not an error, and an answer with none still counts as a call.
const API = 'https://api.coinprice.dev/v2'const headers = { Authorization: `Bearer ${process.env.COINPRICE_API_KEY}` }async function getJson(path, params) { const response = await fetch(`${API}${path}?${new URLSearchParams(params)}`, { headers }) const body = await response.json() if (!response.ok) throw new Error(`${response.status} ${body.error}: ${body.message}`) return body}const prices = await getJson('/simple/price', { ids: 'bitcoin,ethereum', vs_currencies: 'usd', include_24hr_change: 'true', include_last_updated_at: 'true',})console.log(prices)for (const [coin, row] of Object.entries(prices)) { const change = row.usd_24h_change === null ? 'n/a' : `${row.usd_24h_change.toFixed(2)}%` console.log(`${coin}: ${row.usd.toLocaleString('en-US', { style: 'currency', currency: 'USD' })} (${change} in 24h)`)}{ bitcoin: { last_updated_at: 1795494725, usd: 60439.05, usd_24h_change: -1.2396356881006931 }, ethereum: { last_updated_at: 1795494725, usd: 1698.455891, usd_24h_change: -1.8185536860928275 }}bitcoin: $60,439.05 (-1.24% in 24h)ethereum: $1,698.46 (-1.82% in 24h)usd is the price in US dollars, usd_24h_change is the 24-hour change in percent and last_updated_at is when the price was seen, in Unix seconds. A change is null when there is not enough history.
Get candles
/v2/coins/{id}/ohlc returns rows of [time in ms, open, high, low, close], oldest first. The time is the start of the candle in UTC. A request returns at most 5,000 rows, and a longer window returns the newest rows, so page with from and to.
const API = 'https://api.coinprice.dev/v2'const headers = { Authorization: `Bearer ${process.env.COINPRICE_API_KEY}` }const res = await fetch(`${API}/coins/bitcoin/ohlc?interval=1h&limit=3`, { headers })const candles = await res.json()for (const [time, open, high, low, close] of candles) console.log(new Date(time).toISOString(), open, high, low, close)2026-11-24T01:00:00.000Z 61245.22893 61596.66445 60987.03237 61006.006242026-11-24T02:00:00.000Z 61024.45 61024.45 60010.43654 60015.430942026-11-24T03:00:00.000Z 60013.43351 60323.55 59395.53754 60263.4388Handle errors
An error response is JSON with error, message and request_id. This is what getJson throws for a wrong key.
Error: 401 unauthorized: That API key is not valid.request_id is the id of that call. A 429 has two codes. For rate_limited, wait Retry-After seconds and retry. For quota_exceeded, stop and tell the user: the month's calls are used up, there is no Retry-After, and it resets on the 1st of the month UTC. The full list of errors is in the API reference.