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.

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