Our Astronomy API provides timings for sunrise, sunset, moonrise, moonset, sun azimuth, moon azimuth, sun altitude, moon altitude, sun distance from the earth and moon distance from the earth from latitude and longitude or an IPv4 or IPv6 address for a given date.
The Astronomy API provides a detailed dataset about twilight timings, different sun and moon parameters for a given date and location.
1{
2 "location": {
3 "location": "New York, US'",
4 "country": "United States",
5 "state": "New York",
6 "city": "New York",
7 "locality": "Clinton",
8 "latitude": 40.76473335,
9 "longitude": -74.00083980660943
10 },
11 "date": "2026-12-09",
12 "current_time": "07:13:16.209",
13 "sunrise": "07:08",
14 "sunset": "16:28",
15 "sun_status": "-",
16 "solar_noon": "11:48",
17 "day_length": "09:20",
18 "sun_altitude": -0.04277378938141529,
19 "sun_distance": 147366924.6229829,
20 "sun_azimuth": 120.78987572078586,
21 "moonrise": "07:58",
22 "moonset": "16:41",
23 "moon_status": "-",
24 "moon_altitude": -6.805181589019477,
25 "moon_distance": 404814.0580441422,
26 "moon_azimuth": 120.86585289029688,
27 "moon_parallactic_angle": -47.18639517696103,
28 "moon_phase": "NEW_MOON",
29 "moon_illumination_percentage": "0.20",
30 "moon_angle": 5.164672210638351
31}
You can pass the latitude and longitude of a location as query parameters to get the astronomical information.
1{
2 "location": {
3 "latitude": 37.258,
4 "longitude": -122
5 },
6 "date": "2024-11-04",
7 "current_time": "04:21:22.848",
8 "sunrise": "06:36",
9 "sunset": "17:06",
10 "sun_status": "-",
11 "solar_noon": "11:51",
12 "day_length": "10:30",
13 "sun_altitude": -27.1916974786371,
14 "sun_distance": 148361706.3935511,
15 "sun_azimuth": 89.39202575904915,
16 "moonrise": "09:55",
17 "moonset": "19:02",
18 "moon_status": "-",
19 "moon_altitude": -60.310006400447534,
20 "moon_distance": 396442.70137180487,
21 "moon_azimuth": 80.68476682031314,
22 "moon_parallactic_angle": -62.33291127227254,
23 "moon_phase": "WAXING_CRESCENT",
24 "moon_illumination_percentage": "8.23",
25 "moon_angle": 33.33523603807506
26}
You can pass any IPv4 or IPv6 address as a query parameter to get the astronomical information.
1{
2 "location": {
3 "continent_code": "NA",
4 "continent_name": "North America",
5 "country_code2": "US",
6 "country_code3": "USA",
7 "country_name": "United States",
8 "country_name_official": "United States of America",
9 "is_eu": false,
10 "state_prov": "California",
11 "state_code": "US-CA",
12 "district": "Santa Clara",
13 "city": "Mountain View",
14 "zipcode": "94043-1351",
15 "latitude": 37.4224,
16 "longitude": -122.08421
17 },
18 "date": "2024-11-04",
19 "current_time": "04:24:04.939",
20 "sunrise": "06:37",
21 "sunset": "17:06",
22 "sun_status": "-",
23 "solar_noon": "11:51",
24 "day_length": "10:29",
25 "sun_altitude": -26.720690286733994,
26 "sun_distance": 148361706.39355108,
27 "sun_azimuth": 89.66947559541882,
28 "moonrise": "09:56",
29 "moonset": "19:01",
30 "moon_status": "-",
31 "moon_altitude": -59.84017619349532,
32 "moon_distance": 396436.927965668,
33 "moon_azimuth": 80.87803466587684,
34 "moon_parallactic_angle": -62.15740140382433,
35 "moon_phase": "WAXING_CRESCENT",
36 "moon_illumination_percentage": "8.24",
37 "moon_angle": 33.35668681050102
38}
With every sunrise and sunset, nature creates a masterpiece. Take advantage of them and plan your photography sessions ahead of time for the perfect capture with our sunrise-sunset API.
Planning a game of golf? Make sure you plan your tee for the right light. Because you know what they say, "The most important shot is the first one."
Plan the perfect sunset romantic dinner, hiking trip or star-gazing party by taking advantage of the best star API you can find.
"Twilight is the time of the day when the sky looks like it has been painted by a graffiti artist". Use our astronomy API to plan the perfect time to view this breath-taking phenomenon and explore one of the most over-whelming covers of the heavens.
Trying to figure out the optimal angle for your solar panels? Use our API to get the exact solar azimuth and calculate the best solar panel angle by street address.
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.
The Astronomy calculations are much more complex than producing an accurate result from obscure formulas throwing in a few numbers. There is always a tradeoff between the accuracy and computing time. Our Astronomy API focuses more on producing an acceptable results and has an accuracy of around one minute that is good enough for applications like sunrise/sunset timers but is not sufficient for astronomical purposes.
There are three ways to consume the Astronomy API:
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:
You can pass the address of a location as query parameters location
to get the astronomical information. Here is an example to get the astronomical information for address 'New York, US':
1{
2 "location": {
3 "location": "New York, US",
4 "country": "United States",
5 "state": "New York",
6 "city": "New York",
7 "locality": "Clinton",
8 "latitude": 40.76473335,
9 "longitude": -74.00083980660943
10 },
11 "date": "2024-11-04",
12 "current_time": "08:13:22.978",
13 "sunrise": "06:30",
14 "sunset": "16:48",
15 "sun_status": "-",
16 "solar_noon": "11:39",
17 "day_length": "10:18",
18 "sun_altitude": 16.120293371563754,
19 "sun_distance": 148361706.39355108,
20 "sun_azimuth": 128.26575101712496,
21 "moonrise": "09:49",
22 "moonset": "18:29",
23 "moon_status": "-",
24 "moon_altitude": -14.81836182838389,
25 "moon_distance": 396331.25698682835,
26 "moon_azimuth": 113.85094239453929,
27 "moon_parallactic_angle": -51.40390182984849,
28 "moon_phase": "WAXING_CRESCENT",
29 "moon_illumination_percentage": "8.43",
30 "moon_angle": 33.74826084504092
31}
Location details like country name, state/province name, and city are provided in the response for the provided location that can be used for multiple purposes.
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 '-27.4748, 153.017' coordinates:
1{
2 "location": {
3 "latitude": -27.4748,
4 "longitude": 153.017
5 },
6 "date": "2024-11-04",
7 "current_time": "23:28:59.711",
8 "sunrise": "04:54",
9 "sunset": "18:08",
10 "sun_status": "-",
11 "solar_noon": "11:31",
12 "day_length": "13:14",
13 "sun_altitude": -46.89343713201794,
14 "sun_distance": 148361706.39355108,
15 "sun_azimuth": 180.89506040990295,
16 "moonrise": "06:15",
17 "moonset": "20:46",
18 "moon_status": "-",
19 "moon_altitude": -25.365567944837675,
20 "moon_distance": 396297.670873638,
21 "moon_azimuth": 214.4609302018781,
22 "moon_parallactic_angle": 145.49291581261554,
23 "moon_phase": "WAXING_CRESCENT",
24 "moon_illumination_percentage": "8.49",
25 "moon_angle": 33.87230698192152
26}
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':
1{
2 "location": {
3 "continent_code": "NA",
4 "continent_name": "North America",
5 "country_code2": "US",
6 "country_code3": "USA",
7 "country_name": "United States",
8 "country_name_official": "United States of America",
9 "is_eu": false,
10 "state_prov": "California",
11 "state_code": "US-CA",
12 "district": "Santa Clara",
13 "city": "Mountain View",
14 "zipcode": "94043-1351",
15 "latitude": 37.4224,
16 "longitude": -122.08421
17 },
18 "date": "2024-11-04",
19 "current_time": "05:42:37.429",
20 "sunrise": "06:37",
21 "sunset": "17:06",
22 "sun_status": "-",
23 "solar_noon": "11:51",
24 "day_length": "10:29",
25 "sun_altitude": -11.233664962711332,
26 "sun_distance": 148361706.39355108,
27 "sun_azimuth": 101.18075504079837,
28 "moonrise": "09:56",
29 "moonset": "19:01",
30 "moon_status": "-",
31 "moon_altitude": -44.88852591210425,
32 "moon_distance": 396268.3036138962,
33 "moon_azimuth": 93.53924174509945,
34 "moon_parallactic_angle": -63.45786017771775,
35 "moon_phase": "WAXING_CRESCENT",
36 "moon_illumination_percentage": "8.54",
37 "moon_angle": 33.98061036315428
38}
Note: When you get the astronomical information through an IP address, API will also return the extra fields about place information along with the astronomical information.
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:
Note:In above examples, we used API Key everywhere. Astronomy API can be called from client side JavaScript with Request Origin authentication as well on paid plans.
The astronomy information lookup using an IP address can include geolocation information in the following languages:
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:
Only the paid plan subscriptions can get the response in languages other than English. All the other subscriptions will only get the response in English.
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:
Alternatively, you can also call this endpoint with ip address and date parameters:
Note:Date must be in 'YYYY-MM-DD' format. No other format will be accepted and by default, current date will be used. All the astronomical information is calculated at the current time of day at the provided location.
Field | Type | Description | Can be empty? |
---|---|---|---|
location.location | string | Location is the decoded form of the string you provided for searching. | Yes |
location.continent_code | string | 2-letter code of the continent. | Yes |
location.continent_name | string | Name of the continent. | Yes |
location.country_code2 | string | Country code (ISO 3166-1 alpha-2) of the country. | Yes |
location.country_code3 | string | Country code (ISO 3166-1 alpha-3) of the country. | Yes |
location.country | string | Name of the country. It is returned in case of location search. | Yes |
location.country_name | string | Name of the country. | Yes |
location.country_name_official | string | Formal name of the country. | Yes |
location.is_eu | boolean | Is the country belong to European Union? | Yes |
location.state | string | Name of the state/province/region. It is returned in case of location search. | Yes |
location.state_prov | string | Name of the state/province/region. | Yes |
location.state_code | string | Code of the state/province/region. | Yes |
location.district | string | Name of the district or county. | Yes |
location.city | string | Name of the city. | Yes |
location.locality | string | Smaller area, part or region of a city. | Yes |
location.zipcode | string | ZIP/Postal code of the place. | Yes |
location.latitude | float | Latitude of the place. | No |
location.longitude | float | Longitude of the place. | No |
date | string | Provided or current date in the format 'yyyy-MM-dd'. | No |
current_time | string | Current time of the extracted location in the format 'HH:mm:ss.SSS'. | No |
sunrise | string | Time at which sun rises at the extracted location in the format 'HH:mm'. | No |
sunset | string | Time at which sun sets at the extracted location in the format 'HH:mm'. | No |
sun_status* | string | Represents the sun rise and sun set status. | No |
solar_noon | string | The time of day when the sun is at its highest point in the sky, in the format 'HH:mm'. | No |
day_length | string | The total length of daylight for the current day in format 'HH:mm', representing the time from sunrise to sunset. | No |
sun_altitude | float | The sun's altitude angle above the horizon at current_time , measured in degrees. | No |
sun_distance | float | The distance from Earth to the sun at current_time , in kilometers. | No |
sun_azimuth | float | The azimuth angle of the sun at current_time , indicating its compass direction in degrees. | No |
moonrise | string | Time at which moon rises at the extracted location in the format 'HH:mm'. | No |
moonset | string | Time at which moon sets at the extracted location in the format 'HH:mm'. | No |
moon_status* | string | Represents the moon rise and moon set status. | No |
moon_altitude | float | The moon's altitude angle above the horizon at current_time , measured in degrees. | No |
moon_distance | float | The distance from Earth to the moon at current_time , in kilometers. | No |
moon_azimuth | float | The azimuth angle of the moon at current_time , indicating its compass direction in degrees. | No |
moon_parallactic_angle | float | The angle between the celestial pole and the moon's position relative to the location, measured in degrees. | No |
moon_phase | string | The current phase of the moon (e.g., "WAXING_CRESCENT"), indicating its position in the lunar cycle. | No |
moon_illumination_percentage | string | The percentage of the moon's surface that is illuminated by sunlight, as viewed from Earth. | No |
moon_angle | float | The angular diameter of the moon as observed from Earth, measured in degrees. | 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 perpetual daylight. Conversely, if the sun remains below the twilight angle, the status may read "Always below the twilight angle", indicating that the sun does not rise within the current 24-hour period.
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.
Astronomy API returns HTTP status code 200 for a successful API request along with the response.
While, 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 Status | Description |
---|---|
400 Bad Request | It is returned for one of the following reasons:
|
401 Unauthorized | It is returned for one of the following reasons:
|
405 Method Not Allowed |
|
429 Too Many Requests | It is returned for one of the following reasons:
|
499 Client Closed Request |
|
5XX Server Side Error |
|
To facilitate the developers, we have added some SDKs for various programming languages. The detailed documentation on how to use these SDKs is available in the respective SDK's documentation page linked below.
Our SDKs are also available on Github. Feel free to help us improve them. Following are the available SDKs: