抽取世界观并复用
世界观任务通读整个源文件,生成一份译者说明:题材、时代背景、语域、叙述者身份、关键译名与术语指引。按全文字数 0.1 积分/字计费。之后把结果注入翻译任务(后续分卷、重译),即可保持译名和文风一致,且无需再次付费抽取。
1. 创建世界观任务
`target_language` 决定说明中译名参考面向的目标语言。返回 202、状态 `queued`;积分此时预扣,成功后结算。
curl -X POST "https://xsfyj.com/api/b2b/v1/jobs" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"type": "worldview",
"source_id": "src_0mvri8g568XfrxRhqf6Az4C",
"source_language": "zh",
"target_language": "en",
"quote_id": "quo_0mvri9ezlgx1T4CTCRglnh1"
}'
{
"id": "job_0mvriardeM8hGujFyWfbGY0",
"object": "job",
"type": "worldview",
"status": "queued",
"source_id": "src_0mvri8g568XfrxRhqf6Az4C",
"series_id": null,
"target_language": "en",
"source_language": "zh-CN",
"options": { "output_format": "translation_only", "translate_filename": false },
"glossary": null,
"credits": 33,
"billing_state": "held",
"progress": { "stage": null, "percent": 0, "waiting_reason": null },
"result": null,
"error": null,
"poll_after_seconds": 5,
"created_at": "2026-10-28T02:39:44Z",
"completed_at": null
}
2. 轮询任务状态
状态依次为 queued → running → succeeded(或 failed / cancelled)。两次轮询之间等待 `poll_after_seconds` 秒,终态时为 null。`progress.stage` 是稳定的机器值,`progress.percent` 为 0–100。运行中的任务如下:
curl "https://xsfyj.com/api/b2b/v1/jobs/job_0mvriardeM8hGujFyWfbGY0" \
-H "Authorization: Bearer $KEY"
{
"id": "job_0mvriardeM8hGujFyWfbGY0",
"object": "job",
"type": "worldview",
"status": "running",
"credits": 33,
"billing_state": "held",
"progress": { "stage": "LANGUAGE_DETECT", "percent": 22, "waiting_reason": null },
"result": null,
"error": null,
"poll_after_seconds": 10,
"…": "…"
}
// succeeded
{
"id": "job_0mvriardeM8hGujFyWfbGY0",
"object": "job",
"type": "worldview",
"status": "succeeded",
"credits": 33,
"billing_state": "consumed",
"progress": { "stage": "COMPLETE", "percent": 100, "waiting_reason": null },
"result": { "worldview": "Source Title: 雾港\nKnown Target Title: Fog Port (uncertain; Low)\n…" },
"error": null,
"poll_after_seconds": null,
"created_at": "2026-10-28T02:39:44Z",
"completed_at": "2026-10-28T02:39:57Z"
}
3. 获取世界观结果
说明为纯文本,可自行保存、交给编辑审阅或修改后再复用。需要译名作为输出文件名时,在翻译任务里设置 `options.translate_filename: true`。
curl "https://xsfyj.com/api/b2b/v1/jobs/job_0mvriardeM8hGujFyWfbGY0/worldview" \
-H "Authorization: Bearer $KEY"
{
"job_id": "job_0mvriardeM8hGujFyWfbGY0",
"object": "worldview_result",
"worldview": "Source Title: 雾港\nKnown Target Title: Fog Port (uncertain; Low)\nNarrative Identity:\n- Default narrator: identity: impersonal, scope: whole_book\n…\nGenre: Fantasy / Adventure / Mystery\nEra/Setting: Ancient China-like\nRegister: period-flavored\nTone: melancholic, atmospheric, journey-focused\n…\nTranslation References:\n- 雾港 -> Fog Port (work_title; Medium; common web usage)\n Alternatives: Mist Port, Mist Harbor\n- 北境 -> the North (core_concept; High; common web usage)\n…\nRisk Notes: The text is very short; …"
}
4. 在翻译任务中复用
把文本(≤ 20,000 字符)放入 `options.worldview`。任务会以你提供的说明作为翻译上下文;价格仍为所选范围字数 × 1 积分,本例 328 字的 0–50% = 164 积分。
WORLDVIEW=$(curl -s "https://xsfyj.com/api/b2b/v1/jobs/job_0mvriardeM8hGujFyWfbGY0/worldview" \
-H "Authorization: Bearer $KEY" | jq -r .worldview)
curl -X POST "https://xsfyj.com/api/b2b/v1/jobs" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg wv "$WORLDVIEW" '{
type: "translation",
source_id: "src_0mvri8g568XfrxRhqf6Az4C",
source_language: "zh",
target_language: "en",
options: { scope: { start_percent: 0, end_percent: 50 }, worldview: $wv }
}')"
{
"id": "job_0mvribx53EiHALikS1yvzb8",
"object": "job",
"type": "translation",
"status": "queued",
"source_id": "src_0mvri8g568XfrxRhqf6Az4C",
"target_language": "en",
"source_language": "zh-CN",
"options": {
"scope": { "end_percent": 50, "start_percent": 0 },
"worldview": { "injected": true, "characters": 1834 },
"output_format": "translation_only",
"translate_filename": false
},
"glossary": null,
"credits": 164,
"billing_state": "held",
"poll_after_seconds": 5,
"…": "…"
}
// succeeded → result.files
"result": {
"files": [
{ "kind": "translated", "file_id": "NVMVRIBXC64Y_output_cfd974b74bfb4448",
"filename": "novel.range-0-50_translated.epub", "size_bytes": 3028 }
]
}
- 每本书(或每个系列)抽取一次即可反复复用:世界观 0.1 积分/字,30 万字的小说约 30,000 积分。
- 注入前可任意修改说明——在 “Translation References” 中改一个译名,之后的任务都会遵循。需要强制锁定术语时配合术语表使用。
- 任务响应只回显注入世界观的长度({ injected, characters }),不会回显正文。
- 系列(/series)会在各卷之间自动保存并注入世界观;单次任务用 options.worldview 即可。
版本化的术语表资源
术语表资源(`gls_…`)保存你确认过的术语。每次修改都生成一个不可变的新版本,翻译任务记录所用的确切版本,重跑结果可复现。可以从术语任务、CSV 文件或内联 `terms` 创建。
1. 从术语任务结果创建术语表
从任务复制的词条标为 `authority: locked`(用户确认)。每个版本的 `origin` 记录其来源。
curl -X POST "https://xsfyj.com/api/b2b/v1/glossaries" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"name": "Qingyun Saga", "from_job_id": "job_0mvri97fqVgsuxDwMqNrsCz"}'
{
"id": "gls_0mvriazvx5MpABdP6aMqf95",
"object": "glossary",
"name": "Qingyun Saga",
"version": 1,
"current_version": 1,
"term_count": 15,
"terms": [
{ "source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": null, "note": "Protagonist of the story…", "count": 4, "authority": "locked" },
"…"
],
"origin": { "kind": "job", "job_id": "job_0mvri97fqVgsuxDwMqNrsCz" },
"created_at": "2026-10-28T02:39:55Z",
"version_created_at": "2026-10-28T02:39:55Z"
}
2. 用乐观锁修改词条
`upsert` 按 `source` 整条替换(不存在则新增);`remove` 按 `source` 删除。`If-Match` 带上你所基于的版本号;新版本号在响应体和 `ETag` 中返回。
curl -X PATCH "https://xsfyj.com/api/b2b/v1/glossaries/gls_0mvriazvx5MpABdP6aMqf95" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H 'If-Match: "1"' \
-H "Content-Type: application/json" \
-d '{
"upsert": [
{"source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": "male", "note": "Protagonist"},
{"source": "青云宗", "target": "Azure Cloud Sect", "category": "proper_noun"}
],
"remove": ["第一章 青云入门", "长老"]
}'
HTTP/1.1 200 OK
ETag: "2"
{
"id": "gls_0mvriazvx5MpABdP6aMqf95",
"object": "glossary",
"version": 2,
"current_version": 2,
"term_count": 13,
"terms": [
{ "authority": "locked", "source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": "male", "note": "Protagonist" },
"…"
],
"origin": { "kind": "patch" },
"version_created_at": "2026-10-28T02:40:09Z"
}
3. 版本过期 → 409 VERSION_CONFLICT
若他人已保存了更新的版本,请重新读取(`GET /glossaries/{id}`),在最新版本上重做修改后再提交。
curl -X PATCH "https://xsfyj.com/api/b2b/v1/glossaries/gls_0mvriazvx5MpABdP6aMqf95" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H 'If-Match: "1"' \
-H "Content-Type: application/json" \
-d '{"remove": ["魔道"]}'
{
"type": "https://novotranslator.com/api-docs#error-VERSION_CONFLICT",
"title": "Version conflict",
"status": 409,
"code": "VERSION_CONFLICT",
"detail": "Glossary gls_0mvriazvx5MpABdP6aMqf95 changed; current version is 2.",
"param": null,
"request_id": "req_0mvribltqYesRZapdb2q2Yz",
"meta": { "current_version": 2 }
}
4. 导出 CSV
返回 JSON,CSV 文本在 `csv` 字段(列与网页术语工作台一致)。加 `version=1` 可导出旧版本。用 `jq -r .csv > terms.csv` 存成文件。
curl "https://xsfyj.com/api/b2b/v1/glossaries/gls_0mvriazvx5MpABdP6aMqf95/export?format=csv" \
-H "Authorization: Bearer $KEY" | jq -r .csv > terms.csv
{
"object": "glossary_export",
"format": "csv",
"version": 2,
"csv": "term,translation,category,gender,note,authority\n林逸,Lin Yi,person_name,male,Protagonist,locked\n苏清寒,Su Qinghan,person_name,female,Senior disciple of the sect leader…,locked\n…"
}
5. 导入 CSV 文件
使用 multipart/form-data,字段 `file` 和 `name`。必需列 `term`、`translation`,可选 `category`、`note`。导入的词条均为 `locked`。
# terms.csv
# term,translation,category,note
# 林逸,Lin Yi,person_name,Protagonist
# 苏清寒,Su Qinghan,person_name,"Senior sister, cold tone"
# 青云宗,Azure Cloud Sect,proper_noun,
# 血煞门,Blood Fiend Sect,proper_noun,Demonic sect
# 太玄剑诀,Taixuan Sword Art,work_title,
curl -X POST "https://xsfyj.com/api/b2b/v1/glossaries" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F "[email protected];type=text/csv" \
-F "name=Publisher glossary"
{
"id": "gls_0mvric0k0kq6EjO0gxRkPrD",
"object": "glossary",
"name": "Publisher glossary",
"version": 1,
"current_version": 1,
"term_count": 5,
"terms": [
{ "source": "林逸", "target": "Lin Yi", "category": "person_name", "note": "Protagonist", "authority": "locked" },
{ "source": "苏清寒", "target": "Su Qinghan", "category": "person_name", "note": "Senior sister, cold tone", "authority": "locked" },
{ "source": "青云宗", "target": "Azure Cloud Sect", "category": "proper_noun", "authority": "locked" },
"…"
],
"origin": { "kind": "csv", "filename": "terms.csv" },
"version_created_at": "2026-10-28T02:40:42Z"
}
- 用 `GET /glossaries/{id}?version=1` 读取任意旧版本;`ETag` 头始终是返回的版本号。
- 相同 `source` 的词条会去重,以最后一条为准。每张术语表最多 5,000 条。
- 创建和修改术语表免费,只有使用它的任务才计费。
带选项翻译一个源文件
翻译按所选范围的字数每字 1 积分计费。自定义 `style_guide`(≤ 500 字)另加全文字数的 30%,Plus 会员免收。先报价(免费,30 分钟有效),再用相同参数加 `quote_id` 建任务:服务端会重新计价,价格变化时返回 `QUOTE_EXPIRED_OR_CHANGED`。
1. 报价
只译前半部分(399 字中的 200 字)计 200 积分;指南附加费为 ceil(399 × 0.3) = 120。
curl -X POST "https://xsfyj.com/api/b2b/v1/quotes" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
"target_language": "en",
"options": {
"output_format": "original_above",
"style_guide": "Keep a light, modern tone. Use pinyin for names; do not translate sect names literally unless the glossary says so.",
"scope": {"start_percent": 0, "end_percent": 50},
"translate_filename": true,
"retention_days": 30
},
"jobs": [{"type": "translation"}]
}'
{
"id": "quo_0mvricmlthSrwls5txr5Kro",
"object": "quote",
"source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
"target_language": "en",
"items": [{
"type": "translation", "characters": 200, "credits": 320,
"breakdown": { "base_credits": 200, "style_guide_credits": 120, "style_guide_waived": false,
"scope": { "start": 0, "end_exclusive": 200 } }
}],
"total_credits": 320,
"balance": 199085,
"sufficient": true,
"warnings": [],
"expires_at": "2026-10-28T03:11:11Z",
"created_at": "2026-10-28T02:41:11Z"
}
2. 按报价创建任务
`output_format`:`translation_only`(默认)、`original_above`(双语,原文在上)或 `translation_above`。`translate_filename` 同时翻译产物文件名。`retention_days` 只能缩短产物保留期(默认 90 天,Plus 180 天)。
curl -X POST "https://xsfyj.com/api/b2b/v1/jobs" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"quote_id": "quo_0mvricmlthSrwls5txr5Kro",
"type": "translation",
"source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
"target_language": "en",
"options": { …same options as the quote… }
}'
{
"id": "job_0mvrid2ce1Vv9nvcqbyUkw8",
"object": "job",
"type": "translation",
"status": "queued",
"source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
"target_language": "en",
"options": {
"scope": { "end_percent": 50, "start_percent": 0 },
"style_guide": "Keep a light, modern tone. …",
"output_format": "original_above",
"retention_days": 30,
"translate_filename": true
},
"glossary": null,
"credits": 320,
"billing_state": "held",
"progress": { "stage": null, "percent": 0, "waiting_reason": null },
"result": null,
"error": null,
"poll_after_seconds": 5,
"created_at": "2026-10-28T02:41:31Z"
}
3. 轮询到成功
两次轮询之间等待 `poll_after_seconds` 秒。`status` 依次为 `queued` → `running`(附 `progress.stage` / `percent`)→ `succeeded` | `failed` | `cancelled`。成功后 `billing_state` 变为 `consumed`,`result.files` 列出产物。
curl "https://xsfyj.com/api/b2b/v1/jobs/job_0mvrid2ce1Vv9nvcqbyUkw8" \
-H "Authorization: Bearer $KEY"
{
"id": "job_0mvrid2ce1Vv9nvcqbyUkw8",
"object": "job",
"status": "succeeded",
"credits": 320,
"billing_state": "consumed",
"progress": { "stage": "COMPLETE", "percent": 100, "waiting_reason": null },
"result": {
"files": [{ "kind": "translated", "file_id": "NVMVRID2O4ZS_output_ec08cf5334ea43c9",
"filename": "Chapter 1 Entering Qingyun (chapter-1).range-0-50_bilingual.txt", "size_bytes": 1983 }]
},
"poll_after_seconds": null,
"completed_at": "2026-10-28T02:42:32Z",
"…": "…"
}
- 报价只是核价、不预留积分;建任务时才冻结积分。
- 报价带有 `SOURCE_LANGUAGE_MISMATCH` 警告时,建任务需加 `"confirm_source_language": true`,否则返回 409 `SOURCE_LANGUAGE_CONFIRMATION_REQUIRED`。
- 超过账号并发上限的任务会停在 `queued`,属正常排队,轮到后自动开始。
多卷系列翻译
系列让所有分卷共用一份世界观和一张不断累积的术语表,第 1 卷到第 N 卷的译名和文风保持一致。流程:创建系列 → 添加分卷 → 用锚定卷做 bootstrap(该卷字数 × 世界观 0.1 + 术语 0.5 积分)→ 后续每卷可先增量抽取新术语(该卷字数 × 0.5)并审校 → 翻译该卷(1 积分/字,系列设置了 style_guide 时 +30%)。每个任务都会冻结它使用的术语表版本。
1. 创建系列
`glossary_mode` 决定翻译时如何使用系列术语表:`merge`(默认)允许引擎补充新发现的术语,`strict` 只用你的术语表。`style_guide`(≤ 500 字)与 `output_format` 作用于每一卷的翻译。
curl -X POST "https://xsfyj.com/api/b2b/v1/series" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"name": "Azure Cloud Sect",
"source_language": "zh-CN",
"target_language": "en",
"glossary_mode": "merge",
"style_guide": "Keep Chinese names in pinyin; formal, slightly archaic tone for elders.",
"output_format": "translation_only"
}'
{
"id": "ser_0mvri8igdU1ZBKpByrilHDc",
"object": "series",
"name": "Azure Cloud Sect",
"source_language": "zh-CN",
"target_language": "en",
"settings": {
"style_guide": "Keep Chinese names in pinyin; formal, slightly archaic tone for elders.",
"glossary_mode": "merge",
"output_format": "translation_only",
"auto_accept_new_terms": true
},
"glossary_id": null,
"worldview": null,
"worldview_version": 0,
"created_at": "2026-10-28T02:37:59Z"
}
2. 上传每一卷并加入系列
每一卷先作为源文件上传(文件或 `text`),再按阅读顺序挂到系列下。`position` 省略时取下一个序号。第 2 卷同理(`src_0mvri8wtzFSbMncyV5GZvwu` → `vol_0mvri9b6q2tHTry6X2O5cSb`)。
curl -X POST "https://xsfyj.com/api/b2b/v1/sources?wait=30" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F "[email protected]"
# → { "id": "src_0mvri8q0pk5VSCNlpLs0k55", "status": "ready", "characters": 221, … }
curl -X POST "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc/volumes" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "source_id": "src_0mvri8q0pk5VSCNlpLs0k55", "position": 1, "title": "Volume 1: Azure Cloud Gate" }'
{
"id": "vol_0mvri96244cG34JfpngJjzL",
"object": "series_volume",
"source_id": "src_0mvri8q0pk5VSCNlpLs0k55",
"position": 1,
"title": "Volume 1: Azure Cloud Gate"
}
3. 用锚定卷 bootstrap 系列
对锚定卷(默认第 1 卷,可传 `volume_id` 指定)同时启动世界观任务和术语任务,返回 202 和两个任务。本例第 1 卷 221 字:世界观 ⌈221 × 0.1⌉ = 23,术语 ⌈221 × 0.5⌉ = 111 积分。
curl -X POST "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc/bootstrap" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{}'
{
"object": "list",
"data": [
{
"id": "job_0mvri9glj2W6mt6fqgSikI2",
"object": "job",
"type": "worldview",
"status": "queued",
"source_id": "src_0mvri8q0pk5VSCNlpLs0k55",
"series_id": "ser_0mvri8igdU1ZBKpByrilHDc",
"credits": 23,
"billing_state": "held",
"poll_after_seconds": 5,
…
},
{
"id": "job_0mvri9h45o9tD37yT4cbPPw",
"object": "job",
"type": "glossary",
"status": "queued",
"credits": 111,
"billing_state": "held",
…
}
],
"has_more": false,
"next_cursor": null
}
4. bootstrap 完成后查看系列
两个任务都成功后,系列获得 `worldview`(版本 1)和 `glossary_id`(术语表版本 1,词条均为 `suggested`),并发出 `series.glossary.updated` 事件。`volumes[].jobs` 列出每卷最近的任务。
curl "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc" \
-H "Authorization: Bearer $KEY"
{
"id": "ser_0mvri8igdU1ZBKpByrilHDc",
"object": "series",
"name": "Azure Cloud Sect",
"glossary_id": "gls_0mvriah1kudAgkROSl89vK9",
"worldview": "Source Title: 青云门 / azure-cloud-vol1.txt\nGenre: Fantasy / Cultivation / Xianxia\nRegister: period-flavored\nTranslation References:\n- 筑基 -> Foundation Establishment …",
"worldview_version": 1,
"volumes": [
{
"id": "vol_0mvri96244cG34JfpngJjzL",
"object": "series_volume",
"source_id": "src_0mvri8q0pk5VSCNlpLs0k55",
"position": 1,
"title": "Volume 1: Azure Cloud Gate",
"jobs": [
{ "id": "job_0mvri9h45o9tD37yT4cbPPw", "type": "glossary", "status": "succeeded", "credits": 111, "billing_state": "consumed", … },
{ "id": "job_0mvri9glj2W6mt6fqgSikI2", "type": "worldview", "status": "succeeded", "credits": 23, "billing_state": "consumed", … }
]
},
{ "id": "vol_0mvri9b6q2tHTry6X2O5cSb", "object": "series_volume", "position": 2, "title": "Volume 2: Myriad Demon Valley", "jobs": [] }
],
…
}
5. 审校术语表并锁定确认过的词条
术语表按版本保存。`upsert` 按 `source` 整条替换,`remove` 按 `source` 删除。把读到的版本号放进 `If-Match`;期间被他人改过会返回 409 `VERSION_CONFLICT` 并附 `meta.current_version`。锁定(locked)的词条不会被之后的抽取覆盖。
curl -X PATCH "https://xsfyj.com/api/b2b/v1/glossaries/gls_0mvriah1kudAgkROSl89vK9" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H 'If-Match: "1"' \
-H "Content-Type: application/json" \
-d '{
"upsert": [
{ "source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": "male", "authority": "locked" },
{ "source": "苏晴", "target": "Su Qing", "category": "person_name", "gender": "female", "authority": "locked" },
{ "source": "青云门", "target": "Azure Cloud Sect", "category": "proper_noun", "authority": "locked" },
{ "source": "玄冥玉佩", "target": "Xuanming Jade Pendant", "category": "proper_noun", "authority": "locked" }
],
"remove": ["第一章 青云门"]
}'
ETag: "2"
{
"id": "gls_0mvriah1kudAgkROSl89vK9",
"object": "glossary",
"name": "Azure Cloud Sect glossary",
"version": 2,
"current_version": 2,
"term_count": 10,
"terms": [
{ "source": "青云门", "target": "Azure Cloud Sect", "category": "proper_noun", "gender": null, "authority": "locked" },
{ "source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": "male", "authority": "locked" },
{ "source": "问心阶", "target": "Heart-Questioning Steps", "category": "cultural_concept", "gender": null, "note": "…", "alternatives": ["…"], "count": 2, "authority": "suggested" },
…
],
"origin": { "kind": "patch" },
"version_created_at": "2026-10-28T02:40:26Z"
}
6. 从第 2 卷增量抽取新术语
以系列术语表为输入,对这一卷跑术语任务(按该卷字数 0.5 积分/字:⌈209 × 0.5⌉ = 105)。成功后已有词条保持不变,只把新词以 `suggested` 追加,生成新的术语表版本并发出 `series.glossary.updated` 事件(含 `added_terms`、`glossary_version`)。
curl -X POST "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc/volumes/vol_0mvri9b6q2tHTry6X2O5cSb/glossary" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{}'
# after the job succeeds:
curl "https://xsfyj.com/api/b2b/v1/glossaries/gls_0mvriah1kudAgkROSl89vK9" -H "Authorization: Bearer $KEY"
{
"id": "gls_0mvriah1kudAgkROSl89vK9",
"object": "glossary",
"version": 3,
"term_count": 17,
"terms": [
{ "source": "林逸", "target": "Lin Yi", "gender": "male", "authority": "locked", … },
{ "source": "苏晴", "target": "Su Qing", "gender": "female", "authority": "locked", … },
…
{ "source": "血煞宗", "target": "Blood Fiend Sect", "category": "proper_noun", "authority": "suggested", … },
{ "source": "万妖谷", "target": "Myriad Demon Valley", "category": "proper_noun", "authority": "suggested", … },
{ "source": "噬魂幡", "target": "soul-devouring banner", "category": "cultural_concept", "authority": "suggested", … }
],
"origin": { "kind": "series_increment", "added": 7, "job_id": "job_0mvriby2od1mYMZ2wW0IWVC", "series_id": "ser_0mvri8igdU1ZBKpByrilHDc" }
}
7. 翻译第 2 卷
使用系列世界观和提交时的当前术语表版本,并冻结进任务(`glossary.version`),之后再改术语表不影响已提交的任务。积分:209 字 × 1 + 风格指南附加 ⌈209 × 0.3⌉ = 272。结果通过 `GET /jobs/{id}/files/{file_id}` 下载。
curl -X POST "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc/volumes/vol_0mvri9b6q2tHTry6X2O5cSb/translate" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{}'
{
"id": "job_0mvrieto7PiS3X5kaHeulKk",
"object": "job",
"type": "translation",
"status": "queued",
"source_id": "src_0mvri8wtzFSbMncyV5GZvwu",
"series_id": "ser_0mvri8igdU1ZBKpByrilHDc",
"target_language": "en",
"source_language": "zh-CN",
"options": {
"style_guide": "Keep Chinese names in pinyin; formal, slightly archaic tone for elders.",
"output_format": "translation_only",
"translate_filename": false
},
"glossary": { "mode": "merge", "glossary_id": "gls_0mvriah1kudAgkROSl89vK9", "version": 4, "inline_terms": 0 },
"credits": 272,
"billing_state": "held",
…
}
# succeeded → "result": { "files": [{ "kind": "translated", "file_id": "NVMVRIETV3HS_output_e657f246a7ff4dd0", "filename": "azure-cloud-vol2_translated.txt", "size_bytes": 969 }] }
# "Three months later, Lin Yi had broken through to Foundation Establishment. Yun Zhonghe ordered him to travel with Su Qing to Myriad Demon Valley to investigate the Blood Fiend Sect's traces. …"
8. 修订系列世界观
替换世界观文本并递增 `worldview_version`。之后提交的翻译使用新文本,之前的任务保持原样。
curl -X PATCH "https://xsfyj.com/api/b2b/v1/series/ser_0mvri8igdU1ZBKpByrilHDc/worldview" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{ "worldview": "Genre: Xianxia / cultivation.\nNames: pinyin (Lin Yi, Su Qing, Yun Zhonghe). Su Qing is female; address her as \"Senior Sister\".\nFactions: Azure Cloud Sect (orthodox) vs Blood Fiend Sect (demonic)." }'
{
"id": "ser_0mvri8igdU1ZBKpByrilHDc",
"object": "series",
"glossary_id": "gls_0mvriah1kudAgkROSl89vK9",
"worldview": "Genre: Xianxia / cultivation.\nNames: pinyin (Lin Yi, Su Qing, Yun Zhonghe). Su Qing is female; address her as \"Senior Sister\".\nFactions: …",
"worldview_version": 2,
…
}
- 本例费用:bootstrap 23 + 111,第 2 卷术语 105,第 2 卷翻译 272,共 511 积分。积分提交时预扣,仅在成功后结算。
- 账号同时运行的重型任务数有限,多出的任务停在 `queued`(见 `progress.waiting_reason`)。建议订阅 `job.succeeded` 与 `series.glossary.updated` webhook,而不是轮询。
- 如果某卷没有新人名地名,可以跳过增量术语抽取——翻译本身已按 `merge` 模式应用系列术语表。
- 翻译某卷前先审校新增的 `suggested` 词条(PATCH 时设 `authority: "locked"`),这样被冻结的术语表版本就包含你的决定。
接收 webhook
Webhook 遵循 Standard Webhooks 规范。事件是「瘦事件」:只带 ID 和状态摘要,不含译文——收到后再查询任务(或术语表 / 系列)。事件类型:source.ready、source.failed、job.queued、job.running、job.succeeded、job.failed、job.cancelled、series.glossary.updated、account.credits_low。
1. 创建端点
URL 必须是 443 端口的公网 https(内网、回环、http 地址返回 400 `INVALID_PARAMETER`)。`events` 默认 `["*"]`。签名密钥 `secret` 只在本次响应中返回,请立即保存。每个账号最多 10 个端点。
curl -X POST "https://xsfyj.com/api/b2b/v1/webhook_endpoints" \
-H "Authorization: Bearer $KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/hooks/novo",
"events": ["job.succeeded", "job.failed", "series.glossary.updated"],
"description": "production worker"
}'
{
"id": "whe_0mvri9p5niB6qBCANjOEjQ4",
"object": "webhook_endpoint",
"url": "https://example.com/hooks/novo",
"events": ["job.succeeded", "job.failed", "series.glossary.updated"],
"status": "enabled",
"description": "production worker",
"consecutive_failures": 0,
"disabled_at": null,
"created_at": "2026-10-28T02:38:54Z",
"secret": "whsec_…"
}
2. 发送测试事件并查看投递记录
测试会发送一个 `data.test: true` 的 `job.succeeded` 事件。`GET /webhook_endpoints/{id}` 返回最近 20 条投递记录,含 `status`(pending / succeeded / failed)、`attempts`、`last_status_code`、`last_error`、`next_attempt_at`。
curl -X POST "https://xsfyj.com/api/b2b/v1/webhook_endpoints/whe_0mvri9p5niB6qBCANjOEjQ4/test" \
-H "Authorization: Bearer $KEY"
curl "https://xsfyj.com/api/b2b/v1/webhook_endpoints/whe_0mvri9p5niB6qBCANjOEjQ4" \
-H "Authorization: Bearer $KEY"
{
"object": "webhook_test",
"event_id": "evt_0mvri9zz6q8ZGNnz5y0MZKP",
"endpoint": {
"id": "whe_0mvri9p5niB6qBCANjOEjQ4",
"object": "webhook_endpoint",
"status": "enabled",
"consecutive_failures": 0,
"recent_deliveries": [
{
"id": "dc15bd0c-60e0-47bc-a105-120ce14798d3",
"event_id": "evt_0mvri9zz6q8ZGNnz5y0MZKP",
"event_type": "job.succeeded",
"status": "succeeded",
"attempts": 1,
"last_status_code": 200,
"last_error": null,
"next_attempt_at": "2026-10-28T03:02:53Z"
}
],
…
}
}
3. 端点收到的请求
一个带 JSON 请求体和三个签名头的 POST。`webhook-id` 即事件 ID,重试时不变——用它去重。请在 5 秒内返回 2xx;其他状态码(包括重定向)都算失败。
POST /hooks/novo HTTP/1.1
content-type: application/json
user-agent: NovoTranslator-Webhooks/1.0
webhook-id: evt_0mvriah30unQ1UIWaJkCcDY
webhook-timestamp: 1793155171
webhook-signature: v1,<base64 HMAC-SHA256>
{
"id": "evt_0mvriah30unQ1UIWaJkCcDY",
"object": "event",
"type": "job.succeeded",
"created_at": "2026-10-28T02:39:31Z",
"data": {
"id": "job_0mvri9h45o9tD37yT4cbPPw",
"object": "job",
"type": "glossary",
"status": "succeeded",
"credits": 111,
"series_id": "ser_0mvri8igdU1ZBKpByrilHDc",
"source_id": "src_0mvri8q0pk5VSCNlpLs0k55"
}
}
// series.glossary.updated
{ "id": "evt_0mvrid5lnlq9QtEYr35dZHF", "object": "event", "type": "series.glossary.updated", "created_at": "2026-10-28T02:41:36Z",
"data": { "id": "ser_0mvri8igdU1ZBKpByrilHDc", "object": "series", "glossary_id": "gls_0mvriah1kudAgkROSl89vK9", "glossary_version": 3, "added_terms": 7, "job_id": "job_0mvriby2od1mYMZ2wW0IWVC" } }
4. 验证签名 — Node.js
签名内容为 `{webhook-id}.{webhook-timestamp}.{原始请求体}`,密钥为 `whsec_` 之后部分的 base64 解码字节,算法 HMAC-SHA256。用恒定时间比较,并拒绝与当前时间相差超过 5 分钟的时间戳。
// Node.js ≥ 18 — verify a Standard Webhooks signature (no dependencies)
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyWebhook(secret, headers, rawBody, nowSeconds = Math.floor(Date.now() / 1000)) {
const id = headers["webhook-id"];
const timestamp = Number(headers["webhook-timestamp"]);
if (!id || !Number.isFinite(timestamp)) return false;
if (Math.abs(nowSeconds - timestamp) > 5 * 60) return false; // reject replays / clock skew > 5 min
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
const expected = createHmac("sha256", key).update(id + "." + timestamp + "." + rawBody).digest();
// the header may carry several space-separated signatures, e.g. during secret rotation
return String(headers["webhook-signature"] ?? "").split(" ").some((entry) => {
const [version, value] = entry.split(",");
if (version !== "v1" || !value) return false;
const actual = Buffer.from(value, "base64");
return actual.length === expected.length && timingSafeEqual(actual, expected);
});
}
// Express: keep the raw body — re-serialised JSON will not match the signature
app.post("/hooks/novo", express.raw({ type: "application/json" }), async (req, res) => {
if (!verifyWebhook(process.env.NOVO_WEBHOOK_SECRET, req.headers, req.body.toString("utf8"))) {
return res.status(400).end();
}
const event = JSON.parse(req.body);
res.status(204).end(); // acknowledge fast (< 5 s), work async
await queue.add(event.id, event); // dedupe on event.id
});
// Test vector (standardwebhooks.com) → true:
// verifyWebhook("whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw",
// { "webhook-id": "msg_p5jXN8AQM9LWM0D4loKWxJek", "webhook-timestamp": "1614265330",
// "webhook-signature": "v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=" },
// '{"test": 2432232314}', 1614265330)
5. 验证签名 — Python
算法相同。也可直接使用 Standard Webhooks 官方库(npm / PyPI 包名均为 `standardwebhooks`),与这些头完全兼容。
# Python ≥ 3.10 — verify a Standard Webhooks signature (standard library only)
import base64, hashlib, hmac, time
def verify_webhook(secret: str, headers: dict, raw_body: bytes, now: int | None = None) -> bool:
msg_id = headers.get("webhook-id", "")
timestamp = headers.get("webhook-timestamp", "")
if not msg_id or not timestamp.isdigit():
return False
if abs((now or int(time.time())) - int(timestamp)) > 5 * 60: # reject skew > 5 min
return False
key = base64.b64decode(secret.removeprefix("whsec_"))
signed = f"{msg_id}.{timestamp}.".encode() + raw_body
expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
return any(
version == "v1" and hmac.compare_digest(value, expected)
for version, _, value in (entry.partition(",") for entry in headers.get("webhook-signature", "").split(" "))
)
# Flask: use request.get_data() (raw bytes), and lower-case header names
@app.post("/hooks/novo")
def novo_hook():
headers = {k.lower(): v for k, v in request.headers.items()}
if not verify_webhook(os.environ["NOVO_WEBHOOK_SECRET"], headers, request.get_data()):
abort(400)
enqueue(request.get_json()) # dedupe on event["id"]
return "", 204
6. 重试、自动停用与补拉事件
投递失败会按退避重试(30 秒、2 分、10 分、30 分、1 时、2 时、4 时、8 时、12 时,合计约一天),之后标记为 `failed`。端点连续失败 3 天会被设为 `disabled`;修复后用 PATCH `status: "enabled"` 重新启用(同时清零失败计数)。事件保留 30 天——故障恢复后用 `GET /events` 翻页补拉,再逐个查询任务。
curl -X PATCH "https://xsfyj.com/api/b2b/v1/webhook_endpoints/whe_0mvri9p5niB6qBCANjOEjQ4" \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/json" \
-d '{ "status": "enabled" }'
curl "https://xsfyj.com/api/b2b/v1/events?type=job.succeeded&limit=3" \
-H "Authorization: Bearer $KEY"
# continue with ?cursor=<next_cursor>; delete an endpoint with DELETE /webhook_endpoints/{id} → 204
{
"object": "list",
"data": [
{
"id": "evt_0mvriah30unQ1UIWaJkCcDY",
"object": "event",
"type": "job.succeeded",
"created_at": "2026-10-28T02:39:31Z",
"data": { "id": "job_0mvri9h45o9tD37yT4cbPPw", "object": "job", "type": "glossary", "status": "succeeded", "credits": 111, "series_id": "ser_0mvri8igdU1ZBKpByrilHDc", "source_id": "src_0mvri8q0pk5VSCNlpLs0k55" }
},
…
],
"has_more": true,
"next_cursor": "WyIyMDI2LTEwLTI4VDAyOjM5OjA4Ljg4NVoiLCJldnRfMG12cmk5eno2cThaR05uejV5ME1aS1AiXQ"
}
- 基于原始请求字节验签;解析后再序列化 JSON 会改变空白,导致签名不匹配。
- 不保证投递顺序,同一事件可能到达多次——按 `webhook-id` 去重,并始终重新读取任务获取当前状态。
- 不要泄露端点密钥;一旦泄露,新建端点并删除旧端点。