Astronomy8 MIN READ02 / 38
On this page

Planetary position API for the Moon, Sun and planets

The Position API returns coordinates for each selected body at one instant. Optional measurements are requested per body.

For a Moon calendar, request phase for the waxing or waning label, illumination for the lit percentage, and lunar age for days since new Moon.

1. Discover what your host supports

Set ASTROLOGY_BASE_URL to your running host, without a trailing slash, and ASTROLOGY_API_KEY to its key. A direct calculation host uses its configured host key; the customer gateway uses a customer API key. Keep both on your server. The following commands assume those variables are already set.

curl --fail-with-body "$ASTROLOGY_BASE_URL/astronomy/v1/capabilities" \
  --header "X-API-Key: $ASTROLOGY_API_KEY"

Read these discovery fields before constructing a request:

Field Check
bodies Your targets are supported by the configured primary provider
origins Your requested observer type is supported
coverage Provider-declared date coverage, expressed as Julian days TT
quantities Eligible bodies and observers for each optional quantity
definitions, definitionsVersion Units and scientific models used for the extras

Capabilities describe eligibility, not guaranteed availability for a particular date or supporting read. An enabled route also needs an initialized source. If astronomy is disabled, these routes are not mounted and return 404.

2. Choose your viewpoint

An observer determines the origin of the position. Geocentric means Earth’s centre; topocentric means a point on Earth’s surface; heliocentric means the Sun’s centre. Changing the origin changes the measurement, so keep it with any exported values.

Where are you measuring from? Three origin schematics. Geocentric starts at Earth centre; topocentric starts at a WGS84 surface location; heliocentric starts at Sun centre. Earth positions use apparent ecliptic of date, while Sun-centred positions use geometric J2000 ecliptic coordinates. Lunar phase and age remain geocentric. Where are you measuring from? Choose one origin for all primary positions in a request. Schematics are not to scale. Geocentric Origin: centre of Earth Topocentric Origin: an Earth surface location Heliocentric Origin: centre of Sun Earth target Earth target WGS84 latitude / longitude East-positive longitude; metres Sun target Apparent ecliptic of date Default when observer is omitted Apparent ecliptic of date Elevation defaults to zero Geometric ecliptic J2000 Sun cannot be a target here Lunar phase and age always keep a geocentric reference, even with another position origin. Observer-to-target position vector

Use one of these observer objects:

{ "type": "geocentric" }
{ "type": "topocentric", "latitude": 19.076, "longitude": 72.8777, "elevationMeters": 10 }
{ "type": "heliocentric" }

Omitting observer selects geocentric. Topocentric coordinates are WGS84 degrees with east-positive longitude, and elevation is metres, defaulting to zero. A heliocentric request cannot select the Sun as a target. Unsupported core observer geometry fails explicitly.

Earth observers return apparent ecliptic coordinates with the equinox of date. Heliocentric positions use simultaneous geometric coordinates in the fixed J2000 ecliptic frame. These are different conventions: compare results using evidence.position, not just their numbers.

3. Request positions first

Start with the Moon and Mars, without any extras:

curl --fail-with-body --request POST \
  "$ASTROLOGY_BASE_URL/astronomy/v1/positions?detail=full" \
  --header "X-API-Key: $ASTROLOGY_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "instant": "2026-11-12T12:00:00Z",
    "observer": { "type": "geocentric" },
    "bodies": [{ "body": "moon" }, { "body": "mars" }]
  }'

Use an ISO timestamp containing Z or an explicit offset, or integer epoch milliseconds. The response normalizes the instant to UTC. A successful response has instant, observer and bodies at the top level. The example uses detail=full to include the original evidence. Without a detail selector, root evidence is omitted. Use evidence=true to request that field explicitly. There is no chart envelope or data wrapper.

Each body has a position:

Field Meaning
longitudeDegrees Ecliptic longitude in [0, 360), in the declared frame
latitudeDegrees Angle above or below the ecliptic plane, in degrees
distanceAu Distance from the chosen observer, in astronomical units

These are ecliptic coordinates, not compass azimuth and altitude. Position latitude is distinct from the terrestrial latitude supplied for a topocentric observer. The response preserves your body order and includes only selected targets; internally needed Sun/Moon inputs do not add rows.

