Sunrise & Sunset API

Free JSON endpoints for sunrise, sunset, the three twilights, golden hour, solar noon, day length and solar azimuth — for any city in our database. No API key, no signup, no attribution required (though a link back is appreciated).

Times are computed with Skyfield against the JPL DE421 ephemeris, and account for atmospheric refraction at the horizon. Every response is in the city's own local time zone, including daylight saving where it applies.

Monthly solar data

Returns one row per day for a given month, with the full set of solar events.

GEThttps://sunrise.am/api/sun-month-data/{city_slug}/{year}/{month}
ParameterTypeNotes
city_slugstringCity slug as used in our URLs — the tokyo in sunrise.am/tokyo/
yearinteger1900–2999
monthinteger1–12

Example

GEThttps://sunrise.am/api/sun-month-data/tokyo/2026/7
{
  "city_slug": "tokyo",
  "year": 2026,
  "month": 7,
  "month_label": "July 2026",
  "days": [
    {
      "day": 1,
      "sunrise_time": "04:29",
      "sunset_time": "19:00",
      "sunrise_azimuth_deg": 60.2,
      "sunrise_cardinal": "ENE",
      "sunset_azimuth_deg": 299.6,
      "sunset_cardinal": "WNW",
      "daylight_length_str": "14h 31m",
      "daylight_diff_str": "-0m 04s",
      "civil_twilight_start": "04:00",
      "civil_twilight_end": "19:29",
      "nautical_twilight_start": "03:20",
      "nautical_twilight_end": "20:09",
      "astro_twilight_start": "02:37",
      "astro_twilight_end": "20:52",
      "solar_noon_time": "11:44",
      "solar_noon_sun_dist_mil_km": "152.09"
    }
    /* … one object per day of the month … */
  ]
}

Yearly series

Returns 365 (or 366) entries for a whole year, with times expressed as decimal hours — convenient for plotting a daylight curve.

GEThttps://sunrise.am/api/sun-graph-data/{city_slug}/{year}

Example

GEThttps://sunrise.am/api/sun-graph-data/tokyo/2026
[
  {
    "date": "2026-01-01",
    "sunrise": 6.853333333333333,
    "sunset": 16.635833333333334,
    "solar_noon": 11.742777777777777,
    "civil_dawn": 6.371944444444444,
    "civil_dusk": 17.1175,
    "nautical_dawn": 5.843055555555555,
    "nautical_dusk": 17.64611111111111,
    "astronomical_dawn": 5.326388888888888,
    "astronomical_dusk": 18.162777777777777,
    "day_length_hours_str": "9h 46m"
  }
  /* … one object per day of the year … */
]

Decimal hours are local time: 6.8533 is 06:51:12. Multiply the fractional part by 60 for minutes.

Finding a city slug

Slugs match our own URLs, so the simplest way to find one is to look the city up on the site — browse all cities or start from a country. Slugs are lowercase, ASCII, hyphen-separated: sao-paulo, new-york-city, hong-kong-city.

Errors

StatusMeaning
400Year or month outside the accepted range
404No active city with that slug
500City record is missing coordinates or a time zone

Errors return JSON of the form {"error": "City not found"}.

Fair use

This is offered as-is, with no uptime guarantee. It runs on the same infrastructure as the website. Please cache responses on your side — monthly and yearly solar data for a past or future period never changes, and we already cache each response for 24 hours. If you need high volume or a guarantee, get in touch via our contact page first rather than hammering the endpoints.

There is no hard rate limit today, which is a courtesy rather than a promise. Sustained heavy use without caching may be blocked.

Notes on accuracy

Related reading