apyhub
Back
▣ VERIFICATION KIT · OUTPUT KIT

Sun and Moon Position API

What it does

Sun and Moon Times gives you sun and moon position data for a specific location and moment. Send latitude, longitude, and datetime, and get back the current solar and lunar angles plus the key daylight phases for that day.

Use it when your app needs to know more than just sunrise and sunset. The response includes day, morningGoldenHour, civilTwilight, nauticalTwilight, astronomicalTwilight, eveningGoldenHour, civilDusk, nauticalDusk, astronomicalDusk, night, solarNoon, and nadir, along with sun and moon objects. The sun data includes altitude and azimuth. The moon data includes altitude, azimuth, distance, parallacticAngle, moonrise, and moonset.

The phase fields are returned as local-time ranges in HH:MM format, so you can render photography planning tools, astronomy views, outdoor activity schedules, or weather apps without converting timestamps yourself. If you need to account for a specific timezone, you can also pass utcOffset in the request.

Sun and Moon Times is useful anywhere you need time-aware lighting or sky-position data tied to coordinates: planning shoots around golden hour, showing when twilight ends, or checking whether the moon rises on a given calendar day.

GET
Calculates sun and moon information for a given location and time.
https://api.eu.apyhub.com/modernsoftware-pro/sun-and-moon-position-api/sunrise

QUICKSTART

GUIDE

Quickstart

Fetch sun, moon, and twilight times for a specific location and datetime using query parameters.

curl -X GET "https://api.eu.apyhub.com/modernsoftware-pro/sun-and-moon-position-api/sunrise?latitude=40.7128&longitude=-74.006&datetime=2026-10-28T12:00:00" \
  -H "apy-token: $APY_TOKEN"

What you'll get back

Returns a JSON object with top-level timing fields for the day, plus sun and moon objects. Arrays like day, morningGoldenHour, and civilTwilight contain zero or more { "from": "HH:MM", "to": "HH:MM" } entries; solarNoon, nadir, and the various dawn/dusk fields are HH:MM strings, while sun and moon include the numeric position details.

{
  "day": [],
  "morningGoldenHour": [],
  "civilTwilight": [],
  "nauticalTwilight": [],
  "astronomicalTwilight": [],
  "eveningGoldenHour": [],
  "civilDusk": [],
  "nauticalDusk": [],
  "astronomicalDusk": [],
  "night": [],
  "solarNoon": "12:00",
  "nadir": "00:00",
  "sun": { "altitude": 0, "azimuth": 0 },
  "moon": {
    "altitude": 0,
    "azimuth": 0,
    "distance": 0,
    "parallacticAngle": 0,
    "moonrise": [],
    "moonset": []
  }
}
TRY ITLIVE · 20 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
Date and time to check, as `yyyy-MM-ddTHH:mm:ss`
Location latitude to check
Location longitude to check
Optional UTC timezone prefix (leave empty to auto-detect)

About this endpoint

What it does

Calculates sun and moon information for a given location and time. It accepts latitude, longitude, and datetime as query parameters, and returns a JSON object containing sun, moon, and daylight-phase timing information for that request.

Query Parameter(s)

AttributeTypeMandatoryDescription
datetimeStringYesDate and time to check, as yyyy-MM-ddTHH:mm:ss.
Pattern: ^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$
latitudeNumberYesLocation latitude to check.
Minimum: -90
Maximum: 90
longitudeNumberYesLocation longitude to check.
Minimum: -180
Maximum: 180
utcOffsetStringNoOptional UTC timezone prefix (leave empty to auto-detect).
Pattern: ^(UTC)?[+-]\d{1,2}:\d{2}$

Response

Returns a JSON object with required fields for daylight phases, solar timing, and sun/moon measurements. The top-level fields include arrays of time ranges such as day, night, civilTwilight, and similar phase fields, plus solarNoon, nadir, sun, and moon.

AttributeTypeMandatoryDescription
dayObject ArrayYesThe daylight period (from sunrise to sunset). Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
morningGoldenHourObject ArrayYesThe soft, warm morning light shortly after sunrise. Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
civilTwilightObject ArrayYesMorning civil twilight (bright enough for most outdoor activities without artificial light). Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
nauticalTwilightObject ArrayYesMorning nautical twilight (the horizon is still visible at sea). Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
astronomicalTwilightObject ArrayYesMorning astronomical twilight (the sky is almost completely dark). Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
eveningGoldenHourObject ArrayYesThe soft, warm evening light shortly before sunset. Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
civilDuskObject ArrayYesEvening civil twilight. Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
nauticalDuskObject ArrayYesEvening nautical twilight. Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
astronomicalDuskObject ArrayYesEvening astronomical twilight. Each item has from and to fields in HH:MM local-time format. The array is empty if the phase is not observed for that day, and may contain multiple entries if it is observed more than once.
nightObject ArrayYesFull night (dark enough for astronomical observations). May appear as two separate entries on the same calendar day: the tail end of the previous night just after midnight, and the start of the next night just before the following midnight. Each item has from and to fields in HH:MM local-time format.
solarNoonStringYesThe moment the sun is at its highest position, as local time only, in HH:MM format. Always present.
nadirStringYesThe moment the sun is at its lowest position (the darkest moment of the night), as local time only, in HH:MM format. Always present.
sunObjectYesSun measurements for the requested location and time. Contains altitude and azimuth.
moonObjectYesMoon measurements and rise/set timing for the requested location and time. Contains altitude, azimuth, distance, parallacticAngle, moonrise, and moonset.

sun

AttributeTypeMandatoryDescription
altitudeNumberYesThe sun's apparent altitude above the horizon, in degrees.
azimuthNumberYesThe sun's azimuth, in degrees, clockwise from north.

moon

AttributeTypeMandatoryDescription
altitudeNumberYesThe moon's apparent altitude above the horizon, in degrees.
azimuthNumberYesThe moon's azimuth, in degrees, clockwise from north.
distanceIntegerYesThe distance to the moon, in kilometers.
parallacticAngleNumberYesThe moon's parallactic angle, in degrees.
moonriseString ArrayYesThe moonrise time observed on the requested calendar day, as local time only, in HH:MM format. Empty if the moon does not rise that day. Contains at most one entry; if the moon could rise more than once on the same calendar day, only the first such event is reported.
moonsetString ArrayYesThe moonset time observed on the requested calendar day, as local time only, in HH:MM format. Empty if the moon does not set that day. Contains at most one entry; if the moon could set more than once on the same calendar day, only the first such event is reported.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.