Sunrise & Sunset API (with Golden Hour and Moon Phase)
Whether you're building a photography app, smart-home automation, or an outdoor planner, you need accurate sun times for arbitrary coordinates — not just your server's city.
One GET returns the full set of solar events as ISO timestamps: sunrise, sunset, solar noon, dawn, dusk, and golden hour. Sibling endpoints add solar azimuth/altitude, moon phase and illumination, and moonrise/moonset.
Get sun times for any coordinates
curl -G "https://sun-moon-times.p.rapidapi.com/times" \
-d "lat=51.5074" -d "lng=-0.1278" -d "date=2026-09-21" \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: sun-moon-times.p.rapidapi.com"const qs = new URLSearchParams({ lat: "51.5074", lng: "-0.1278", date: "2026-09-21" });
const res = await fetch(
"https://sun-moon-times.p.rapidapi.com/times?" + qs,
{ headers: {
"X-RapidAPI-Key": "YOUR_KEY",
"X-RapidAPI-Host": "sun-moon-times.p.rapidapi.com",
} }
);
const { times } = await res.json();
console.log(times.sunrise, times.goldenHour);Golden hour for photographers
The /times response includes goldenHour (evening) and goldenHourEnd (morning) alongside dawn and dusk, all as ISO timestamps in UTC — convert to the local timezone client-side. That's the exact window photographers plan shoots around, computed for the precise coordinates rather than the nearest city.
Moon phase and moonrise/moonset
GET /moon returns the phase (0-1) and illuminated fraction — enough to render an accurate moon icon or plan astrophotography. GET /moon-times returns moonrise and moonset with always-up/always-down flags for polar latitudes, and GET /position gives the sun's azimuth and altitude for any timestamp (useful for shadow calculation and solar-panel math).
Why it's fast and private
Everything is pure astronomical math (SunCalc) computed in-process — no upstream weather service, no location logging, sub-millisecond latency. Coordinates are used for the calculation and discarded.
Run it in production
Sun & Moon Times has a permanent free tier — 1,000 requests a month, no credit card. Paid plans start at $5/month for 100,000 requests.
FAQ
What timezone are the timestamps in?
All times are ISO 8601 in UTC. Convert to the viewer's local timezone client-side (e.g., with Intl.DateTimeFormat).
How accurate are the times?
Within about a minute for typical latitudes — the same SunCalc math used across the industry. Extreme polar latitudes are handled with always-up/always-down flags.
Do you store the coordinates I send?
No. The calculation runs in-memory and nothing is logged or persisted.