Every calculation on this site is available as a free JSON API. No key, no signup, no quota. It runs the same functions that render the pages, so a response here and a number on a city page cannot disagree.
Both take lat, lng and an optional date (YYYY-MM-DD; omit it for today).
GET /api/v1/sun?lat=51.5074&lng=-0.1278
GET /api/v1/moon?lat=51.5074&lng=-0.1278&date=2027-06-21A call to /api/v1/sun for London:
{
"location": { "latitude": 51.5074, "longitude": -0.1278,
"timezone": "Europe/London" },
"date": "2026-08-06",
"sunrise": { "local": "5:32 AM", "utc": "2026-08-06T04:32:44Z" },
"sunset": { "local": "8:42 PM", "utc": "2026-08-06T19:42:42Z" },
"dayLength": { "text": "15 hours 10 minutes", "seconds": 54597 },
"polarState": null
}Local times follow the site's own formatting, which is the 12-hour clock on the English build and the 24-hour clock on the Danish one. If you need an unambiguous instant, use the utc field rather than parsing the local string. The sun endpoint also returns the sun's altitude at solar noon, whether the sun is up right now, and polarState, which is "day" or "night" inside the polar circles. The moon endpoint returns moonrise, moonset, phase, illumination, the moon's age in days, its distance in kilometres, and flags for supermoon, micromoon and blue moon.
Every instant is given twice: as a wall-clock time in the location's own zone, and as an ISO timestamp in UTC. The wall-clock string is what a person should read; the UTC instant is what a machine should compare. A bare "05:33" with no zone is a bug waiting to happen, and sending two fields is better than making you guess.
Inside the polar circles the sun does not necessarily rise. During midnight sun or polar night, sunrise and sunset are null and polarState says which case applies. The same holds for the moon, where alwaysUp and alwaysDown mark days on which it never crosses the horizon. A missing time is information, not a failure.
lat between −90 and 90, lng between −180 and 180.GET only. CORS is open, so calling straight from a browser works.400 with an explanatory hint rather than an empty body.Every response carries a source field naming what computed the number, which independent ephemeris it was checked against, when, and how many facts that check covered. The method and its limits are set out on accuracy and verification, and the calculation itself on how we calculate the times.
The data is free to use under CC BY 4.0, including commercially — credit the source with a link.
No. There is no key, no registration and no quota. Responses are cached hard, because the answer for a given coordinate and date never changes, so repeated calls cost nothing.
Yes, including commercially. The data is published under CC BY 4.0, which means you may use and build on it as long as you credit the source with a link. Every response carries its own licence and attribution in the source field.
Yes, literally. The endpoint calls the same functions the pages call, so an API response and the time shown on a city page cannot disagree. That is tested by comparing the two across several cities.