合作方接口 POST /v1/profile
接口版本 v1 · 本页更新于 2026-11-14
开放状态:这是按合作逐个开通的合作方接口,目前不提供自助申请或自助开通 API key。开放进度以站点实际开关为准:接口未对外开放时,除 OPTIONS 外的请求一律回 404。OPTIONS 请求由全站跨域处理直接回 204(无正文),这不表示接口已开放。合作意向请发邮件到 support@guan.life。
这个接口做什么
传入一个人的出生日期、时间、性别、时区(可选经度),返回八字命盘的结构化字段:四柱与十神、地支藏干、五行占比、日主强弱档位、格局、喜忌、大运,以及每个喜用五行对应的属性、行业和方位词条。
- 只返回结构化字段,不返回句子。没有性格原话,没有修养建议,也没有说明文字。性格描述和建议由调用方根据字段自己组织。
- 不返回颜色。
likes[]里没有colors字段(颜色词尚未经核定,2026-11-13 起已从对外字段中移除)。 - 全部在服务端按排盘引擎计算,不调用语言模型,也不读取观命用户的任何数据。
请求
POST $API_BASE/v1/profile
Authorization: Bearer $API_KEY
Idempotency-Key: $IDEMPOTENCY_KEY
Content-Type: application/json
{"calendar":"solar","date":"1985-11-03","time":"08:30","gender":"female","timeZone":"Asia/Shanghai","longitude":121.47}
$API_BASE、$API_KEY 都是占位符,开通时单独提供;$IDEMPOTENCY_KEY 由调用方自己生成(见下文「幂等」)。
| 字段 | 规则 |
|---|---|
calendar | 只收 "solar"(公历)。v1 不收农历。 |
date | YYYY-MM-DD,1900–2100 之间的真实日期。1990-02-30 这类不存在的日期回 400,不会顺延到下个月。 |
time | "HH:MM" 或 null。必须显式给出,缺这个键回 400。不知道出生时间就传 null,不要填 12:00。 |
gender | male 或 female。 |
timeZone | 必填,IANA 时区名,例如 Asia/Shanghai、Australia/Sydney。+08:00 这类纯偏移拒收,因为它不带夏令时历史。 |
longitude | 可选,-180 到 180。建议给。给了就按真太阳时排盘:先用 timeZone 把钟表时间换成绝对时刻,再加上经度差和均时差,不需要判断夏令时。不给就按当地钟表时间排,只扣除有名称的夏令时;遇到历史上无名的时区段(如东京 1948–1951)不扣,若看起来像夏令时会把 flags.dstUncertain 置为 true。两种方式都受下面「夏令时切换当天」的限制。 |
夏令时切换当天的限制:
- 夏令时结束、时钟回拨的那一小时里,同一个钟表时间对应两个真实时刻。例如
Australia/Sydney的2026-04-05 02:30,先后出现两次,相隔一小时。请求里没有字段能指明是哪一次,给经度也无法消除这个歧义。服务端固定取其中一次,取前一次还是后一次随时区而定(悉尼取后一次,纽约取前一次)。两种取法的排盘时刻相差一小时,可能落在不同时辰。这类出生时间请先向本人核实,再决定怎么用结果。 - 夏令时开始、时钟拨快跳过的那一小时里的钟表时间实际不存在(例如
Australia/Sydney的2026-10-04 02:30)。服务端不报错,会换算到跳变前或跳变后的某个时刻,同样随时区而定。
鉴权
- 请求头
Authorization: Bearer $API_KEY。方案名Bearer不分大小写,key 本身区分大小写。 - 无 key、key 错误、key 已吊销或过期,以及鉴权时合作方账户已停用,都回同一个
401 UNAUTHORIZED,响应头带WWW-Authenticate: Bearer,不区分具体原因。 - 例外:账户在本次请求通过鉴权之后、扣次之前才被停用,这次请求不回 401,而是回
402 QUOTA_EXCEEDED,即使尚有余额也一样(见「计费与额度」)。扣次时还会按顺序再查 key 和幂等记录:key 在这期间也被吊销或过期,仍回 401;带的Idempotency-Key此前已成功扣次,同一请求回 200 重放、不扣次,换了请求体回 409(见「计费与额度」的检查顺序)。之后的请求在鉴权时就会回 401。 - 这是服务端对服务端的接口。key 不要放进浏览器或 App 前端;浏览器跨域预检不允许
Idempotency-Key头,前端直接调用会被挡住。
幂等(Idempotency-Key)
- 强烈建议每个请求带一个调用方生成的唯一串(例如 UUID),重试时带同一个。格式:1–255 个可见 ASCII 字符(
!到~,不含空格),格式不对回400 INVALID_IDEMPOTENCY_KEY。 - 同一个 key + 同一个
Idempotency-Key+ 同一请求(字段相同即可,JSON 键顺序和空白不影响):回 200,结果与第一次相同,不再扣次,响应头带Idempotent-Replayed: true。服务端不保存生日,重放时按同一输入重新计算;唯一可能不同的是dayun.next:如果重放时已过交运日,会按当天取下一步。 - 同一个
Idempotency-Key用于不同请求:回409 IDEMPOTENCY_CONFLICT,不扣次。 - 只有已扣次的 200 会占用一个幂等键。402、429 和其他 4xx 不占用,补了额度或稍后可以继续用同一个键重试。
- 不带
Idempotency-Key:每次调用都按新请求计费,网络超时后重试会再扣一次。
计费与额度
- 预付额度制。每个成功的
200扣 1 次额度;其余状态码都不扣(503 COUNT_UNAVAILABLE的特殊情况见下)。 - 新开通的合作方账户默认有 200 次试用额度。
- 正式单价尚未确定。本页不报价,接口目前也不提供在线购买或在线充值;补充额度需联系我们办理。
- 200 响应头
X-Quota-Remaining给出扣完后的剩余次数(重放时为当前剩余)。额度不放进 JSON 正文。 402 QUOTA_EXCEEDED有两种情况,都不扣次,响应头都带X-Quota-Remaining:- 额度用完:
X-Quota-Remaining为0。重试这次请求、或换新的Idempotency-Key发新请求都没用,要先补额度。此前已成功扣次的请求用原来的Idempotency-Key重放,额度为 0 也照常回 200、不扣次。 - 账户在本次请求通过鉴权之后、扣次之前被停用:即使尚有余额也回 402,
X-Quota-Remaining显示实际余额,可能大于 0。重试没用,请联系我们确认账户状态。
- 额度用完:
- 扣次时按这个顺序检查,哪一步有结果就在哪一步返回:
- key 是否有效:此时已吊销或过期,回
401 UNAUTHORIZED。 - 幂等记录:带的
Idempotency-Key此前已成功扣次,同一请求回 200 重放、不扣次,换了请求体回409 IDEMPOTENCY_CONFLICT。额度为 0 或账户已停用都不影响这一步。 - 账户是否仍在启用、余额是否够:任一不满足回
402 QUOTA_EXCEEDED;都满足才扣 1 次。
- key 是否有效:此时已吊销或过期,回
- 扣次和结果在同一个数据库事务里完成:没有「给了结果却没记账」的 200。记账失败时回
503 COUNT_UNAVAILABLE、不给结果。 - 收到
503 COUNT_UNAVAILABLE不代表一定没扣次。服务端分不清「已回滚」和「已提交但结果在返回途中断线」。请用同一个Idempotency-Key重试:若上次其实已提交,会走重放(200 +Idempotent-Replayed: true),不会再扣;若上次已回滚,重试正常扣 1 次。不带幂等键的请求遇到这种 503 无法确认,重试可能多扣一次。 - 用量记录只存次数、状态码和一个带密钥的命盘指纹,不存出生日期、请求体或 IP 地址。
返回
200,Cache-Control: no-store。下例是上面那个请求的结果(计算日为 2026-11-10),大运和行业词条截短,… 处为省略:
{
"v": "1",
"chartId": "0123456789abcdef",
"flags": {"hourKnown": true, "dstUncertain": false},
"birth": {
"calendar": "solar",
"date": "1985-11-03",
"time": "08:30",
"timeZone": "Asia/Shanghai",
"longitude": 121.47,
"chartTime": {"date": "1985-11-03", "time": "08:52"},
"trueSolarTime": {
"date": "1985-11-03",
"time": "08:52",
"longitudeOffsetMin": 5.88,
"eotMin": 16.46,
"totalShiftMin": 22.34
},
"lunar": {"label": "一九八五年九月廿一"}
},
"bazi": {
"year": {"ganzhi": "乙丑", "gan": "乙", "zhi": "丑", "ganShishen": "正印",
"hidden": [{"gan": "己", "shishen": "伤官"}, {"gan": "癸", "shishen": "正官"}, {"gan": "辛", "shishen": "正财"}]},
"month": {"ganzhi": "丙戌", "gan": "丙", "zhi": "戌", "ganShishen": "比肩",
"hidden": [{"gan": "戊", "shishen": "食神"}, {"gan": "辛", "shishen": "正财"}, {"gan": "丁", "shishen": "劫财"}]},
"day": {"ganzhi": "丙午", "gan": "丙", "zhi": "午", "ganShishen": "日主",
"hidden": [{"gan": "丁", "shishen": "劫财"}, {"gan": "己", "shishen": "伤官"}]},
"hour": {"ganzhi": "壬辰", "gan": "壬", "zhi": "辰", "ganShishen": "七杀",
"hidden": [{"gan": "戊", "shishen": "食神"}, {"gan": "乙", "shishen": "正印"}, {"gan": "癸", "shishen": "正官"}]}
},
"dayMaster": {"gan": "丙", "element": "火"},
"wuxing": {"木": 9, "火": 22, "土": 45, "金": 14, "水": 10},
"strength": "身弱",
"pattern": "杂气食神格",
"xiyong": {"favor": ["火", "木"], "avoid": ["金", "水"], "settled": true},
"dayun": {
"steps": [
{"age": 3, "year": 1987, "date": "1987-04-28", "ganzhi": "丁亥"},
{"age": 13, "year": 1997, "date": "1997-04-28", "ganzhi": "戊子"},
…
],
"next": {"age": 43, "year": 2027, "date": "2027-04-28", "ganzhi": "辛卯"}
},
"likes": [
{
"element": "火",
"attributes": ["高热", "光亮", "传播性"],
"industries": ["电力照明", "电器", "光学眼镜", …],
"direction": {"north": "南", "south": "北"}
},
{
"element": "木",
"attributes": ["文教", "新生", "植物性"],
"industries": ["木材家具", "室内装潢", "教育学校", …],
"direction": {"north": "东", "south": "东"}
}
]
}
示例里的 chartId 是占位值。
| 字段 | 类型 | 说明 |
|---|---|---|
v | "1" | 接口版本。 |
chartId | string | 16 位十六进制命盘指纹,由服务端带密钥计算,不能反推出生日。时辰未知的盘与任何具体时辰的盘指纹都不同。 |
flags.hourKnown | boolean | 请求里 time 是否给了。 |
flags.dstUncertain | boolean | 没给经度、出生时刻落在无名时区段且看起来像夏令时:未扣除,时辰处在临界时请补经度再算。时辰未知时恒为 false。 |
birth.calendar / date / time / timeZone | 原样回传请求;time 未知为 null。 | |
birth.longitude | number | null | 没给为 null。 |
birth.chartTime | {date, time} | null | 排盘实际使用的时刻。给了经度 = 真太阳时;没给 = 当地钟表时间去掉夏令时。时辰未知为 null。 |
birth.trueSolarTime | object | null | 真太阳时换算明细:date、time、longitudeOffsetMin、eotMin、totalShiftMin(单位分钟,取到 0.01)。只在给了经度且时辰已知时返回。 |
birth.lunar.label | string | 农历日期标签,如「一九八五年九月廿一」。 |
bazi.year / month / day / hour | object | ganzhi、gan、zhi、ganShishen(天干十神;日柱恒为 日主)、hidden(地支藏干,本气在前,每个带 shishen)。时辰未知时 hour 为 null。 |
dayMaster | {gan, element} | 日主天干与五行。 |
wuxing | object | null | 五行占比,木 火 土 金 水 各一个 0–100 的整数,四舍五入后合计约 100。时辰未知为 null。 |
strength | string | null | 强弱档位:身强 / 中和偏强 / 中和偏弱 / 身弱 / 极弱 / 从格 / 化气。时辰未知为 null。 |
pattern | string | null | 子平主格名。判不出或时辰未知为 null。 |
xiyong | {favor, avoid, settled} | null | 喜用五行与忌五行,与观命页面一致。settled = false 表示边界盘:喜忌随大运流年变化,只作倾向。时辰未知为 null。 |
dayun | {steps, next} | null | 大运:每步 age(交运虚岁)、year、date(交运日,排不出为 null)、ganzhi。next 为今天及以后最近的一步,超出序列为 null。时辰未知为 null(起运岁依赖出生时刻)。 |
likes[] | array | 每个喜用五行一条,顺序同 xiyong.favor:element、attributes、industries(取自行业五行表)、direction.north / direction.south(北半球木东、火南、土中、金西、水北;南半球火、水对调)。边界盘照样返回,请按 settled 降低语气。时辰未知为 []。不含颜色。 |
不返回:性格句、修养建议、说明句、颜色、强弱推算日志、完整命盘。
错误
除 500 外,错误正文统一为 {"error": {"code": "…", "message": "…"}},带 Cache-Control: no-store。500 是未预料的异常,正文为纯文本 Internal Server Error。
| 状态 | code | 什么时候 | 扣次 |
|---|---|---|---|
| 204 | (无正文) | 不是错误:OPTIONS 请求不论接口是否开放,都由全站跨域处理直接回 204,不鉴权 | 否 |
| 404 | NOT_FOUND | 接口未开放(除 OPTIONS 外的任何方法) | 否 |
| 405 | METHOD_NOT_ALLOWED | 接口已开放,方法既不是 POST 也不是 OPTIONS | 否 |
| 401 | UNAUTHORIZED | 无 key、key 错误、key 已吊销或过期;鉴权时账户已停用 | 否 |
| 429 | RATE_LIMITED | 超过每分钟限额(按合作方设定,默认每分钟 60 次);带 Retry-After: 60,等待后重试即可 | 否 |
| 400 | INVALID_IDEMPOTENCY_KEY | Idempotency-Key 格式不对 | 否 |
| 400 | INVALID_JSON、INVALID_BODY、INVALID_CALENDAR、INVALID_DATE、INVALID_TIME、INVALID_GENDER、INVALID_TIMEZONE、INVALID_LONGITUDE、UNCOMPUTABLE | 请求体或字段不合规,或输入无法排盘 | 否 |
| 402 | QUOTA_EXCEEDED | 额度用完(X-Quota-Remaining: 0);或账户在鉴权之后、扣次之前被停用,此时即使尚有余额也回 402(X-Quota-Remaining 为实际余额)。两种情况下,带此前已成功扣次的 Idempotency-Key 都先走重放或 409 | 否 |
| 409 | IDEMPOTENCY_CONFLICT | 同一 Idempotency-Key 已用于不同请求 | 否 |
| 503 | MISCONFIGURED | 服务端配置异常(在鉴权之前检查,不带 key 也是 503) | 否 |
| 503 | AUTH_UNAVAILABLE | 暂时无法校验 key;带 Retry-After: 5 | 否 |
| 503 | COUNT_UNAVAILABLE | 结果算出来了,但扣次或记账失败;带 Retry-After: 5,不给结果 | 通常否;见上文「计费与额度」,用同一 Idempotency-Key 重试确认 |
429 和 402 的区别:429 是这一分钟请求太快,等 Retry-After 秒后重试即可。402 靠重试解决不了:X-Quota-Remaining 为 0 是预付额度用完,需要先补额度;大于 0 是账户在鉴权之后被停用,需要联系我们。
调用示例
curl -sS -X POST "$API_BASE/v1/profile" \
-H "Authorization: Bearer $API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"calendar":"solar","date":"1985-11-03","time":"08:30","gender":"female","timeZone":"Asia/Shanghai","longitude":121.47}'
重试同一个请求时,请复用第一次生成的那个 Idempotency-Key,不要每次重新生成。
English summary
POST /v1/profileis a partner API, enabled per partner. API keys are not available for self-service sign-up. Availability follows the live switch on our side; while the endpoint is not open, every request exceptOPTIONSreturns404.OPTIONSalways gets204(no body) from the site-wide CORS handler, which does not mean the endpoint is open. Once open, methods other thanPOSTandOPTIONSreturn405. Contact support@guan.life.- Input: solar birth date, explicit time (
"HH:MM"ornull), gender, IANA time zone, optional longitude (recommended). With longitude, the chart uses true solar time: the clock time is converted to an absolute instant via the IANA zone, then the longitude offset and the equation of time are added. Without longitude, it uses local clock time with only named daylight-saving time removed. - Limitation on DST transition days: in the repeated hour when DST ends, one clock time maps to two real instants (e.g.
Australia/Sydney2026-04-05 02:30). No request field can say which one, and longitude does not resolve it; the server always picks one of them, and which one depends on the zone. Clock times skipped when DST starts do not exist; the server does not reject them and maps them to one side of the jump. - Output: structured BaZi fields only — four pillars with Ten Gods and hidden stems, five-element percentages, strength class, pattern, favourable / unfavourable elements, luck pillars, and per-element attribute / industry / direction terms. No personality sentences, no advice text, and no
likes[].colors. - Auth:
Authorization: Bearer $API_KEY(scheme name case-insensitive). Server-to-server only; do not ship the key to a browser. A missing, wrong, revoked or expired key, or an account already suspended at authentication, returns401 UNAUTHORIZED. - Idempotency: send an
Idempotency-Keyand reuse it on retries. Same key and same request replays the result without charging again (Idempotent-Replayed: true); same key with a different request returns409. - Billing: prepaid quota. Each successful
200uses one call; new partner accounts get a default trial quota of 200 calls.402 QUOTA_EXCEEDEDwhen the quota runs out (X-Quota-Remaining: 0), and also when the account is suspended after authentication but before the call is charged; in that case it is 402 even with quota remaining, andX-Quota-Remainingshows the real balance. At charge time the checks run in order: the key first (revoked or expired by then: 401), then the idempotency record (a request already charged under the sameIdempotency-Keyreplays as 200 without a charge, even with zero quota or a suspended account; a different request with that key gets 409), and only then account status and balance (402). Retrying a request that got 402, or sending it under a newIdempotency-Key, does not help: add quota first, or contact us about the account status. Formal per-call pricing has not been set yet; there is no online purchase or top-up. - Other errors:
429 RATE_LIMITEDmeans the per-minute limit was hit (set per partner, default 60 per minute); waitRetry-After: 60seconds and retry, not charged.503 COUNT_UNAVAILABLEmeans the result was computed but charging or recording failed, so no result is returned; the call may still have been charged, so retry with the sameIdempotency-Keyto confirm (a committed call replays without a second charge; a rolled-back call is charged once).