Sunrise and Sunset API

Beginner's Pick Science & Math / No Auth Required Beginner HTTPS
Free to Use
82 A
Measured Score 0 50 100 Speed 19/30 Consistency 20/20 Security 20/20 Browser access 15/15 Transparency 8/15 TESTED 2026-08-10

Overview

The Sunrise and Sunset API returns accurate sunrise, sunset, solar noon, and day length data for any latitude/longitude coordinate on Earth. It is completely free and requires no API key, making it one of the easiest APIs to start with. Use it to build apps that adapt content or UI based on daylight, from smart home automation to photography planning tools.

Beginner Tip

Pass any latitude and longitude plus a date to get precise solar times — for example, use your city coordinates to see today sunrise and sunset. All times are returned in UTC by default; add tzid=YOUR_TIMEZONE to get local times.

Measurement Record

What actually happened when we called this API from our own infrastructure. Every value below was recorded by the request, not copied from the provider's documentation.

Request
GET https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=today&formatted=0
Result
HTTP 200 · application/json · 495 bytes · compressed
Response time
186 ms (median of 3) · fastest 183 ms
Transport
TLSv1.3 · TLS_AES_256_GCM_SHA384 · certificate issued by Google Trust Services
Browser CORS
Allowed — Access-Control-Allow-Origin: *
Served by
cloudflare
Recorded
2026-08-10

Fields Returned

Top-level fields present in the response we captured, with the type and value we actually received.

Field Type Value received
sunrise string (date) 2026-08-10T10:00:18+00:00
sunset string (date) 2026-08-11T00:02:26+00:00
solar_noon string (date) 2026-08-10T17:01:22+00:00
day_length integer 50528
civil_twilight_begin string (date) 2026-08-10T09:31:59+00:00
civil_twilight_end string (date) 2026-08-11T00:30:45+00:00
nautical_twilight_begin string (date) 2026-08-10T08:55:36+00:00
nautical_twilight_end string (date) 2026-08-11T01:07:08+00:00
astronomical_twilight_begin string (date) 2026-08-10T08:16:10+00:00
astronomical_twilight_end string (date) 2026-08-11T01:46:34+00:00

Captured Response

Captured from a real request to https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=today&formatted=0 on 2026-08-10. Long arrays and nested objects are truncated to keep the shape readable.

JSON Response · Captured
{
  "results": {
    "sunrise": "2026-08-10T10:00:18+00:00",
    "sunset": "2026-08-11T00:02:26+00:00",
    "solar_noon": "2026-08-10T17:01:22+00:00",
    "day_length": 50528,
    "civil_twilight_begin": "2026-08-10T09:31:59+00:00",
    "civil_twilight_end": "2026-08-11T00:30:45+00:00",
    "nautical_twilight_begin": "2026-08-10T08:55:36+00:00",
    "nautical_twilight_end": "2026-08-11T01:07:08+00:00",
    "astronomical_twilight_begin": "2026-08-10T08:16:10+00:00",
    "astronomical_twilight_end": "2026-08-11T01:46:34+00:00"
  },
  "status": "OK",
  "tzid": "UTC"
}

Field Reference

status Request status — OK on success or INVALID_REQUEST when parameters are wrong.

Implementation Example

Calls a real endpoint of this API. Replace any placeholder credentials with your own key.

Request
const url = "https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=today&formatted=0";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

How This API Fails

We deliberately sent this API a broken request and recorded exactly what came back on 2026-08-10. Knowing the shape of an error before you hit it makes error handling much easier to write.

HTTP 404 Requesting a path that does not exist text/html

Returned an HTML error page rather than JSON — worth knowing if your client assumes every response can be parsed as JSON.

Common Errors & Troubleshooting

Generated guidance based on this API's documentation, not observed by us. Treat it as a starting point and check against the provider's own error reference.

Times returned in UTC when local time expected The API defaults to UTC unless a timezone is specified.
Add the tzid parameter with an IANA timezone identifier such as tzid=Europe/London to receive times in local timezone.
Identical sunrise/sunset for polar regions Near the poles, the sun may not set or rise at all on certain dates due to midnight sun or polar night.
Check the day_length field — a value of 0 or 86400 seconds indicates polar night or midnight sun respectively.
400 Bad Request Latitude or longitude values are out of range or formatted incorrectly.
Ensure latitude is between -90 and 90, and longitude is between -180 and 180, using decimal degrees.

Measured Score Breakdown

Live HTTP request to the API endpoint

Speed 19/30
Consistency 20/20
Security 20/20
Browser access 15/15
Transparency 8/15
Endpoint Response Time 186ms

Fully tested on Aug 10, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS NO
Category Science & Math
Difficulty Beginner
Endpoint last called: 2026-08-10

Related Tags

Similar APIs

View All →