Sun Position API
Overview
To use Sun Position, you need an API key. You can get one by creating a free account and visiting your dashboard.
GET Endpoint
https://api.apiverve.com/v1/sunpositionExample
How to call the Sun Position API in different programming languages.
curl -X GET \
"https://api.apiverve.com/v1/sunposition?lat=37.7749&lon=-122.4194&date=01-16-2026&time=14%3A30&timezone=America%2FLos_Angeles" \
-H "X-API-Key: your_api_key_here"const response = await fetch('https://api.apiverve.com/v1/sunposition?lat=37.7749&lon=-122.4194&date=01-16-2026&time=14%3A30&timezone=America%2FLos_Angeles', {
method: 'GET',
headers: {
'X-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);import requests
headers = {
'X-API-Key': 'your_api_key_here',
'Content-Type': 'application/json'
}
response = requests.get('https://api.apiverve.com/v1/sunposition?lat=37.7749&lon=-122.4194&date=01-16-2026&time=14%3A30&timezone=America%2FLos_Angeles', headers=headers)
data = response.json()
print(data)package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.apiverve.com/v1/sunposition?lat=37.7749&lon=-122.4194&date=01-16-2026&time=14%3A30&timezone=America%2FLos_Angeles", nil)
req.Header.Set("X-API-Key", "your_api_key_here")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}{
"status": "ok",
"error": null,
"data": {
"date": "01-16-2026",
"time": "14:30",
"timezone": "America/Los_Angeles",
"timestampUTC": "2026-01-16T22:30:00.000Z",
"coordinates": {
"latitude": 37.7749,
"longitude": -122.4194
},
"sun": {
"altitude": 0.41616137328975444,
"azimuth": 0.5817558808515568,
"altitudeDegrees": 23.844,
"azimuthDegrees": 33.332,
"compassBearing": 213.332,
"isDaylight": true,
"declination": -20.7961,
"rightAscension": 19.9228,
"hourAngle": 2.174,
"distance": 0.983786
},
"equationOfTime": -9.88,
"airMass": 2.454,
"clearSky": {
"directNormal": 702.4,
"globalHorizontal": 284.9
},
"shadowRatio": 2.254,
"panelAim": {
"tilt": 66.07,
"azimuth": 213.44
}
}
}Authentication
The Sun Position API requires authentication via API key. Include your API key in the request header:
X-API-Key: your_api_key_hereInteractive API Playground
Test the Sun Position API directly in your browser with live requests and responses.
Parameters
The following parameters are available for the Sun Position API:
Get Sun Position Data
| Parameter | Type | Required | Description | Default | Example |
|---|---|---|---|---|---|
lat | number | required | The latitude of the location Range: -90 - 90 | - | |
lon | number | required | The longitude of the location Range: -180 - 180 | - | |
datePremium | string | optional | The date to get the sun position data for (MM-DD-YYYY) Format: date (e.g., 01-16-2026) | - | |
time | string | optional | The time of day for the calculation (HH:mm format, 24-hour), read in the timezone of the coordinates. Defaults to 00:00 if not provided Format: time (e.g., 14:30) | - | |
timezone | string | optional | IANA timezone to read the date and time in, such as America/Los_Angeles. Defaults to the timezone of the coordinates Format: timezone (e.g., America/Los_Angeles) | - |
Response
The Sun Position API returns responses in JSON, XML, YAML, and CSV formats. The JSON response is shown in the Example section above; alternative formats below.
Other Response Formats
<?xml version="1.0" encoding="UTF-8"?>
<response>
<status>ok</status>
<error xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<data>
<date>01-16-2026</date>
<time>14:30</time>
<timezone>America/Los_Angeles</timezone>
<timestampUTC>2026-01-16T22:30:00.000Z</timestampUTC>
<coordinates>
<latitude>37.7749</latitude>
<longitude>-122.4194</longitude>
</coordinates>
<sun>
<altitude>0.41616137328975444</altitude>
<azimuth>0.5817558808515568</azimuth>
<altitudeDegrees>23.844</altitudeDegrees>
<azimuthDegrees>33.332</azimuthDegrees>
<compassBearing>213.332</compassBearing>
<isDaylight>true</isDaylight>
<declination>-20.7961</declination>
<rightAscension>19.9228</rightAscension>
<hourAngle>2.174</hourAngle>
<distance>0.983786</distance>
</sun>
<equationOfTime>-9.88</equationOfTime>
<airMass>2.454</airMass>
<clearSky>
<directNormal>702.4</directNormal>
<globalHorizontal>284.9</globalHorizontal>
</clearSky>
<shadowRatio>2.254</shadowRatio>
<panelAim>
<tilt>66.07</tilt>
<azimuth>213.44</azimuth>
</panelAim>
</data>
</response>
status: ok
error: null
data:
date: 01-16-2026
time: '14:30'
timezone: America/Los_Angeles
timestampUTC: '2026-01-16T22:30:00.000Z'
coordinates:
latitude: 37.7749
longitude: -122.4194
sun:
altitude: 0.41616137328975444
azimuth: 0.5817558808515568
altitudeDegrees: 23.844
azimuthDegrees: 33.332
compassBearing: 213.332
isDaylight: true
declination: -20.7961
rightAscension: 19.9228
hourAngle: 2.174
distance: 0.983786
equationOfTime: -9.88
airMass: 2.454
clearSky:
directNormal: 702.4
globalHorizontal: 284.9
shadowRatio: 2.254
panelAim:
tilt: 66.07
azimuth: 213.44
| key | value |
|---|---|
| date | 01-16-2026 |
| time | 14:30 |
| timezone | America/Los_Angeles |
| timestampUTC | 2026-01-16T22:30:00.000Z |
| coordinates | {latitude:37.7749,longitude:-122.4194} |
| sun | {altitude:0.41616137328975444,azimuth:0.5817558808515568,altitudeDegrees:23.844,azimuthDegrees:33.332,compassBearing:213.332,isDaylight:true,declination:-20.7961,rightAscension:19.9228,hourAngle:2.174,distance:0.983786} |
| equationOfTime | -9.88 |
| airMass | 2.454 |
| clearSky | {directNormal:702.4,globalHorizontal:284.9} |
| shadowRatio | 2.254 |
| panelAim | {tilt:66.07,azimuth:213.44} |
Response Structure
All API responses follow a consistent structure with the following fields:
| Field | Type | Description | Example |
|---|---|---|---|
status | string | Indicates whether the request was successful ("ok") or failed ("error") | ok |
error | string | null | Contains error message if status is "error", otherwise null | null |
data | object | null | Contains the API response data if successful, otherwise null | {...} |
Learn more about response formats β
Response Data Fields
When the request is successful, the data object contains the following fields:
| Field | Type | Sample Value | Description |
|---|---|---|---|
date | string | Date the position was calculated for | |
time | string | Time of day the position was calculated for | |
timezone | string | IANA timezone the date and time were read in, resolved from the coordinates unless one was given | |
timestampUTC | string | The instant the position was calculated for, in UTC, so the answer is unambiguous | |
coordinates | object | The point on Earth the position was calculated from | |
β latitude | number | Latitude used for the calculation | |
β longitude | number | Longitude used for the calculation | |
sun | object | Where the sun sits in the sky at that time and place | |
β altitude | number | Height of the sun above the horizon, in radians; negative when the sun is below the horizon. Multiply by 180/PI for degrees | |
β azimuth | number | Direction of the sun, in radians measured from due south and increasing westward. Multiply by 180/PI for degrees, then add 180 for a compass bearing | |
β altitudeDegrees | number | Height of the sun above the horizon in degrees; negative when below | |
β azimuthDegrees | number | Direction of the sun in degrees from due south, increasing westward | |
β compassBearing | number | Direction of the sun as a compass bearing, 0 for north and 180 for south | |
β isDaylight | boolean | Whether the sun is above the horizon at this time and place | |
β declinationPremium | number | Angle of the sun north or south of the celestial equator, in degrees | |
β rightAscensionPremium | number | Position of the sun along the celestial equator, in hours | |
β hourAnglePremium | number | Hours since the sun crossed the local meridian; negative before solar noon | |
β distancePremium | number | Distance from Earth to the sun in astronomical units | |
equationOfTimePremium | number | Minutes a sundial reads ahead of the clock at this date; negative when it reads behind | |
airMassPremium | number | How much atmosphere the sunlight crosses, as a multiple of straight overhead; null after dark |
Headers
Only X-API-Key is required. Optional headers include Accept for response format negotiation (JSON, XML, or YAML), User-Agent, and X-Request-ID for request tracing. See all request headers β
GraphQL AccessALPHA
Access Sun Position through GraphQL to combine it with other API calls in a single request. Query only the sun position data you need with precise field selection, and orchestrate complex data fetching workflows.
Credit Cost: Each API called in your GraphQL query consumes its standard credit cost.
POST https://api.apiverve.com/v1/graphqlquery {
sunposition(
input: {
lat: 37.7749
lon: -122.4194
date: "01-16-2026"
time: "14:30"
timezone: "America/Los_Angeles"
}
) {
date
time
timezone
timestampUTC
coordinates {
latitude
longitude
}
sun {
altitude
azimuth
altitudeDegrees
azimuthDegrees
compassBearing
isDaylight
declination
rightAscension
hourAngle
distance
}
equationOfTime
airMass
clearSky {
directNormal
globalHorizontal
}
shadowRatio
panelAim {
tilt
azimuth
}
}
}Note: Authentication is handled via the x-api-key header in your GraphQL request, not as a query parameter.
CORS Support
The Sun Position API accepts cross-origin requests from any origin, so it can be called directly from browser-based applications without a proxy. See CORS support β
Rate Limiting
Sun Position requests are throttled per minute on the Free plan and unthrottled on paid plans. Exceeding the limit returns 429 Too Many Requests; rate-limit usage is reported in the X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset response headers. See per-plan limits and best practices β
Error Codes
The Sun Position API uses standard HTTP status codes β 200 on success, 400 for invalid parameters, 401 for missing or invalid keys, 403 for insufficient credits, 429 for rate-limit exhaustion, and 500/503 for server-side issues. Each error response includes an X-Request-ID header you can quote when contacting support. See full error handling guide β
SDKs for Sun Position
Official Sun Position packages on npm, PyPI, NuGet, and JitPack β plus a Postman collection and an OpenAPI spec. See the SDK guide β
No-Code Integrations
Sun Position works with Zapier, Make, Pipedream, n8n, and Power Automate using the same API key. See setup guides β
Frequently Asked Questions
How do I get an API key for Sun Position?
How many credits does Sun Position cost?
Each successful Sun Position API call consumes credits based on plan tier. Check the pricing section above for the exact credit cost. Failed requests and errors don't consume credits, so you only pay for successful sun position lookups.
Can I use Sun Position in production?
The free plan is for testing and development only. For production use of Sun Position, upgrade to a paid plan (Starter, Pro, or Mega) which includes commercial use rights, no attribution requirements, and guaranteed uptime SLAs. All paid plans are production-ready.
Can I use Sun Position from a browser?
What happens if I exceed my Sun Position credit limit?
When you reach your monthly credit limit, Sun Position API requests will return an error until you upgrade your plan or wait for the next billing cycle. You'll receive notifications at 80% and 95% usage to give you time to upgrade if needed.
Other ways to use Sun Position
Set up Sun Position on APIVerve, or reach the same source a different way. Your APIVerve account and credits work on all of them β one key, one balance.








