5-Element Balance
curl -X POST https://api.astroway.info/v1/bazi/element-balance \ -H "X-Api-Key: aw_live_..." \ -H "Content-Type: application/json" \ -d '{ "date": "1990-05-15", "time": "14:30:00", "timezoneOffset": 8 }'const res = await fetch('https://api.astroway.info/v1/bazi/element-balance', { method: 'POST', headers: { 'X-Api-Key': process.env.ASTROWAY_API_KEY, 'Content-Type': 'application/json', }, body: JSON.stringify({ "date": "1990-05-15", "time": "14:30:00", "timezoneOffset": 8 }),});const { ok, data, error } = await res.json();if (!ok) throw new Error(error.message);console.log(data);import os, requests
r = requests.post( 'https://api.astroway.info/v1/bazi/element-balance', headers={'X-Api-Key': os.environ['ASTROWAY_API_KEY'], 'Content-Type': 'application/json'}, json={ 'date': "1990-05-15", 'time': "14:30:00", 'timezoneOffset': 8 },)result = r.json()if not result['ok']: raise RuntimeError(result['error']['message'])print(result['data'])<?phpuse GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://api.astroway.info/v1/']);$r = $client->post('bazi/element-balance', [ 'headers' => ['X-Api-Key' => getenv('ASTROWAY_API_KEY')], 'json' => [ 'date' => '1990-05-15', 'time' => '14:30:00', 'timezoneOffset' => 8, ],]);$result = json_decode($r->getBody(), true);if (!$result['ok']) throw new \RuntimeException($result['error']['message']);print_r($result['data']);Element balance across the whole chart. The balance object opens the branches and counts all eight characters three ways: visible, with every hidden stem, and weighted so the total stays at eight. The top-level elementCounts, dominantElement and missingElements are DEPRECATED (year and month only, four characters, branches unopened) and keep answering unchanged until 2027-09-08; the response carries RFC 8594 Deprecation and Sunset headers.
Authorizations
Section titled “Authorizations ”Parameters
Section titled “ Parameters ”Query Parameters
Section titled “Query Parameters ”Comma-separated dotted paths, relative to data, to keep in the response. A path is applied to every element of an array, so planets.name means the name of each planet. Paths that match nothing come back in _fields_unmatched; a list where nothing matches at all is a 400, because an empty object would be a confident wrong answer.
Example
planets.name,planets.longitudeRound every non-integer number in the response to this many decimal places. Integers are left alone, because an id is not a measurement. Ecliptic longitudes ship with fourteen decimals by default; 2 is about a tenth of an arcminute.
Example
4Request Body required
Section titled “Request Body required ”object
Ignored when timezone is sent.
IANA zone name such as Europe/Kyiv, or auto to look the zone up from latitude and longitude. The server takes the offset that zone kept at this local date and time, summer time included, and uses it in place of timezoneOffset. A clock time that happened twice takes the first occurrence; one skipped when clocks went forward takes the offset from before the change. Abbreviations such as EST are refused. Before 1970 the tz database is not reliable for every place, so send timezoneOffset when the local clock is known.
Example
{ "date": "1990-05-15", "time": "14:30:00", "timezoneOffset": 8}Responses
Section titled “ Responses ”Successful calculation
object
object
object
object
object
object
object
object
object
object
object
Example
{ "ok": true, "data": { "solarYear": 1990, "pillars": [ { "name": "year", "stem": "Geng", "branch": "Wu", "pillar": "Geng-Wu" }, { "name": "month", "stem": "Xin", "branch": "Si", "pillar": "Xin-Si" }, { "name": "day", "stem": "Geng", "branch": "Chen", "pillar": "Geng-Chen" }, { "name": "hour", "stem": "Gui", "branch": "Wei", "pillar": "Gui-Wei" } ], "elementCounts": { "Wood": 0, "Fire": 2, "Earth": 0, "Metal": 2, "Water": 0 }, "dominantElement": "Fire", "missingElements": [ "Wood", "Earth", "Water" ], "balance": { "scope": "eight characters", "visible": { "Wood": 0, "Fire": 2, "Earth": 2, "Metal": 3, "Water": 1 }, "withHiddenStems": { "Wood": 2, "Fire": 3, "Earth": 4, "Metal": 4, "Water": 2 }, "weighted": { "Wood": 0.4, "Fire": 1.6, "Earth": 1.6, "Metal": 3.3, "Water": 1.1 }, "weighting": "Each branch contributes one character split among the stems it shelters: 1.0 alone, 0.7/0.3 for two, 0.6/0.3/0.1 for three (本气/中气/余气). The membership is canonical; the split is a stated convention, and the day-count 人元司令 scheme distributes the same characters differently.", "dominantElement": "Metal", "dominantElementName": "Метал", "missingElements": [], "missingElementNames": [], "hiddenStems": [ { "pillar": "year", "branch": "Wu", "stems": [ { "stem": "Ding", "stemIndex": 3, "element": "Fire", "yin": true, "role": "principal", "weight": 0.7 }, { "stem": "Ji", "stemIndex": 5, "element": "Earth", "yin": true, "role": "middle", "weight": 0.3 } ] }, { "pillar": "month", "branch": "Si", "stems": [ { "stem": "Bing", "stemIndex": 2, "element": "Fire", "yin": false, "role": "principal", "weight": 0.6 }, { "stem": "Geng", "stemIndex": 6, "element": "Metal", "yin": false, "role": "middle", "weight": 0.3 }, { "stem": "Wu", "stemIndex": 4, "element": "Earth", "yin": false, "role": "residual", "weight": 0.1 } ] }, { "pillar": "day", "branch": "Chen", "stems": [ { "stem": "Wu", "stemIndex": 4, "element": "Earth", "yin": false, "role": "principal", "weight": 0.6 }, { "stem": "Yi", "stemIndex": 1, "element": "Wood", "yin": true, "role": "residual", "weight": 0.3 }, { "stem": "Gui", "stemIndex": 9, "element": "Water", "yin": true, "role": "middle", "weight": 0.1 } ] }, { "pillar": "hour", "branch": "Wei", "stems": [ { "stem": "Ji", "stemIndex": 5, "element": "Earth", "yin": true, "role": "principal", "weight": 0.6 }, { "stem": "Ding", "stemIndex": 3, "element": "Fire", "yin": true, "role": "residual", "weight": 0.3 }, { "stem": "Yi", "stemIndex": 1, "element": "Wood", "yin": true, "role": "middle", "weight": 0.1 } ] } ] }, "deprecations": [ { "fields": [ "elementCounts", "dominantElement", "missingElements" ], "since": "2026-09-08", "sunset": "2027-09-08", "successor": "balance", "reason": "They count the year and month pillars only, four of the eight characters, and never open the branches, so an element sheltered as a hidden stem is reported absent. `balance` counts the whole chart. The old fields keep answering unchanged until the sunset date." } ], "notes": [], "methodology": "Under `balance`: all eight characters with the branches opened. `visible` counts the four stems plus each branch's principal hidden stem, the classic count of eight. `withHiddenStems` counts every sheltered stem whole. `weighted` splits each branch among the stems it shelters, so the total stays at eight. An element is called missing only when the weighted count reaches zero.", "source": "地支藏干 per 淵海子平 and 三命通會, public domain", "disclaimer": "BaZi pillars use the canonical 60-jiazi cycle, anchored at 1990-01-01 = Bing-Yin. Year and month boundaries are the exact Lichun and 節 instants from the ephemeris, stated in China Standard Time; pass time and timezoneOffset for births near a boundary. Day and hour follow the birthplace clock, with the day rolling at 23:00 local." }}Validation error
Example
{ "ok": false, "error": { "code": "INVALID_INPUT", "message": "Validation failed: date: Date must be YYYY-MM-DD", "details": [ { "path": "date", "message": "Date must be YYYY-MM-DD" } ] }}Missing or invalid API key
Example
{ "ok": false, "error": { "code": "INVALID_API_KEY", "message": "Invalid API key" }}