Skip to content
Free · No key · Millions of requests / month

A fast, keyless API for the sun and the moon.

JSON sunrise, sunset, twilight, golden hour, and moon data for any point on Earth. No signup, no key, no rate limit dance. Just call it.

Request
GETapi.sunrisesunset.io/json?lat=38.9&lng=-77
fetch("https://api.sunrisesunset.io/json?lat=38.9&lng=-77")
  .then(r => r.json())
  .then(data => console.log(data.results.sunrise));
cURL
curl "https://api.sunrisesunset.io/json?lat=38.9&lng=-77"
Response200 OK
{
  "results": {
    "date": "2026-06-21",
    "sunrise": "5:43:05 AM",
    "sunset": "8:36:50 PM",
    "first_light": "3:42:17 AM",
    "last_light": "10:37:38 PM",
    "dawn": "5:10:24 AM",
    "dusk": "9:09:31 PM",
    "solar_noon": "1:09:58 PM",
    "golden_hour": "7:58:12 PM",
    "day_length": "14:53:45",
    "nautical_twilight_begin": "4:28:40 AM",
    "nautical_twilight_end": "9:51:15 PM",
    "timezone": "America/New_York",
    "utc_offset": -240,
    "sun_altitude": 72.58,
    "sun_azimuth": 180.27,
    "sunrise_azimuth": 58.14,
    "sunset_azimuth": 301.86,
    "moonrise": "1:16:23 PM",
    "moonset": "1:42:05 AM",
    "moon_illumination": 24.7,
    "moon_phase": "Waxing Crescent",
    "moon_phase_value": 0.22,
    "moon_always_up": false,
    "moon_always_down": false,
    "elevation": 26
  },
  "status": "OK",
  "tzid": "America/New_York"
}

Free forever

No signup, no API key, no credit card. Just include a link back to sunrisesunset.io.

Edge-served

Hosted on Cloudflare Workers in 300+ cities. P99 response times under 50 ms.

Up to 365 days

One request returns a full year of daily data via date_start + date_end.

Moon + sun

Rise, set, azimuth, altitude, and moon phase. All in one endpoint.

Example requests

All parameters

Parameters

All sent as query-string values on a single GET request.

latRequirednumber
Latitude in decimal degrees.
Example: 38.907192
lngRequirednumber
Longitude in decimal degrees.
Example: -77.036873
dateOptionalstring
Date to query. ISO YYYY-MM-DD, or a relative word like "today" or "tomorrow". Defaults to today in the location's timezone.
Example: 2026-06-21
date_startOptionalstring
Start of a date range (inclusive). Must be paired with date_end. Up to 365 days.
date_endOptionalstring
End of a date range (inclusive). Returns an array of daily results instead of a single object.
timezoneOptionalIANA tz
Return times in this timezone. Defaults to the location's IANA timezone resolved from lat/lng. Falls back silently if the value is invalid.
Default: auto
Example: America/New_York
time_formatOptionalenum
Format of all time fields. One of 12, 24, military, unix. Unix timestamps are always UTC.
Default: 12
formattedOptional0 | 1
Set to 0 to receive times in ISO 8601 format and day_length in seconds.
Default: 1
elevationOptionalnumber | false
Elevation override in meters. By default, auto-detected from terrain via ETOPO1. Pass false to compute at sea level. Higher elevation pushes sunrise earlier and sunset later.
Default: auto
callbackOptionalstring
JSONP callback function name. Returns application/javascript wrapped in your callback when present.

Response fields

Wrapped in { results, status, tzid }. results is a single object, or an array when a date range is used.

date
string
Queried date, YYYY-MM-DD.
sunrise
time
Sunrise time.
sunset
time
Sunset time.
dawn
time
Civil dawn — sun 6° below horizon in the morning.
dusk
time
Civil dusk — sun 6° below horizon in the evening.
first_light
time
Astronomical dawn — faintest sky brightening.
last_light
time
Astronomical dusk — last trace of sky light.
nautical_twilight_begin
time
Sun 12° below horizon in the morning.
nautical_twilight_end
time
Sun 12° below horizon in the evening.
solar_noon
time
Sun at its highest point.
golden_hour
time
Start of evening golden hour.
day_length
H:MM:SS | seconds
Length of daylight (seconds if formatted=0).
timezone
string
IANA timezone of the response times.
utc_offset
number
UTC offset in minutes.
sun_altitude
degrees
Sun altitude at solar noon.
sun_azimuth
degrees
Sun azimuth at solar noon (N = 0°, clockwise).
sunrise_azimuth
degrees
Compass bearing where the sun rises.
sunset_azimuth
degrees
Compass bearing where the sun sets.
moonrise
time | null
Moonrise time. Null if the moon doesn't rise that day.
moonset
time | null
Moonset time. Null if the moon doesn't set that day.
moon_illumination
percent
Percent of the moon's disk illuminated, 0–100.
moon_phase
string
Named phase: New Moon, Waxing Crescent, First Quarter, Waxing Gibbous, Full Moon, Waning Gibbous, Last Quarter, Waning Crescent.
moon_phase_value
0–1
Continuous phase value — 0 and 1 are new, 0.5 is full.
moon_always_up
boolean
True at polar latitudes when the moon is circumpolar that day.
moon_always_down
boolean
True when the moon doesn't appear above the horizon.
elevation
meters
Terrain elevation used in the calculation.

Status codes

Returned in the status field. HTTP status follows logically — 200 for OK and INVALID_TZID (which still returns data), 400 for bad input, 500 for unexpected.

Attribution

The API is free for personal and commercial use. All we ask is a visible backlink. Paste this anywhere on your site:

Powered by <a href="https://sunrisesunset.io">SunriseSunset.io</a>

FAQ

Do I need an API key?
No — the keyless endpoint works for most apps. If you want higher limits or want to track usage per-app, sign in and mint a key in your account. When you do use a key, send it as Authorization: Bearer sss_.... Never put it in the URL query string — query strings get logged by every proxy and CDN on the wire.
Is it really free for commercial use?
Yes. A link back to sunrisesunset.io keeps the lights on — please include one on your site or in your attribution section.
How accurate are the times?
Astronomical to the second. Atmospheric refraction and terrain elevation are both factored in by default.
What if the sun or moon never rises/sets that day?
Fields return null. For the moon, moon_always_up or moon_always_down flip to true at polar latitudes.
Can I bulk-query a full year?
Yes. Use date_start and date_end (up to 365 days apart). You get an array of daily objects in one request.
What timezone are the times in?
Whatever the location is in, auto-detected from lat/lng. Override with the timezone parameter.
Rate limits?
None enforced. Be reasonable. If you're going to hit it every hour per user, cache on your end.

Changelog

  1. Moon data (rise/set, phase, illumination), sun altitude/azimuth at solar noon + rise + set, automatic elevation from terrain.

  2. JSONP callback, formatted=0 for ISO 8601 output, nautical twilight fields, granular status codes.

  3. Fixed a DST edge-case that could return the wrong day at the boundary.

  4. time_format option (12, 24, military, unix).

  5. date_start + date_end range queries, up to 365 days.

  6. Lower response times; migrated onto Cloudflare Workers.

  7. utc_offset added to responses.

  8. first_light + last_light fields (astronomical twilight).

  9. API released.

Watching the API? Status page