Supported physical targets are sun, moon, mercury, venus, mars, jupiter, saturn, uranus, neptune and pluto, subject to provider support. Orbital nodes belong to the astrology API. The bodies array must contain at least one entry, and each body may appear only once.

4. Add measurements independently for each body

Replace the first request body with this expanded example. It asks for lunar quantities on the Moon, solar separation on Venus, and only a position on Mars:

curl --fail-with-body --request POST \
  "$ASTROLOGY_BASE_URL/astronomy/v1/positions?detail=full" \
  --header "X-API-Key: $ASTROLOGY_API_KEY" \
  --header 'Content-Type: application/json' \
  --output positions.json \
  --data '{
    "instant": "2026-11-12T12:00:00Z",
    "observer": { "type": "geocentric" },
    "bodies": [
      { "body": "moon", "include": ["illumination", "moonPhase", "moonAge"] },
      { "body": "venus", "include": ["solarElongation"] },
      { "body": "mars" }
    ]
  }'

include belongs inside each body entry. Omitted include and include: [] both mean position only. Every selected body still gets its core position.

Select extras per body, read results per body Three body requests map to three ordered results. Moon selects illumination, phase and age; Venus selects elongation; Mars selects position only. Expected optional failures attach issues to the requesting body. Core failures and unexpected internal errors reject the request. Select extras per body, read results per body Every selected body gets a position. Each include list adds quantities to its own body only. REQUEST · one instant and observer HTTP 200 · when core positions succeed moon include: illumination, moonPhase, moonAge moon.position + illumination + moonPhase + moonAge Only successfully calculated extras appear. same body venus include: solarElongation venus.position + solarElongation, if successful same body mars include omitted (or empty array) mars.position No extras and no extra-related issues same body If a requested extra cannot be returned: Keep that body’s position; omit the extra; attach an INAPPLICABLE or UNAVAILABLE issue. Invalid input or a core acquisition failure rejects the request. Unexpected internal errors also propagate. Request-to-result mapping; row order is preserved

Include Successful output beside position When to use it
motion longitudeDegreesPerDay, latitudeDegreesPerDay, distanceAuPerDay Rates of change in the position frame; requires all three provider rates
solarElongation angleDegrees Great-circle separation from the Sun, 0–180°; Earth observers; zero for the Sun itself
illumination phaseAngleDegrees, illuminatedFraction, evidence Reflected-light bodies viewed from Earth; requires geometric source support
angularDiameter arcseconds Spherical disc size for observers outside the adopted mean radius; excludes rings and oblateness
moonPhase longitudeDifferenceDegrees, cycleFraction, label, reference Moon’s angular cycle progress using a geocentric reference
moonAge previousNewMoon, elapsedDays, reference, convergenceSeconds Time since the previous solved geocentric new moon

The output object uses the same name as the include, for example bodies[0].illumination.illuminatedFraction. Names are case-sensitive. Unknown fields, duplicate body entries, string-only body arrays, null includes, duplicate include names and top-level include are rejected before source reads. There is no merge or override behavior.

5. Interpret the three lunar measurements

Phase, illumination and age are different measurements Moon phase is apparent geocentric Moon-minus-Sun longitude divided by 360. Illumination uses a simultaneous geometric Sun-target-observer triangle to calculate lit fraction. Lunar age is elapsed 86400-second days since the preceding solved geocentric conjunction. Neither phase labels nor search convergence establish exact physical events or accuracy. Phase, illumination and age are different measurements Three different questions: angular progress, lit fraction and elapsed time. Illustrations are conceptual. moonPhase Where is the Moon in its cycle? illumination How much of the disc is lit? moonAge How long since the last new moon? 0° / new 90° 180° / full 270° Moon − Sun longitude cycleFraction = angle / 360 0.5 means 180° cycle progress. Labels use nearest 45° sectors. Reference: geocentric apparent Sun target observer phase angle illuminatedFraction: 0 to 1 Multiply by 100 for a percentage. Simultaneous geometric model Uses its own geometric evidence. previousNewMoon instant solved event now elapsedDays One day = 86400 seconds Bounded search for conjunction Not fraction × assumed month Reference: geocentric apparent A 0.5 cycle fraction does not mean 50% illumination. Numerical search convergence is not physical accuracy. Direction of cycle progress or elapsed time; triangle lines show geometric relationships

