Load oil prices in a Supabase Edge Function

Use a Supabase Edge Function to fetch a timestamped Brent quote for an internal application. Keep credentials in function secrets and deduplicate observations.

Collect Brent observations for an internal application

  1. Create an Edge Function for your internal task. Store OILPRICEAPI_KEY as a project Edge Function secret and require authorization on the function.
  2. Fetch the quote inside the function with the code below. Validate the returned benchmark code, numeric price, unit and source timestamp before writing a row.
  3. Store each observation once using code and as_of as a unique key. When a scheduled request fails, retain the last successful source timestamp so your app can show its age.

Inside your Edge Function

const key = Deno.env.get("OILPRICEAPI_KEY");
if (!key) throw new Error("Missing OilPriceAPI function secret");
const response = await fetch(
  "https://api.oilpriceapi.com/v1/prices/latest?by_code=BRENT_CRUDE_USD",
  { headers: { Authorization: "Token " + key }, signal: AbortSignal.timeout(10000) }
);
if (!response.ok) throw new Error("OilPriceAPI HTTP " + response.status);
const { data } = await response.json();

Latest BRENT_CRUDE_USD from the API

$90.54per barrel

As of 2026-11-23 13:31 UTC

Supabase function secrets guide