Overview
Sunrise Sunset works by calculating the sunrise and sunset times based on the location and date provided. It returns the sunrise and sunset times in a structured format.
Endpoint
One host, one path per API. The block below shows this call in four languages; every one of them is the same HTTP request. Making requests covers the timeouts, retries and parameter rules that apply to all of them. The SDKs wrap the same call in a typed client.
curl "https://api.apiverve.com/v1/sunrisesunset?lat=36.72016&lon=-4.42034&date=01-16-2026" \
-H "x-api-key: your_api_key_here"const res = await fetch('https://api.apiverve.com/v1/sunrisesunset?lat=36.72016&lon=-4.42034&date=01-16-2026', {
headers: { 'x-api-key': 'your_api_key_here' },
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();
console.log(data);import requests
res = requests.get(
"https://api.apiverve.com/v1/sunrisesunset?lat=36.72016&lon=-4.42034&date=01-16-2026",
headers={"x-api-key": "your_api_key_here"},
timeout=15,
)
res.raise_for_status()
print(res.json()["data"])package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.apiverve.com/v1/sunrisesunset?lat=36.72016&lon=-4.42034&date=01-16-2026", nil)
req.Header.Set("x-api-key", "your_api_key_here")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
out, _ := io.ReadAll(res.Body)
fmt.Println(string(out))
}Replace your_api_key_here with the key from your dashboard. When the inputs arrive as a list rather than one at a time, batch requests run up to 200 of them through this same API in a single call.
Authentication
Send your key in the x-api-key header. That is the only auth step — there is no token exchange and no per-endpoint scope to configure. Authentication covers creating, rotating and revoking keys.
A 401 means the key is missing, invalid or expired. A 403 means the key is valid but not permitted here — blocked by a key restriction or an IP allow-list. Running out of credits is a 429.
Parameters
Sent in the query string. Premium parameters are accepted on every plan but only take effect on plans that include them.
| Parameter | Type | Description |
|---|---|---|
latRequired | number | The latitude of the location range -90–90 |
lonRequired | number | The longitude of the location range -180–180 |
dateOptionalPremium | string | The date for which you want to get the sunrise and sunset times (e.g., MM-DD-YYYY : 01-01-2022) date |
Response
Every API returns the same three top-level keys, so one response handler covers your whole integration: status, error and data. Only data changes shape. Response format covers the envelope, the other output formats and how premium fields are withheld.
{
"status": "ok",
"error": null,
"data": {
"solarNoon": "2025-12-16T12:14:40.51Z",
"sunrise": "2025-12-16T07:24:56.165Z",
"sunset": "2025-12-16T17:04:24.854Z",
"sunriseEnd": "2025-12-16T07:27:58.828Z",
"sunsetStart": "2025-12-16T17:01:22.192Z",
"dawn": "2025-12-16T06:56:02.774Z",
"dusk": "2025-12-16T17:33:18.245Z",
"nauticalDawn": "2025-12-16T06:23:38.134Z",
"nauticalDusk": "2025-12-16T18:05:42.886Z",
"nightEnd": "2025-12-16T05:52:07.048Z",
"night": "2025-12-16T18:37:13.971Z",
"goldenHourEnd": "2025-12-16T08:05:08.406Z",
"goldenHour": "2025-12-16T16:24:12.613Z"
}
}Response fields
Paths are relative to data. Premium fields are absent rather than zeroed on plans that do not include them, so check for presence instead of comparing to 0.
| Field | Type | Example | Description |
|---|---|---|---|
solarNoonPremium | string | "2025-12-16T12:14:40.51Z" | Solar noon time |
sunrise | string | "2025-12-16T07:24:56.165Z" | Sunrise time in ISO 8601 format |
sunset | string | "2025-12-16T17:04:24.854Z" | Sunset time in ISO 8601 format |
sunriseEnd | string | "2025-12-16T07:27:58.828Z" | Moment the sun's disc has fully cleared the horizon, in UTC |
sunsetStart | string | "2025-12-16T17:01:22.192Z" | Moment the sun's disc first touches the horizon at sunset, in UTC |
dawn | string | "2025-12-16T06:56:02.774Z" | Start of civil twilight, when the sun is 6 degrees below the horizon |
dusk | string | "2025-12-16T17:33:18.245Z" | End of civil twilight, when the sun drops 6 degrees below the horizon |
nauticalDawn | string | "2025-12-16T06:23:38.134Z" | Start of nautical twilight, when the sun is 12 degrees below the horizon |
nauticalDusk | string | "2025-12-16T18:05:42.886Z" | End of nautical twilight, when the sun drops 12 degrees below the horizon |
nightEnd | string | "2025-12-16T05:52:07.048Z" | End of astronomical night, when the sun rises above 18 degrees below the horizon |
night | string | "2025-12-16T18:37:13.971Z" | Start of astronomical night, when the sun drops 18 degrees below the horizon |
goldenHourEnd | string | "2025-12-16T08:05:08.406Z" | End of the morning golden hour, when soft low-angle light gives way to daylight |
goldenHour | string | "2025-12-16T16:24:12.613Z" | Start of the evening golden hour, when the light turns soft and low-angle |
Errors
Read the HTTP status first, then error for the specific reason. The body names the parameter that has to change. Error handling covers the full status list and which of them are worth retrying.
| Status | Meaning | What to do |
|---|---|---|
400 | Input was rejected | Read error; it names the parameter. |
401 | Key missing or invalid | Check the header name and the key value. |
403 | Key valid, but not permitted | A key restriction or IP allow-list; see key scoping. |
429 | Rate limited, or out of credits | Read error to tell them apart; see rate limits. |
Use cases
- Photography
- Use the Sunrise Sunset API to get sunrise and sunset times for photography. Use the data to plan shoots, capture golden hours, and optimize lighting
- Outdoor Activities
- Plan outdoor activities by using the Sunrise Sunset API to get sunrise and sunset times. Use the data to schedule events, organize trips, and optimize experiences
- Gardening
- Get sunrise and sunset times by using the Sunrise Sunset API for gardening. Use the data to plan planting, schedule harvests, and optimize crop growth
- Weather App
- Use the Sunrise Sunset API to get sunrise and sunset times for a weather app. Use the data to display weather information, provide forecasts, and offer alerts
Other ways to use Sunrise Sunset
Set up Sunrise Sunset on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them — one key, one balance.
Related
More in Weather: