// Node.js 24. OSRM_API_KEY=... node platform-starter.mjs
// This is a normal live geocoding call; normal credits apply.
const key = process.env.OSRM_API_KEY;
if (!key) throw new Error("Set OSRM_API_KEY");
const response = await fetch(
  "https://osrmroute.com/api/1/geocode?q=Baku&limit=1",
  {
    headers: { Authorization: "Bearer " + key },
    signal: AbortSignal.timeout(20000),
    redirect: "error",
  },
);
const body = await response.json();
if (!response.ok)
  throw new Error(
    JSON.stringify({
      status: response.status,
      code: body.code,
      request_id: response.headers.get("x-request-id"),
    }),
  );
console.log(
  JSON.stringify(
    { request_id: response.headers.get("x-request-id"), result: body },
    null,
    2,
  ),
);
