Developers

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>

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

Calendar feed URL and parameters
PartValuesWhat it does
[city]any city slugThe same slug the site uses, so /sun/new-york pairs with /api/ics/new-york.
?events=sunrise, sunset, goldenhourComma separated. Defaults to sunrise,sunset. Adding goldenhour marks when the evening golden hour begins.
Schemewebcal:// 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 and to link to, in your own projects or your own newsletter. An attribution link back is appreciated.

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.

Response fields, types and units
FieldTypeUnit or range
city.slug, city.name, city.country, city.regionstringslug matches the site URL
city.lat, city.lonnumberdegrees, WGS84
city.timezonestringIANA time zone name
datestringYYYY-MM-DD, the city's local date
sun.sunrise, sun.sunsetobject or nullsun centre at -0.833 degrees
sun.solarNoonobjectsun at its highest
sun.dayLengthMinutesnumber or nullminutes, 0 to 1440
sun.goldenHourobjectdegrees; has morning and evening, each with start and end
sun.blueHourobjectsame shape as goldenHour
sun.twilight.civilDawn, civilDuskobject or nullsun at -6 degrees
sun.twilight.nauticalDawn, nauticalDuskobject or nullsun at -12 degrees
sun.twilight.astronomicalDawn, astronomicalDuskobject or nullsun at -18 degrees
moon.phasenumber0 to 1, see below
moon.phaseNamestringone of eight names, see below
moon.illuminationnumber0 to 1, fraction of the disc lit
moon.moonrise, moon.moonsetobject or nullnull on days with no rise or set
sourcestringalways SunCalc
attributionstringthe URL to link back to

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 name by phase value
Phase valuephaseName
0 to 0.0169 and 0.9831 to 1New Moon
0.0169 to 0.2331Waxing Crescent
0.2331 to 0.2669First Quarter
0.2669 to 0.4831Waxing Gibbous
0.4831 to 0.5169Full Moon
0.5169 to 0.7331Waning Gibbous
0.7331 to 0.7669Last Quarter
0.7669 to 0.9831Waning 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. Close to a boundary the two can therefore differ by one name and by about a percentage point of illumination. Full reasoning on methodology.

Errors and edge cases

Status codes
StatusWhenBody
200the city existsthe JSON document above
404unknown city slug{ "error": "unknown_city", "message": ... }
204CORS 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

Licensed CC BY 4.0: use it anywhere, including commercially, with attribution 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. In exchange we ask for one thing: a visible link back to sunandmoon.app. The embed widget keeps that link itself, so if you use the widget you are already done. If you call the API directly, please put the link somewhere a reader can see it. The attribution field in every response carries the URL so you can render it automatically.

Changelog

API changelog
DateChange
2026-08-04Moon 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-04Added the public daylight-year dataset, a documented field reference, the phase boundary table and explicit CC BY 4.0 licensing.
2026-07-16Calendar 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. A link back to sunandmoon.app is appreciated.

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. Please keep the attribution link.

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.

More