Sunrise Sunset & Moon Phase API
Sunrise, sunset, twilight, golden & blue hour, day length and sun position for any place and date. Moon phase, illumination, moonrise & moonset.
Get a free API key on RapidAPI Try it in the playgroundSunrise Sunset & Moon Phase API
Astronomy for apps — computed on the edge in milliseconds, in local time for any IANA time zone.
☀️ Sun
- Sunrise, sunset, solar noon and day length (with the change versus yesterday)
- Civil, nautical and astronomical twilight
- Golden hour and blue hour for photographers
- Sun position (altitude, azimuth, compass direction, shadow length) for any instant
- Up to 366 days in one call for calendars and charts
- Handles polar day / polar night and observer elevation
🌙 Moon
- Phase name and emoji, illumination %, age and distance
- Moonrise and moonset and current position for your location
- Dates of the next new moon, first quarter, full moon and last quarter
- A monthly lunar calendar with the exact times of the principal phases
Use cases: weather and outdoor apps · photography planners · smart-home & lighting automation · solar-energy tools · fishing, hunting and gardening calendars · astronomy widgets
Keywords: sunrise sunset api, sunset time, golden hour api, blue hour, twilight times, day length, sun position, solar noon, moon phase api, full moon dates, moonrise moonset, lunar calendar
Endpoints (5)
| Endpoint | What it returns |
|---|---|
GET/sun | Sunrise, sunset & twilight Sun times for one day: sunrise, sunset, solar noon, day length (and change since yesterday), civil / nautical / astronomical twilight, golden hour, blue hour, sunrise and sunset azimuth. |
GET/sun/range | Sun times for a date range Sunrise, sunset, solar noon, day length and civil twilight for up to 366 consecutive days. |
GET/sun/position | Sun position Altitude and azimuth of the sun at an instant (default: now), compass direction, daylight phase and the shadow-length ratio (shadow length = object height × ratio). |
GET/moon | Moon phase & times Moon phase name and emoji, illumination, age, distance and the dates of the next four principal phases. When lat and lon are given, also moonrise, moonset and the moon's current position. |
GET/moon/calendar | Lunar calendar Moon phase and illumination for every day of a month, plus the exact local times of new moon, first quarter, full moon and last quarter in that month. |
Quick start
Subscribe on RapidAPI (free plan available), copy your key, and call GET /sun:
curl --request GET \
--url 'https://sunrise-sunset-moon-phase-api1.p.rapidapi.com/sun?lat=40.7128&lon=-74.0060&timezone=America%2FNew_York&date=2026-06-21' \
--header 'x-rapidapi-host: sunrise-sunset-moon-phase-api1.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY'import requests
url = "https://sunrise-sunset-moon-phase-api1.p.rapidapi.com/sun?lat=40.7128&lon=-74.0060&timezone=America%2FNew_York&date=2026-06-21"
headers = {
"x-rapidapi-host": "sunrise-sunset-moon-phase-api1.p.rapidapi.com",
"x-rapidapi-key": "YOUR_RAPIDAPI_KEY",
}
resp = requests.get(url, headers=headers)
print(resp.json())const res = await fetch("https://sunrise-sunset-moon-phase-api1.p.rapidapi.com/sun?lat=40.7128&lon=-74.0060&timezone=America%2FNew_York&date=2026-06-21", {
method: "GET",
headers: {
"x-rapidapi-host": "sunrise-sunset-moon-phase-api1.p.rapidapi.com",
"x-rapidapi-key": "YOUR_RAPIDAPI_KEY"
}
});
console.log(await res.json());
Example response
{
"latitude": 40.7128,
"longitude": -74.006,
"timezone": "America/New_York",
"date": "2026-06-21",
"sunrise": "2026-06-21T05:26:15-04:00",
"sunset": "2026-06-21T20:31:52-04:00",
"solar_noon": "2026-06-21T12:59:04-04:00",
"day_length": "15:05:38",
"day_length_seconds": 54338,
"civil_twilight": {
"begin": "2026-06-21T04:52:49-04:00",
"end": "2026-06-21T21:05:18-04:00"
},
"nautical_twilight": {
"begin": "2026-06-21T04:10:10-04:00",
"end": "2026-06-21T21:47:58-04:00"
},
"astronomical_twilight": {
"begin": "2026-06-21T03:19:45-04:00",
"end": "2026-06-21T22:38:23-04:00"
},
"golden_hour": {
"morning": {
"begin": "2026-06-21T05:26:15-04:00",
"end": "2026-06-21T06:07:34-04:00"
},
"evening": {
"begin": "2026-06-21T19:50:33-04:00",
"end": "2026-06-21T20:31:52-04:00"
}
},
"blue_hour": {
"morning": {
"begin": "2026-06-21T04:52:49-04:00",
"end": "2026-06-21T05:06:03-04:00"
},
"evening": {
"begin": "2026-06-21T20:52:05-04:00",
"end": "2026-06-21T21:05:18-04:00"
}
},
"sun_altitude_at_noon": 72.73,
"sunrise_azimuth": 57.7,
"sunset_azimuth": 302.7,
"polar": null,
"day_length_change_seconds": 2
}
Start free. Every plan includes all endpoints; upgrade only when you need more requests. Runs on Cloudflare's global network for low latency worldwide.
Subscribe on RapidAPIRelated APIs
Aviation Weather API - METAR & TAF
Live decoded METAR & TAF for airports worldwide, flight category (VFR/IFR), airport info, runways & crosswind, nearby stations, SIGMETs.
WeatherWeather Forecast API
Global weather by city or coordinates: current conditions, 90-hour hourly & 10-day daily forecast, UV, wind, rain chance, sunrise/sunset, alerts.