# Sun Position API — sunrise, sunset & golden hour times (`aimojo/sun-position-api`) Actor

Compute sunrise, sunset, golden hour and twilight times plus the sun's elevation and azimuth for any locations and dates, in each location's local time zone. One row per location and date, or per location and time.

- **URL**: https://apify.com/aimojo/sun-position-api.md
- **Developed by:** [AI Mojo](https://apify.com/aimojo) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 sun data rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

### Sun position API — sunrise, sunset, golden hour and twilight times

Sun Position API computes sunrise, sunset, solar noon, day length, golden hour, blue hour and civil, nautical and astronomical twilight times, plus the sun's elevation and azimuth, for any list of locations and dates. Every time is given in each location's local time zone, which is looked up from its coordinates. You get one row per location and date, or one row per location and time when you set a step in minutes. It is built for photographers planning golden hour and blue hour shoots, solar engineers and architects studying sun angles and shading, agriculture teams tracking day length, and app developers who need sun times in bulk without running their own calculations. To try it, press **Start**: the prefilled Greenwich Observatory example returns its result in seconds.

### How to get sunrise, sunset and golden hour times

1. Add your places to **Locations** as a JSON list. Each location needs a latitude and a longitude, and can have a name.
2. Set **Start date**, and optionally **End date** to compute a range of local calendar dates.
3. Optionally set **Step (minutes)** to get the sun elevation and sun azimuth through each day, for example every 15 minutes.
4. Optionally set **Time zone** to use one IANA time zone for every location instead of each location's own local time zone.
5. Press **Start** and wait for the run to finish.
6. Open the **Output** tab to view the rows, then download them as JSON, CSV, Excel, XML or HTML.
7. To automate it, call the actor through the Apify API, or connect it to Make, Zapier, Google Sheets or a webhook with Apify integrations.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `locations` | array of objects | none (required) | The places to compute sun times and sun positions for. Each has a `latitude` (-90 to 90), a `longitude` (-180 to 180, east positive) and an optional `name`. Up to 1,000 locations. |
| `startDate` | string | none (required) | The first local calendar date to compute, as YYYY-MM-DD. |
| `endDate` | string | the start date | The last local calendar date to compute, as YYYY-MM-DD, at most 366 days after the start date counting both. |
| `stepMinutes` | integer | none | When set (1 to 1440), returns one row per location for every step through each local day, with the sun's elevation and azimuth at that time. Leave empty for one row per location per date. |
| `timeZone` | string | looked up per location | An IANA time zone name such as Europe/London, used for every location instead of the zone looked up from its coordinates. |

Example input (the prefilled values):

```json
{
  "locations": [{ "name": "Greenwich Observatory", "latitude": 51.4769, "longitude": -0.0005 }],
  "startDate": "2026-06-21"
}
```

### Output

Each dataset item is one location and local date (a once-per-day row), or one location and time when **Step (minutes)** is set. A sun event that does not happen on the date is `null`.

Example row for the prefilled input. On the June solstice the sun never sinks 18° below the horizon at Greenwich, so astronomical twilight is `null`:

```json
{
  "id": "51.4769,-0.0005,2026-06-21",
  "name": "Greenwich Observatory",
  "latitude": 51.4769,
  "longitude": -0.0005,
  "timeZone": "Europe/London",
  "date": "2026-06-21",
  "time": null,
  "elevation": null,
  "azimuth": null,
  "polar": null,
  "sunrise": "2026-06-21T04:43:59+01:00",
  "sunset": "2026-06-21T21:22:01+01:00",
  "solarNoon": "2026-06-21T13:03:00+01:00",
  "dayLengthMinutes": 998.03,
  "civilDawn": "2026-06-21T03:56:17+01:00",
  "civilDusk": "2026-06-21T22:09:43+01:00",
  "nauticalDawn": "2026-06-21T02:41:50+01:00",
  "nauticalDusk": "2026-06-21T23:24:10+01:00",
  "astronomicalDawn": null,
  "astronomicalDusk": null,
  "goldenHourMorningStart": "2026-06-21T04:15:45+01:00",
  "goldenHourMorningEnd": "2026-06-21T05:38:11+01:00",
  "goldenHourEveningStart": "2026-06-21T20:27:49+01:00",
  "goldenHourEveningEnd": "2026-06-21T21:50:14+01:00",
  "blueHourMorningStart": "2026-06-21T03:56:17+01:00",
  "blueHourMorningEnd": "2026-06-21T04:15:45+01:00",
  "blueHourEveningStart": "2026-06-21T21:50:14+01:00",
  "blueHourEveningEnd": "2026-06-21T22:09:43+01:00"
}
```

All times are local time in the location's time zone, as ISO 8601 with that zone's offset.

| Field | Type | Description |
|---|---|---|
| `id` | string | Stable row ID: `<latitude>,<longitude>,<date>`, plus `,<UTC instant>` for a row at a specific time. It stays the same across runs. |
| `name` | string or null | The location's name as given in the input. |
| `latitude` | number | The location's latitude in decimal degrees (north positive). |
| `longitude` | number | The location's longitude in decimal degrees (east positive). |
| `timeZone` | string | The location's IANA time zone, for example Europe/London. |
| `date` | string | The local calendar date, YYYY-MM-DD. All sun events in the row happen on this date. |
| `time` | string or null | The instant the sun elevation and sun azimuth are computed for. Null for a once-per-day row. |
| `elevation` | number or null | Sun elevation above the horizon in degrees (negative below it), geometric, without atmospheric refraction. Null when `time` is null. |
| `azimuth` | number or null | Sun azimuth in degrees clockwise from true north (0 to 360). Null when `time` is null. |
| `polar` | string or null | Polar day or night: `day` when the sun never sets on the date, `night` when it never rises, otherwise null. |
| `sunrise` | string or null | When the sun's upper edge rises above the horizon. |
| `sunset` | string or null | When the sun's upper edge sets below the horizon. |
| `solarNoon` | string or null | When the sun is highest in the sky. |
| `dayLengthMinutes` | number | Minutes from sunrise to sunset; 1440 in polar day and 0 in polar night. |
| `civilDawn` | string or null | Civil twilight begins: the sun's center rises to 6° below the horizon. |
| `civilDusk` | string or null | Civil twilight ends: the sun's center sets to 6° below the horizon. |
| `nauticalDawn` | string or null | Nautical twilight begins: the sun rises to 12° below the horizon. |
| `nauticalDusk` | string or null | Nautical twilight ends: the sun sets to 12° below the horizon. |
| `astronomicalDawn` | string or null | Astronomical twilight begins: the sun rises to 18° below the horizon. |
| `astronomicalDusk` | string or null | Astronomical twilight ends: the sun sets to 18° below the horizon. |
| `goldenHourMorningStart` | string or null | Morning golden hour starts: the sun rises to 4° below the horizon. |
| `goldenHourMorningEnd` | string or null | Morning golden hour ends: the sun rises to 6° above the horizon. |
| `goldenHourEveningStart` | string or null | Evening golden hour starts: the sun sets to 6° above the horizon. |
| `goldenHourEveningEnd` | string or null | Evening golden hour ends: the sun sets to 4° below the horizon. |
| `blueHourMorningStart` | string or null | Morning blue hour starts: the sun rises to 6° below the horizon. |
| `blueHourMorningEnd` | string or null | Morning blue hour ends: the sun rises to 4° below the horizon. |
| `blueHourEveningStart` | string or null | Evening blue hour starts: the sun sets to 4° below the horizon. |
| `blueHourEveningEnd` | string or null | Evening blue hour ends: the sun sets to 6° below the horizon. |

The run also saves a short summary in the **Run summary** output.

### Pricing

This actor uses pay-per-event pricing: you pay for each sun data row delivered to your dataset, and nothing for pages or requests.

#### How much does it cost to get 1,000 results?

$0.50 per 1,000 sun data rows ($0.0005 per row), lower on paid Apify plans.

- You're charged only for rows delivered to your dataset.
- The run stops when it reaches your **maximum charge per run** setting, so you never pay more than you set.
- Apify adds a small fee for each run start.

For example, one location for a full year of dates is 365 rows, about $0.18. One location every 15 minutes for a typical 24-hour day is 96 rows, about $0.05.

### Limits & accuracy

- Up to 1,000 locations, 366 days and 1,000,000 rows per run. A larger input is rejected before any row is computed.
- Sun elevation and sun azimuth are within about half a degree of NOAA's solar calculator when the sun is more than 5° above the horizon.
- Sun elevation is geometric: no atmospheric refraction is applied, so near the horizon it reads a little lower than what you see.
- In polar day or polar night, `polar` is `day` or `night` and `sunrise` and `sunset` are null.

### Compliance & licences

- All results are computed. No website or API is contacted at run time, and no personal data is collected.
- Sun times and positions use the [suncalc](https://github.com/mourner/suncalc) library, BSD-2-Clause licence, Copyright (c) 2014, Vladimir Agafonkin.
- Time zones are looked up offline with the [tz-lookup](https://github.com/darkskyapp/tz-lookup) library, released under CC0 1.0 by The Dark Sky Company, LLC. This licence covers the library itself.
- The time zone boundary data inside tz-lookup is sourced from Evan Siroky's [timezone-boundary-builder](https://github.com/evansiroky/timezone-boundary-builder/), which is built from OpenStreetMap. That upstream project's own README ("Licenses" section) states that its output data is licensed under the [Open Data Commons Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/). Time zone boundary data © [OpenStreetMap contributors](https://www.openstreetmap.org/copyright).

### FAQ

#### Is it legal to use this sun data?

The actor collects nothing from any website: every sunrise, sunset and sun position is calculated from astronomy formulas, and no personal data is involved. You are still responsible for how you use the data; if you are unsure, ask a lawyer about your use case.

#### Which time zone are the times in?

Each location's local time zone, looked up from its coordinates. A point at sea gets a fixed-offset zone such as Etc/GMT+3. Set **Time zone** to use one zone for every location.

#### Why are some golden hour or twilight times null?

Near the poles, or near midsummer at high latitudes, the sun may never reach that angle on the date. The field is then null rather than a guess.

#### Where can I report an issue or request a feature?

Open the **Issues** tab on this actor's page and describe the input and what you expected.

# Changelog

This Actor's version history is a separate document: https://apify.com/aimojo/sun-position-api/changelog.md

# Actor input Schema

## `locations` (type: `array`):

The places to compute sun times and sun positions for, as a JSON list. Each location has a latitude (-90 to 90), a longitude (-180 to 180) and an optional name, for example {"name": "Greenwich Observatory", "latitude": 51.4769, "longitude": -0.0005}. Each location's time zone is looked up from its coordinates unless Time zone is set.

## `startDate` (type: `string`):

The first local calendar date to compute, as YYYY-MM-DD.

## `endDate` (type: `string`):

The last local calendar date to compute, as YYYY-MM-DD, at most 366 days after the start date counting both. Leave empty to compute the start date only.

## `stepMinutes` (type: `integer`):

When set, returns one row per location for every step through each local day, with the sun's elevation and azimuth at that time. Leave empty for one row per location per date with the day's sun times only.

## `timeZone` (type: `string`):

An IANA time zone name such as Europe/London. When set, it is used for every location instead of the zone looked up from each location's coordinates.

## Actor input object example

```json
{
  "locations": [
    {
      "name": "Greenwich Observatory",
      "latitude": 51.4769,
      "longitude": -0.0005
    }
  ],
  "startDate": "2026-06-21"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "locations": [
        {
            "name": "Greenwich Observatory",
            "latitude": 51.4769,
            "longitude": -0.0005
        }
    ],
    "startDate": "2026-06-21"
};

// Run the Actor and wait for it to finish
const run = await client.actor("aimojo/sun-position-api").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "locations": [{
            "name": "Greenwich Observatory",
            "latitude": 51.4769,
            "longitude": -0.0005,
        }],
    "startDate": "2026-06-21",
}

# Run the Actor and wait for it to finish
run = client.actor("aimojo/sun-position-api").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "locations": [
    {
      "name": "Greenwich Observatory",
      "latitude": 51.4769,
      "longitude": -0.0005
    }
  ],
  "startDate": "2026-06-21"
}' |
apify call aimojo/sun-position-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,aimojo/sun-position-api"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/gGapT2q5CyDSZtj6H/builds/eRA5G9mu7MOwhDwnN/openapi.json
