Free sun & moon API
SunAndMoon offers a free, public JSON API and an embeddable widget for sunrise, sunset, golden hour, twilight and moon times for any city. No key, no limits, computed in the open with SunCalc.
JSON API
Request today's times for a city, or pass ?date=YYYY-MM-DD for any day. The response is CORS-enabled, so you can call it straight from the browser.
GET https://sunandmoon.app/api/sun/london GET https://sunandmoon.app/api/sun/tokyo?date=2026-12-25
Example response (trimmed):
{
"city": { "name": "London", "country": "United Kingdom",
"slug": "london", "timezone": "Europe/London",
"lat": 51.5074, "lon": -0.1278 },
"date": "2026-07-12",
"sun": {
"sunrise": { "iso": "2026-07-12T03:57:00.000Z", "local": "04:57" },
"sunset": { "iso": "2026-07-12T20:14:00.000Z", "local": "21:14" },
"dayLengthMinutes": 977,
"goldenHour": { "evening": { "start": {...}, "end": {...} } },
"twilight": { "civilDawn": {...}, "civilDusk": {...} }
},
"moon": { "phaseName": "Waning Crescent", "illumination": 0.05,
"moonrise": {...}, "moonset": {...} },
"attribution": "https://sunandmoon.app"
}Every time is returned both as a UTC iso instant and a localstring in the city's own time zone. Events that do not occur (polar day or night) are null. City slugs match the site's URLs, e.g. /api/sun/london, /api/sun/new-york.
Embeddable widget
Drop a compact live card into any page with an iframe. It shows today's sunrise, sunset, day length, golden hour and moon for the city, and links back here.
<iframe src="https://sunandmoon.app/embed/london" width="420" height="220" style="border:0" title="London sun times"></iframe> <p>Sunrise times by <a href="https://sunandmoon.app/sun/london">SunAndMoon</a></p>
Keep the one line under the iframe. It is plain HTML on your own page, so it credits the source for readers who never interact with the widget, it still shows when an iframe is blocked or fails to load, and screen readers announce it as an ordinary link. A link inside the iframe belongs to the embedded page, not to yours. Change london in both URLs to any city slug.
Try it: /embed/london, /embed/tokyo.
Calendar feed (ICS)
Subscribe to a city's sunrise and sunset in any calendar app and today's light shows up next to your meetings. It is a standard iCalendar (.ics) subscription: no account, no key, and it rolls forward on its own, so you add it once and forget it.
# subscribe in a calendar app webcal://sunandmoon.app/api/ics/london # or fetch the file over https https://sunandmoon.app/api/ics/tokyo?events=sunrise,sunset,goldenhour
What the feed contains
Each request returns the next 90 days for that city as a text/calendardocument. Every event is a zero-length marker at the exact instant of the event, titled with the time and the city, and linked back to that city's page. The calendar advertises a one-day refresh interval (REFRESH-INTERVAL:P1D), which is what makes it keep itself current: your calendar app re-fetches the URL and picks up the next horizon of days. Events that do not occur, such as sunset during polar summer, are simply absent rather than faked.
Options
| Part | Values | What it does |
|---|---|---|
[city] | any city slug | The same slug the site uses, so /sun/new-york pairs with /api/ics/new-york. |
?events= | sunrise, sunset, goldenhour | Comma separated. Defaults to sunrise,sunset. Adding goldenhour marks when the evening golden hour begins. |
| Scheme | webcal:// or https:// | webcal:// opens the subscribe dialog directly; https:// returns the same file to fetch or import. |
Adding it to your calendar
In Google Calendar, open Other calendars, choose From URL and paste the https:// form. In Apple Calendar, use File then New Calendar Subscription, or simply click a webcal:// link on an Apple device. In Outlook, use Add calendar then Subscribe from web. Each app decides how often it re-fetches; most honour the one-day interval, some are lazier.
Examples: /api/ics/london (sunrise and sunset), /api/ics/tokyo?events=sunrise,sunset,goldenhour (the photographer feed). Free to use in your own projects or your own newsletter under CC BY 4.0: wherever you show these times, name SunAndMoon and link to sunandmoon.app.
Field reference
Every time field is an object with two members: iso, a UTC instant in ISO 8601, and local, an HH:MM string already converted to the city's own time zone. A field is null when the event does not occur that day, which happens inside the polar circles.
| Field | Type | Unit or range |
|---|---|---|
city.slug, city.name, city.country, city.region | string | slug matches the site URL |
city.lat, city.lon | number | degrees, WGS84 |
city.timezone | string | IANA time zone name |
date | string | YYYY-MM-DD, the city's local date |
sun.sunrise, sun.sunset | object or null | sun centre at -0.833 degrees |
sun.solarNoon | object | sun at its highest |
sun.dayLengthMinutes | number or null | minutes, 0 to 1440 |
sun.goldenHour | object | degrees; has morning and evening, each with start and end |
sun.blueHour | object | same shape as goldenHour |
sun.twilight.civilDawn, civilDusk | object or null | sun at -6 degrees |
sun.twilight.nauticalDawn, nauticalDusk | object or null | sun at -12 degrees |
sun.twilight.astronomicalDawn, astronomicalDusk | object or null | sun at -18 degrees |
moon.phase | number | 0 to 1, see below |
moon.phaseName | string | one of eight names, see below |
moon.illumination | number | 0 to 1, fraction of the disc lit |
moon.moonrise, moon.moonset | object or null | null on days with no rise or set |
source | string | always SunCalc |
attribution | string | the URL to link back to |
attribution_html | string | a ready-made HTML credit line naming SunAndMoon |
The moon phase value
moon.phase is the position in the synodic month, from 0 to 1: 0 is new moon, 0.25 first quarter, 0.5 full moon, 0.75 last quarter. Naming a phase means putting boundaries on that number, and there is no universal convention. These are ours: a narrow band of half a day either side of each principal phase, and wide bands for the four intermediate names, so a moon called full really looks full.
| Phase value | phaseName |
|---|---|
0 to 0.0169 and 0.9831 to 1 | New Moon |
0.0169 to 0.2331 | Waxing Crescent |
0.2331 to 0.2669 | First Quarter |
0.2669 to 0.4831 | Waxing Gibbous |
0.4831 to 0.5169 | Full Moon |
0.5169 to 0.7331 | Waning Gibbous |
0.7331 to 0.7669 | Last Quarter |
0.7669 to 0.9831 | Waning Crescent |
The API computes the moon for the moment of the request; the HTML pages compute it for local midnight at the start of the city's day. Late in the day the two can therefore differ by up to about 11 percentage points of illumination (most around first and last quarter), and close to a phase boundary by one name. Full reasoning on methodology.
Errors and edge cases
| Status | When | Body |
|---|---|---|
| 200 | the city exists | the JSON document above |
| 404 | unknown city slug | { "error": "unknown_city", "message": ... } |
| 204 | CORS preflight (OPTIONS) | empty |
An invalid ?date= is not an error: anything that is not YYYY-MM-DDis ignored and today in the city's time zone is used instead. Above the Arctic Circle and below the Antarctic Circle there are days with no sunrise or no sunset at all; those fields come back null rather than as a made-up time, and dayLengthMinutes is then 1440 during midnight sun and 0 during polar night. Try /api/sun/tromso?date=2026-06-21 and /api/sun/tromso?date=2026-12-21.
Public dataset
Beyond the per-request API there is a single file with the shape of the whole year per city: total daylight hours, the longest and shortest day, the earliest and latest sunrise and sunset (which are not the solstices, and that is the interesting part), the fastest day-length change, and the counts of midnight sun, polar night and never-fully-dark days.
https://sunandmoon.app/data/daylight-year.json https://sunandmoon.app/data/daylight-year.csv
Download: daylight-year.csv (spreadsheets) or daylight-year.json (code).
Licensed CC BY 4.0: use it anywhere, including commercially. Wherever you show these figures, name SunAndMoon and link to sunandmoon.app. Licence text.
Code examples
curl:
curl -s https://sunandmoon.app/api/sun/london | jq '.sun.sunset.local'
JavaScript, straight from the browser:
const r = await fetch("https://sunandmoon.app/api/sun/london");
const d = await r.json();
console.log(d.city.name + " sunset: " + d.sun.sunset.local);Python:
import urllib.request, json
url = "https://sunandmoon.app/api/sun/london"
with urllib.request.urlopen(url) as r:
d = json.load(r)
print(d["city"]["name"], d["sun"]["sunset"]["local"])iOS Shortcuts: add a Get Contents of URL action pointed at https://sunandmoon.app/api/sun/london, then a Get Dictionary Value action with the key sun.sunset.local, then Show Result. No key and no account, so it works from a personal automation.
Licence and attribution
The API, the widget, the calendar feed and the dataset are free to use, including commercially, under CC BY 4.0. There is no key and no rate limit for reasonable use. Licensed CC BY 4.0. Wherever you show these times, name SunAndMoon and link to sunandmoon.app. The licence asks for nothing more than that credit. The embed widget names and links its source inside the frame, so the iframe needs no extra link; the text line in the snippet is a courtesy, not a condition. When you call the API directly, the attribution field carries the URL and attribution_html a ready-made credit line you can render as it is:
Sun data: <a href="https://sunandmoon.app">SunAndMoon</a>
A machine-readable description of the API is at sunandmoon.app/openapi.json (OpenAPI 3.1).
To cite the data in an article, a paper or an answer, use:
Cite as: SunAndMoon (sunandmoon.app), computed with SunCalc.
How the figures are produced and how closely they match NOAA's published solar equations is set out, with a table recomputed on every build, on methodology.
Changelog
| Date | Change |
|---|---|
| 2026-08-04 | Moon phase names corrected. The eight names used to sit on eight equal bands, which called a 68 percent lit moon a last quarter. The principal phases now occupy a narrow band around their exact value. phase and illumination are unchanged; only phaseName moves. |
| 2026-08-04 | Added the public daylight-year dataset, a documented field reference, the phase boundary table and explicit CC BY 4.0 licensing. |
| 2026-07-16 | Calendar feed (ICS) published with an events filter. |
There is no version in the URL and no breaking change is planned. Fields may be added; existing fields will not be removed or renamed without a note here first.
Frequently asked questions
Is the API free?
Yes. The JSON API and the embeddable widget are free and public, with no API key and no rate limit for reasonable use. Licensed CC BY 4.0. Wherever you show these times, name SunAndMoon and link to sunandmoon.app.
Do I need an API key?
No. There is no sign-up and no key. Just request the URL for the city you want.
Can I use it in my own site or app?
Yes, including commercially. The data is computed with the open-source SunCalc library from public coordinates and licensed CC BY 4.0. Wherever you show these times, name SunAndMoon and link to sunandmoon.app.
How accurate are the times?
Accurate to about a minute for a clear, flat horizon, the same computation the site itself uses. At high latitudes some events do not occur and are returned as null.
How do I add sunset times to my calendar?
Subscribe to webcal://sunandmoon.app/api/ics/[city] in any calendar app, for example webcal://sunandmoon.app/api/ics/london. It is a standard iCalendar feed covering the next 90 days, it refreshes itself daily, and it needs no account. Add ?events=sunrise,sunset,goldenhour for a photographer's version that also marks the evening golden hour.