Astronomy API

Run in Postman

Overview

The Astronomy API provides the location-based rise and set times for the Sun and Moon along with the current position, distance from earth, and azimuth of the Sun and the Moon for a specific date at the queried time.

Astronomy calculations are far more complex than throwing a few numbers into obscure formulas. There is always a tradeoff between accuracy and computing time. Our Astronomy API focuses on producing acceptable results with an accuracy of around one minute, good enough for applications like sunrise and sunset timers but not sufficient for astronomical purposes.

There are three ways to consume the Astronomy API:

  • Using any Location Address (preferably, city address)
  • Using Geo Coordinates (latitude & longitude)
  • Using any IPv4 or IPv6 address

Responses are returned in JSON by default. To receive XML, add output=xml (for successful responses, used only when no Accept header, or Accept: */*, is sent) or send Accept: application/xml. You can also explicitly request JSON with output=json. For XML examples and response-format options, see API Response Formats (JSON and XML).

The three variations of Astronomy API take the different input sources to produce astronomical information along with location details. Here is how to consume each variation:


Getting Astronomical Information for an Address

Pass a city name or street address in the location query parameter. Here is an example to get the astronomical information for the address 'New York, US':

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&location=New%20York&elevation=10'
Response Preview
{
  "location": {
    "location_string": "New York",
    "country_name": "United States",
    "state_prov": "New York",
    "city": "New York",
    "locality": "",
    "latitude": "40.71273",
    "longitude": "-74.00602",
    "elevation": "6"
  },
  "astronomy": {
    "date": "2026-10-29",
    "current_time": "06:33:56.534",
    "mid_night": "00:39",
    "night_end": "05:50",
    "morning": {
      "astronomical_twilight_begin": "05:50",
      "astronomical_twilight_end": "06:22",
      "nautical_twilight_begin": "06:22",
      "nautical_twilight_end": "06:54",
      "civil_twilight_begin": "06:54",
      "civil_twilight_end": "07:22",
      "blue_hour_begin": "06:44",
      "blue_hour_end": "07:05",
      "golden_hour_begin": "07:05",
      "golden_hour_end": "08:01"
    },
    "sunrise": "07:22",
    "sunset": "17:56",
    "evening": {
      "golden_hour_begin": "17:17",
      "golden_hour_end": "18:13",
      "blue_hour_begin": "18:13",
      "blue_hour_end": "18:35",
      "civil_twilight_begin": "17:56",
      "civil_twilight_end": "18:24",
      "nautical_twilight_begin": "18:24",
      "nautical_twilight_end": "18:56",
      "astronomical_twilight_begin": "18:56",
      "astronomical_twilight_end": "19:28"
    },
    "night_begin": "19:28",
    "sun_status": "-",
    "solar_noon": "12:39",
    "day_length": "10:34",
    "sun_altitude": -9.86299503761222,
    "sun_distance": 148631813.8153374,
    "sun_azimuth": 99.41602438618526,
    "moon_phase": "WANING_GIBBOUS",
    "moonrise": "20:31",
    "moonset": "11:43",
    "moon_status": "-",
    "moon_altitude": 52.61741568059783,
    "moon_distance": 364605.1661316123,
    "moon_azimuth": 263.3689600954356,
    "moon_parallactic_angle": 58.2638340362214,
    "moon_illumination_percentage": "-85.67",
    "moon_angle": 224.48482345746874
  }
}

Getting Astronomical Information for Location Coordinates

You can pass the latitude and longitude of a location as query parameters lat and long to get the astronomical information. Here is an example to get the astronomical information for '40.76473, -74.00084' coordinates:

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&lat=40.76473&long=-74.00084&elevation=10'
Response Preview
{
  "location": {
    "latitude": "40.76473",
    "longitude": "-74.00084",
    "country_name": "United States",
    "state_prov": "New York",
    "city": "New York",
    "locality": "Midtown West",
    "elevation": "9"
  },
  "astronomy": {
    "date": "2026-10-29",
    "current_time": "06:33:56.040",
    "mid_night": "00:39",
    "night_end": "05:50",
    "morning": {
      "astronomical_twilight_begin": "05:50",
      "astronomical_twilight_end": "06:22",
      "nautical_twilight_begin": "06:22",
      "nautical_twilight_end": "06:54",
      "civil_twilight_begin": "06:54",
      "civil_twilight_end": "07:22",
      "blue_hour_begin": "06:44",
      "blue_hour_end": "07:05",
      "golden_hour_begin": "07:05",
      "golden_hour_end": "08:01"
    },
    "sunrise": "07:22",
    "sunset": "17:56",
    "evening": {
      "golden_hour_begin": "17:17",
      "golden_hour_end": "18:13",
      "blue_hour_begin": "18:13",
      "blue_hour_end": "18:35",
      "civil_twilight_begin": "17:56",
      "civil_twilight_end": "18:24",
      "nautical_twilight_begin": "18:24",
      "nautical_twilight_end": "18:56",
      "astronomical_twilight_begin": "18:56",
      "astronomical_twilight_end": "19:28"
    },
    "night_begin": "19:28",
    "sun_status": "-",
    "solar_noon": "12:39",
    "day_length": "10:33",
    "sun_altitude": -9.869168560046097,
    "sun_distance": 148631813.8153374,
    "sun_azimuth": 99.40906748202292,
    "moon_phase": "WANING_GIBBOUS",
    "moonrise": "20:30",
    "moonset": "11:43",
    "moon_status": "-",
    "moon_altitude": 52.608971139098124,
    "moon_distance": 364605.1626589418,
    "moon_azimuth": 263.3038592927023,
    "moon_parallactic_angle": 58.17925492923368,
    "moon_illumination_percentage": "-85.67",
    "moon_angle": 224.48474531450978
  }
}

Getting Astronomical Information for an IPv4 or IPv6 Address

You can pass any IPv4 or IPv6 address as a query parameter ip to get the astronomical information. Here is an example to get the astronomical information for the IP address '8.8.8.8':

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&ip=8.8.8.8'
Response Preview
{
  "ip": "8.8.8.8",
  "location": {
    "continent_code": "NA",
    "continent_name": "North America",
    "country_code2": "US",
    "country_code3": "USA",
    "country_name": "United States",
    "country_name_official": "United States of America",
    "is_eu": false,
    "state_prov": "California",
    "state_code": "US-CA",
    "district": "Santa Clara",
    "city": "Mountain View",
    "zipcode": "94043-1351",
    "latitude": "37.42240",
    "longitude": "-122.08421",
    "locality": "Charleston Terrace",
    "elevation": "3"
  },
  "astronomy": {
    "date": "2026-10-29",
    "current_time": "03:33:56.039",
    "mid_night": "00:52",
    "night_end": "06:02",
    "morning": {
      "astronomical_twilight_begin": "06:02",
      "astronomical_twilight_end": "06:32",
      "nautical_twilight_begin": "06:32",
      "nautical_twilight_end": "07:03",
      "civil_twilight_begin": "07:03",
      "civil_twilight_end": "07:30",
      "blue_hour_begin": "06:53",
      "blue_hour_end": "07:13",
      "golden_hour_begin": "07:13",
      "golden_hour_end": "08:06"
    },
    "sunrise": "07:30",
    "sunset": "18:13",
    "evening": {
      "golden_hour_begin": "17:37",
      "golden_hour_end": "18:29",
      "blue_hour_begin": "18:29",
      "blue_hour_end": "18:50",
      "civil_twilight_begin": "18:13",
      "civil_twilight_end": "18:40",
      "nautical_twilight_begin": "18:40",
      "nautical_twilight_end": "19:10",
      "astronomical_twilight_begin": "19:10",
      "astronomical_twilight_end": "19:41"
    },
    "night_begin": "19:41",
    "sun_status": "-",
    "solar_noon": "12:51",
    "day_length": "10:43",
    "sun_altitude": -46.85301788883555,
    "sun_distance": 148631813.8153374,
    "sun_azimuth": 67.31450511528658,
    "moon_phase": "WANING_GIBBOUS",
    "moonrise": "21:05",
    "moonset": "11:50",
    "moon_status": "-",
    "moon_altitude": 79.38111034286753,
    "moon_distance": 364605.1626519111,
    "moon_azimuth": 154.59096812163125,
    "moon_parallactic_angle": -22.638676928232154,
    "moon_illumination_percentage": "-85.67",
    "moon_angle": 224.48474515618548
  }
}

Returning Astronomical Event Times in a Specific Time Zone

By default, the API calculates astronomical events (such as sunrise, sunset, moonrise, moonset, twilight phases, and solar noon) based on the geographic location derived from the request. This location may be determined using an IP address, coordinates, or a provided location name.

If you want the same astronomical events to be represented in a different time zone, you can provide the time_zone parameter in your request. When this parameter is supplied, the API keeps the original geographic location for the astronomical calculations but converts all event timestamps into the specified time zone.

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&time_zone=Europe/London'
Response Preview
{
  "ip": "39.63.58.51",
  "location": {
    "continent_code": "AS",
    "continent_name": "Asia",
    "country_code2": "PK",
    "country_code3": "PAK",
    "country_name": "Pakistan",
    "country_name_official": "Islamic Republic of Pakistan",
    "is_eu": false,
    "state_prov": "Punjab",
    "state_code": "PK-PB",
    "district": "Lahore District",
    "city": "Lahore",
    "zipcode": "54000",
    "latitude": "31.52037",
    "longitude": "74.35875",
    "locality": "Gulberg",
    "elevation": ""
  },
  "astronomy": {
    "time_zone": "Europe/London",
    "date": "2026-10-29",
    "current_time": "10:33:56.044",
    "mid_night": "2026-10-29 18:46",
    "night_end": "2026-10-28 23:53",
    "morning": {
      "astronomical_twilight_begin": "2026-10-28 23:53",
      "astronomical_twilight_end": "2026-10-29 00:22",
      "nautical_twilight_begin": "2026-10-29 00:22",
      "nautical_twilight_end": "2026-10-29 00:50",
      "civil_twilight_begin": "2026-10-29 00:50",
      "civil_twilight_end": "2026-10-29 01:15",
      "blue_hour_begin": "2026-10-29 00:41",
      "blue_hour_end": "2026-10-29 01:00",
      "golden_hour_begin": "2026-10-29 01:00",
      "golden_hour_end": "2026-10-29 01:49"
    },
    "sunrise": "2026-10-29 01:15",
    "sunset": "2026-10-29 12:16",
    "evening": {
      "golden_hour_begin": "2026-10-29 11:42",
      "golden_hour_end": "2026-10-29 12:31",
      "blue_hour_begin": "2026-10-29 12:31",
      "blue_hour_end": "2026-10-29 12:50",
      "civil_twilight_begin": "2026-10-29 12:16",
      "civil_twilight_end": "2026-10-29 12:41",
      "nautical_twilight_begin": "2026-10-29 12:41",
      "nautical_twilight_end": "2026-10-29 13:09",
      "astronomical_twilight_begin": "2026-10-29 13:09",
      "astronomical_twilight_end": "2026-10-29 13:38"
    },
    "night_begin": "2026-10-29 13:38",
    "sun_status": "-",
    "solar_noon": "2026-10-29 06:46",
    "day_length": "11:00",
    "sun_altitude": 19.283663601726765,
    "sun_distance": 148631813.81533742,
    "sun_azimuth": 239.65048387012152,
    "moon_phase": "WANING_GIBBOUS",
    "moonrise": "2026-10-29 14:45",
    "moonset": "2026-10-29 04:47",
    "moon_status": "-",
    "moon_altitude": -29.792962878084037,
    "moon_distance": 364605.16268705844,
    "moon_azimuth": 11.548153013856336,
    "moon_parallactic_angle": -11.114294150819825,
    "moon_illumination_percentage": "-85.67",
    "moon_angle": 224.48474594714244
  }
}

Time Series Lookup

You can look up astronomy details for any location by providing a starting and ending date for the time series. The API allows a maximum 90-day lookup period, whether for future or past dates. The range counts both dateStart and dateEnd, so dateEnd can be at most 89 days after dateStart. Here's how you can do it.

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy/timeSeries?apiKey=API_KEY&lat=40.76473&long=-74.00084&dateStart=2026-10-26&dateEnd=2026-10-28'
Response Preview
{
  "location": {
    "latitude": "40.76473",
    "longitude": "-74.00084",
    "country_name": "United States",
    "state_prov": "New York",
    "city": "New York",
    "locality": "Midtown West",
    "elevation": "9"
  },
  "astronomy": [
    {
      "date": "2026-10-26",
      "mid_night": "00:40",
      "night_end": "05:47",
      "morning": {
        "astronomical_twilight_begin": "05:47",
        "astronomical_twilight_end": "06:19",
        "nautical_twilight_begin": "06:19",
        "nautical_twilight_end": "06:51",
        "civil_twilight_begin": "06:51",
        "civil_twilight_end": "07:19",
        "blue_hour_begin": "06:40",
        "blue_hour_end": "07:02",
        "golden_hour_begin": "07:02",
        "golden_hour_end": "07:57"
      },
      "sunrise": "07:19",
      "sunset": "18:00",
      "evening": {
        "golden_hour_begin": "17:21",
        "golden_hour_end": "18:17",
        "blue_hour_begin": "18:17",
        "blue_hour_end": "18:38",
        "civil_twilight_begin": "18:00",
        "civil_twilight_end": "18:27",
        "nautical_twilight_begin": "18:27",
        "nautical_twilight_end": "18:59",
        "astronomical_twilight_begin": "18:59",
        "astronomical_twilight_end": "19:31"
      },
      "night_begin": "19:31",
      "sun_status": "-",
      "solar_noon": "12:39",
      "day_length": "10:41",
      "moon_phase": "FULL_MOON",
      "moonrise": "17:57",
      "moonset": "07:56",
      "moon_status": "-"
    },
    {
      "date": "2026-10-27",
      "mid_night": "00:40",
      "night_end": "05:48",
      "morning": {
        "astronomical_twilight_begin": "05:48",
        "astronomical_twilight_end": "06:20",
        "nautical_twilight_begin": "06:20",
        "nautical_twilight_end": "06:52",
        "civil_twilight_begin": "06:52",
        "civil_twilight_end": "07:20",
        "blue_hour_begin": "06:41",
        "blue_hour_end": "07:03",
        "golden_hour_begin": "07:03",
        "golden_hour_end": "07:59"
      },
      "sunrise": "07:20",
      "sunset": "17:59",
      "evening": {
        "golden_hour_begin": "17:20",
        "golden_hour_end": "18:15",
        "blue_hour_begin": "18:15",
        "blue_hour_end": "18:37",
        "civil_twilight_begin": "17:59",
        "civil_twilight_end": "18:26",
        "nautical_twilight_begin": "18:26",
        "nautical_twilight_end": "18:58",
        "astronomical_twilight_begin": "18:58",
        "astronomical_twilight_end": "19:30"
      },
      "night_begin": "19:30",
      "sun_status": "-",
      "solar_noon": "12:39",
      "day_length": "10:38",
      "moon_phase": "FULL_MOON",
      "moonrise": "18:37",
      "moonset": "09:15",
      "moon_status": "-"
    },
    {
      "date": "2026-10-28",
      "mid_night": "00:39",
      "night_end": "05:49",
      "morning": {
        "astronomical_twilight_begin": "05:49",
        "astronomical_twilight_end": "06:21",
        "nautical_twilight_begin": "06:21",
        "nautical_twilight_end": "06:53",
        "civil_twilight_begin": "06:53",
        "civil_twilight_end": "07:21",
        "blue_hour_begin": "06:42",
        "blue_hour_end": "07:04",
        "golden_hour_begin": "07:04",
        "golden_hour_end": "08:00"
      },
      "sunrise": "07:21",
      "sunset": "17:57",
      "evening": {
        "golden_hour_begin": "17:18",
        "golden_hour_end": "18:14",
        "blue_hour_begin": "18:14",
        "blue_hour_end": "18:36",
        "civil_twilight_begin": "17:57",
        "civil_twilight_end": "18:25",
        "nautical_twilight_begin": "18:25",
        "nautical_twilight_end": "18:57",
        "astronomical_twilight_begin": "18:57",
        "astronomical_twilight_end": "19:29"
      },
      "night_begin": "19:29",
      "sun_status": "-",
      "solar_noon": "12:39",
      "day_length": "10:36",
      "moon_phase": "WANING_GIBBOUS",
      "moonrise": "19:28",
      "moonset": "10:32",
      "moon_status": "-"
    }
  ]
}

Using Client or Machine IP Address

You can call the astronomy API without passing any coordinates or IP address as well. It will use the calling machine's IP address to return the regional astronomical information. Here is an example:

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY'

Response in Multiple Languages

The astronomy information lookup using an IP address can include geolocation information in the following languages:

  • English (en)
  • German (de)
  • Russian (ru)
  • Japanese (ja)
  • French (fr)
  • Chinese Simplified (cn)
  • Spanish (es)
  • Czech (cs)
  • Italian (it)
  • Korean (ko)
  • Persian (fa)
  • Portuguese (pt)
  • Standard Arabic (ar)

By default, the API responds in English. But you can change the response language by passing the language code as a query parameter lang. Here is an example:

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&ip=1.1.1.1&lang=cn'

Getting Astronomical Information for a Specific Date

Along with the above two variations, there is a third variation that you can get the astronomical information for a specific date. You can pass date query parameter with the date value. Here are some example calls for coordinates search along with date:

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&lat=-27.4748&long=153.017&date=2025-01-01'

Alternatively, you can also call this endpoint with IP address and date parameters:

curl -X GET 'https://api.ipgeolocation.io/v3/astronomy?apiKey=API_KEY&ip=1.1.1.1&date=2025-01-01'

Reference to Astronomy API Response

Below we have provided separate tables for location object and astronomy object fields that can be returned by Astronomy API.


1. Standalone Fields Reference

FieldTypeDescriptionCan Be Empty?
ipstring

The IP address used for the astronomy lookup. Returned when queried using the ip= parameter or with no parameters.

Yes

2.  location JSON Object Reference

FieldTypeDescriptionCan Be Empty?
location_stringstring

Location is the string, you provided for searching.

Yes
continent_codestring

2-letter code of the continent.

Yes
continent_namestring

Name of the continent.

Yes
country_code2string

Country code (ISO 3166-1 alpha-2) of the country.

Yes
country_code3string

Country code (ISO 3166-1 alpha-3) of the country.

Yes
country_namestring

Name of the country.

Yes
country_name_officialstring

Formal name of the country.

Yes
is_euboolean

Whether the country belongs to the European Union

Yes
state_provstring

Name of the state/province/region.

Yes
state_codestring

Code of the state/province/region.

Yes
districtstring

Name of the district or county.

Yes
citystring

Name of the city.

Yes
localitystring

Smaller area, part or region of a city.

Yes
zipcodestring

ZIP/Postal code of the place.

Yes
latitudestring

Latitude of the place.

No
longitudestring

Longitude of the place.

No
elevationstring

Elevation in meters of the nearest known city, as a string. Empty string when not available. It does not echo the elevation request parameter.

Yes

3.  astronomy JSON Object Reference

Event times use HH:mm by default. When you supply time_zone, event times use yyyy-MM-dd HH:mm in the requested zone. A rise or set that does not occur is -:-. current_time uses HH:mm:ss.SSS, and day_length is a duration.

FieldTypeDescriptionCan Be Empty?
time_zonestring

Appears (with the provided value) only when the user includes a time_zone in the query to specify which time to observe.

No
datestring

Provided or current date in the format yyyy-MM-dd.

No
current_timestring

Current time in the format HH:mm:ss.SSS, in the location's time zone, or in time_zone when that parameter is given. Positional values are calculated for this time.

No
mid_nightstring

Astronomical midnight (nadir) for the given date.

No
night_endstring

End of night / start of astronomical twilight (morning).

No
night_beginstring

Start of night / end of astronomical twilight (evening).

No
sunrisestring

Time at which sun rises at the extracted location, in HH:mm format, or yyyy-MM-dd HH:mm when time_zone is supplied. Returns -:- if the sun does not rise on this date.

No
sunsetstring

Time at which sun sets at the extracted location, in HH:mm format, or yyyy-MM-dd HH:mm when time_zone is supplied. Returns -:- if the sun does not set on this date.

No
sun_statusstring

Describes the sunrise and sunset status.

No
solar_noonstring

The time of day when the sun is at its highest point in the sky, in HH:mm format, or yyyy-MM-dd HH:mm when time_zone is supplied.

No
day_lengthstring

The total length of daylight for the current day in format HH:mm, representing the time from sunrise to sunset.

No
sun_altitudefloat

The sun's altitude angle above the horizon at current_time, measured in degrees.

No
sun_distancefloat

The distance from Earth to the sun at current_time, in kilometers.

No
sun_azimuthfloat

The azimuth angle of the sun at current_time, indicating its compass direction in degrees.

No
moonrisestring

Time at which moon rises at the extracted location, in HH:mm format, or yyyy-MM-dd HH:mm when time_zone is supplied. Returns -:- if the moon does not rise on this date.

No
moonsetstring

Time at which moon sets at the extracted location, in HH:mm format, or yyyy-MM-dd HH:mm when time_zone is supplied. Returns -:- if the moon does not set on this date.

No
moon_statusstring

Represents the moon rise and moon set status.

No
moon_altitudefloat

The moon's altitude angle above the horizon at current_time, measured in degrees.

No
moon_distancefloat

The distance from Earth to the moon at current_time, in kilometers.

No
moon_azimuthfloat

The azimuth angle of the moon at current_time, indicating its compass direction in degrees.

No
moon_parallactic_anglefloat

The angle between the celestial pole and the moon's position relative to the location, measured in degrees.

No
moon_phasestring

The current phase of the moon (e.g., WAXING_CRESCENT), indicating its position in the lunar cycle.

No
moon_illumination_percentagestring

The percentage of the moon's surface that is illuminated by sunlight, as viewed from Earth. The value is signed: a positive value means the moon is waxing and a negative value means it is waning, while the magnitude is the illuminated percentage.

No
moon_anglefloat

The Moon's angular position relative to the Sun, measured from 0° to 360°, indicating its position in the lunar cycle.

No
morning.astronomical_twilight_beginstring

Start of astronomical twilight (pre‑dawn) in the morning.

No
morning.astronomical_twilight_endstring

End of astronomical twilight in the morning.

No
morning.nautical_twilight_beginstring

Start of nautical twilight (when the horizon first becomes visible) in the morning.

No
morning.nautical_twilight_endstring

End of nautical twilight in the morning.

No
morning.civil_twilight_beginstring

Start of civil twilight (enough light for outdoor activities) in the morning.

No
morning.civil_twilight_endstring

End of civil twilight in the morning.

No
morning.blue_hour_beginstring

Start of blue hour (soft, diffused light) before sunrise.

No
morning.blue_hour_endstring

End of blue hour before sunrise.

No
morning.golden_hour_beginstring

Start of golden hour (warm, low‑angle light) before sunrise.

No
morning.golden_hour_endstring

End of the morning golden hour, occurring after sunrise.

No
evening.golden_hour_beginstring

Start of the evening golden hour (warm, low‑angle light), occurring before sunset.

No
evening.golden_hour_endstring

End of golden hour after sunset.

No
evening.blue_hour_beginstring

Start of blue hour (soft, diffused light) after sunset.

No
evening.blue_hour_endstring

End of blue hour after sunset.

No
evening.civil_twilight_beginstring

Start of civil twilight (enough light for outdoor activities) in the evening.

No
evening.civil_twilight_endstring

End of civil twilight in the evening.

No
evening.nautical_twilight_beginstring

Start of nautical twilight (horizon still visible) in the evening.

No
evening.nautical_twilight_endstring

End of nautical twilight in the evening.

No
evening.astronomical_twilight_beginstring

Start of astronomical twilight (night sky begins) in the evening.

No
evening.astronomical_twilight_endstring

End of astronomical twilight in the evening.

No

sun_status: Indicates the current state of the sun relative to the horizon. If both the sunrise and sunset values are not equal to "-:-", sun_status will be set to "-", indicating no special status. If the sun is continuously above the twilight angle, sun_status may be set to "Always above the twilight angle", indicating that the Sun remains above the twilight-angle threshold throughout the 24-hour period, without crossing it. Conversely, if the sun remains below the twilight angle, the status may read "Always below the twilight angle", indicating that the Sun remains below the twilight-angle threshold throughout the 24-hour period, without crossing it.

moon_status: Represents the current state of the moon in relation to the horizon. If both the moonrise and moonset values are not equal to "-:-", moon_status will be set to "-", indicating no special status. If the moon is always visible above the horizon, moon_status may be assigned "Always above the horizon", signifying that the moon does not set within the current 24-hour period. Conversely, if the moon is consistently below the horizon, it may read "Always below the horizon", indicating it does not rise during this timeframe.


Error Codes

Astronomy API returns HTTP status code 200 for a successful API request along with the response.

In case of a bad or invalid request, Astronomy API returns 4xx HTTP status code along with a descriptive message explaining the reason for the error.

Below is a detailed explanation of the specific HTTP status codes and their corresponding error conditions:

HTTP StatusDescription
400
Bad Request

It is returned for one of the following reasons:

  • If the provided IPv4 or IPv6 address is invalid.
  • If special characters [ ] { } | ^ ` are passed in the API URL, either as a parameter or its value, especially in the API key.
  • If the provided date is not in the format 'yyyy-MM-dd'. On the astronomy/timeSeries endpoint the messages are `dateStart` must be in 'yyyy-MM-dd' format and `dateEnd` must be in 'yyyy-MM-dd' format.
  • If the IPv4 or IPv6 address does not exist in our database.
  • If an invalid lang value is provided on the astronomy endpoint. Supported values: en, de, ru, ja, fr, cn, es, cs, it, ko, fa, pt, ar. The lang parameter only affects the values inside the location object. On the astronomy/timeSeries endpoint the value is not validated: on paid plans an unsupported value returns English names, and on a Free plan any value other than en returns HTTP 401.
  • If the provided values to the request parameters lat and long are not numbers, or the values fall outside the acceptable latitude and longitude ranges. The valid range for latitude is between -90 and 90, and for longitude, it is between -180 and 180. Non-numeric values, and values written with an exponent larger than 50 (for example 1e51), return Invalid value '1e51' for parameter 'lat'..
  • If only one of the request parameters lat and long is provided.
  • Thrown when the provided elevation exceeds the maximum allowed value (10,000 meters / 10 km).
  • If the range covers more than 90 days, counting both dateStart and dateEnd (so dateEnd can be at most 89 days after dateStart), on the astronomy/timeSeries endpoint (Date range cannot exceed 90 days.).
  • If dateEnd is before dateStart on the astronomy/timeSeries endpoint (End date must be on or after start date.).
  • If dateStart or dateEnd is missing (Required request parameter 'dateStart' is missing) or sent empty on the astronomy/timeSeries endpoint.
  • Thrown when the provided time_zone is invalid or unrecognized.
401
Unauthorized

It is returned for one of the following reasons:

  • An API key is required for this request, but the apiKey query parameter is missing and the request doesn't come from a domain added under Request Origin.
  • If an invalid (a random value) API key is provided, or the request has no API key and its Origin or Referer domain is not registered as a Request Origin.
  • If your account has been locked because of abuse or illegal activity.
  • If you haven't verified the email address on your account.
  • When the request uses an API key associated with a database subscription.
  • When the subscription associated with the API key is paused.
  • If you're making API requests after your subscription trial has expired.
  • If a language other than English is specified in the lang parameter while using an API key on the free plan.
402
Payment Required
  • If your paid subscription's active-until date has passed (one day after it for an active or trialing subscription) and you need to renew or upgrade your subscription. Paused subscriptions and expired trials get 401 instead.
403
Forbidden
  • If the API key has an IP allow-list and the request comes from an IP address that isn't on it.
404
Not Found

It is returned for one of the following reasons:

  • If an IPv4 or IPv6 address is passed as a path variable instead of as a URL parameter (ip=).
  • If the location address provided to the request parameter location is invalid. A city-level or state-level address must be provided.
  • If an endpoint that does not exist in our API is called.
405
Method Not Allowed
  • If wrong HTTP request method is used for calling the endpoint. Only GET method is allowed for astronomy endpoint requests.
423
Locked
  • If the passed IP address is from a bogon IP range, or is part of a private network.
429
Too Many Requests

It is returned for one of the following reasons:

  • If the API usage limit has been reached on a Free plan, on an active trial (100,000 API credits), on a paid plan with surcharge usage turned off (it is on by default on all paid plans), or on a subscription with the status 'past due' or 'deleted'.
  • If the surcharge API usage limit has been reached against the subscribed plan.
499
Client Closed Request
  • The edge logs 499 when the client closes the connection before the server can respond. A short client timeout can cause this. Check your client's timeout settings.
5XX
Server Side Error
  • If a 500 (Internal Server Error), 502 (Bad Gateway), 503 (Service Unavailable), 504 (Gateway Timeout), or 505 (HTTP Version Not Supported) status code is returned, it indicates an issue on our end. Please contact us with your request at support@ipgeolocation.io for further assistance.
  • A 503 is returned if your API key can't be verified because of a temporary internal error (message: "We're unable to verify your API key (...) due to an internal error..."). Retry after a short wait.
  • A 503 is also returned when a location value cannot be geocoded because the geocoding service is temporarily unavailable. Example: We couldn't look up the location (London, UK) right now. Please try again shortly, or use the 'lat' and 'long' parameters instead. Retry, or use coordinates.

OpenAPI Specification

The Astronomy API has an OpenAPI 3.0 specification in JSON and YAML, published in our OpenAPI repository on GitHub. Import it into Postman, Insomnia or another API client, or use it to generate client code. To try the endpoints without any setup, open our Postman workspace.


Other Ways to Use the Astronomy API

You can also get sun and moon data using our CLI, MCP server, or third-party integration tools.


Frequently Asked Questions

The IP Geolocation Astronomy API provides comprehensive astronomical data, including sunrise and sunset times, moonrise and moonset times, solar noon, day length, the current sun position (azimuth and altitude), moon phases, and moon illumination percentages. It also delivers data for any location on Earth based on geographic coordinates or IP address.
You can retrieve accurate sunrise and sunset times by sending a simple request to the Astronomy API with your preferred location parameters: latitude and longitude, city name, or IP address. Optionally, include a date parameter to get data for a past or future date. The API returns the sunrise and sunset times in local time in JSON and XML formats for easy integration.
Yes. The Astronomy API includes detailed moon data, such as the current moon phase (e.g., WAXING_CRESCENT, NEW_MOON, FULL_MOON), and the moon’s illumination percentage. This data suits astronomy apps, photography planning, and tide tracking.
Yes. The Astronomy API provides real-time sun position data, including azimuth and altitude, for any specific geographic location and date. This feature is ideal for solar panel optimization, solar tracking, and outdoor planning applications.
The Astronomy API integrates seamlessly with IPGeolocation.io’s database. By simply providing an IP address in your API request, the system automatically determines the geographic coordinates and returns accurate astronomical data, including sunrise, sunset, sun position, and moon phases for that IP address location.
Yes. The Astronomy API allows you to retrieve sun and moon data for historical dates as well as future dates.
The Astronomy API returns data in JSON (default) and XML formats, making it easy to integrate into web and mobile applications. The response includes sunrise and sunset times, solar noon, day length, sun position (azimuth and altitude), moonrise and moonset times, moon phase, and illumination percentage.
Yes. IPGeolocation.io provides comprehensive documentation with code examples in multiple programming languages, including JavaScript, Python, PHP, and even in curl format. You can find these examples in the documentation section, making it easy to integrate the Astronomy API into your application or system quickly.
The Astronomy API targets event-time accuracy of about one minute, which is suitable for sunrise and sunset displays, outdoor planning, and similar applications. Observed times vary with atmospheric conditions and elevation. For precision astronomical or scientific work, validate the results against a suitable ephemeris or observatory source.
IPGeolocation.io offers different pricing plans with varying usage limits. The free plan includes 1,000 credits per day and can be used in production. Paid plans provide larger credit allowances per billing period, priority support, and additional features to support enterprise-level applications.
API for Sunset, Sunrise, Moonset and Moonrise timings

Looking for features, modules, and use cases? Visit the Astronomy API page.

Explore Astronomy API

Subscribe to Our Newsletter

Get the latest in geolocation tech, straight to your inbox.