moonPhase.cycleFraction is the geocentric apparent Moon-minus-Sun longitude difference divided by 360. It describes angular progress around the cycle. Phase labels use the nearest 45° sector; new_moon is a sector label, not proof of an exact conjunction.

illumination.illuminatedFraction describes how much of the spherical disc is lit in the simultaneous Sun–target–observer model. Multiply this fraction by 100 for a percentage. The model uses geometric vectors, with separate evidence; it does not model light-time or eclipse shading. A cycle fraction of 0.5 is the full-moon angular configuration, not a claim of 50% illumination.

moonAge.elapsedDays counts 86400-second days from previousNewMoon to the requested instant. It comes from a bounded event search, rather than multiplying cycleFraction by an assumed month length. The defaults allow 96 evaluations over a 35-day backward window with one-second numerical convergence. Host configuration can change these limits; request JSON cannot. Coverage or search exhaustion can make this extra unavailable. Convergence is not a physical-accuracy guarantee.

For topocentric and heliocentric Moon positions, both lunar phase and lunar age still use a geocentric reference, reported as reference: "geocentric". Do not derive them from the primary position’s longitude unless its reference and conventions match.

6. Handle issues while retaining useful positions

Check HTTP status first. On HTTP 200, inspect each body’s issues as well as the fields you requested. A successful extra is present under its include name. An inapplicable or unavailable extra is absent, with an issue attached to that body.

To try a predictable applicability issue, send the same instant with "bodies": [{ "body": "sun", "include": ["illumination"] }]. If its core position succeeds, the Sun’s issues field is:

[
  {
    "quantity": "illumination",
    "code": "INAPPLICABLE",
    "reason": "Quantity does not apply to this body and observer."
  }
]
Outcome Client behavior
Extra present Display it with its documented units and reference
INAPPLICABLE Keep the position; explain that the extra does not apply to this body/observer
UNAVAILABLE Keep the position; retain the stable source error code in reason for diagnostics
Extra absent and not requested Treat it as unrequested, not zero
Non-200 response Handle the request error; do not assume a partial position response exists

Core acquisition failures reject the entire request. Unexpected internal errors also propagate; they are not converted into optional issues. Calculation errors use { "error": { "code": "…", "message": "…" } }; customer-gateway admission errors can use the separate shape described in the HTTP error reference. Invalid includes return 400 INVALID_REQUEST; the message identifies the entry, such as bodies[1].include, and lists supported names. Unsupported bodies and out-of-range calculations map to 422. A missing route returns 404. Check the key and the enabled host before retrying.

The position feature does not save charts or create database records. Supporting reads and their failures are reused within one request; that is not a persistent result cache or automatic provider fallback. Customer-gateway usage tracking remains a separate effect of making API calls.

Keep the scientific context with the result

Retain evidence.position for the mandatory positions, evidence.supporting for additional position contexts, evidence.definitionsVersion for the bundled conventions, and each illumination result’s own evidence. Use them to identify provider/data versions, frames, origins and corrections when comparing or exporting measurements.

For a display, a useful minimum is the requested UTC instant, observer, coordinates with units, successful extras and a visible explanation for each issue. Never substitute zero for an absent quantity.

Scientific definitions

Angular diameter uses 2 asin(radius / distance) with bundled mean radii and returns arcseconds. The illumination triangle uses Sun, target and observer vectors at the same TT instant; it does not reconstruct illumination from apparent longitude differences. These definitions are versioned with the service rather than selected through astrology profiles or rulebooks.

Model references: JPL quantity conventions, USNO lunar phases, and Swiss geometric coordinate flags.

  • Astronomy: domain scope and the relationship to provider acquisition and astrology.
  • Maintainer guide: enablement, ownership, request assembly, provider limits and source references.
  • HTTP API reference: shared authentication and gateway errors.