Novo Translator 开放 API

English

小说翻译 API v1

上传书稿、获取有约束力的积分报价,配合术语表和风格指南翻译,再下载结果。全部接口异步,按积分计费。本页是 API v1 的唯一参考文档;试点用户请看“从试点版迁移”一节。

Base URL
https://novotranslator.com/api/b2b/v1
开发者控制台
/dashboard/developer

快速开始

  1. 登录并确保积分余额大于 0,在开发者控制台(用户中心 > 开发者 API)创建 API 密钥。
  2. POST /sources:上传书稿(.txt、.epub、.docx)。等待 source 状态变为 ready(用 ?wait=30,或轮询 GET /sources/{id})。
  3. POST /quotes:获取免费、有约束力的报价,30 分钟内有效。把 quote_id 传给下一步即可锁定价格。
  4. POST /jobs:创建翻译任务,积分立即冻结。
  5. 用 GET /jobs/{id} 跟踪任务(遵守 poll_after_seconds),或接收 job.* Webhook。
  6. 任务成功后用 GET /jobs/{id}/files/{file_id} 下载结果。

同样的流程用 cURL 表示(把 NOVO_API_KEY 换成你的密钥,并在服务器上执行):

export NOVO_API_KEY="<your key>"
BASE="https://novotranslator.com/api/b2b/v1"

# 1. Upload the manuscript (waits up to 30 s for analysis)
curl -X POST "$BASE/sources?wait=30" \
  -H "Authorization: Bearer $NOVO_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F "[email protected]"
# -> {"id":"src_...","status":"ready","characters":120345,...}

# 2. Quote (free, valid 30 minutes)
curl -X POST "$BASE/quotes" \
  -H "Authorization: Bearer $NOVO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"source_id":"src_...","target_language":"en"}'
# -> {"id":"qte_...","total_credits":120345,...}

# 3. Create the translation job (credits are held)
curl -X POST "$BASE/jobs" \
  -H "Authorization: Bearer $NOVO_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type":"translation","source_id":"src_...","target_language":"en","quote_id":"qte_...","glossary":{"mode":"auto"}}'
# -> 202 {"id":"job_...","status":"queued","poll_after_seconds":5,...}

# 4. Poll (or use webhooks)
curl "$BASE/jobs/job_..." -H "Authorization: Bearer $NOVO_API_KEY"

# 5. Download the result
curl -L "$BASE/jobs/job_.../files/file_..." -H "Authorization: Bearer $NOVO_API_KEY" -o translated.txt

接口地址

  • 使用上方显示的 Base URL。生产地址:https://open.novotranslator.com/v1(国际)和 https://open.xsfyj.com/v1(国内)。
  • 主站上的路径别名 /api/b2b/v1 指向同一套 API,为兼容而保留。
  • 除文件上传(multipart/form-data)和下载外,请求与响应均为 UTF-8 JSON。时间戳为 UTC 的 RFC 3339 格式。

认证与 API 密钥

  • 用 Bearer 令牌发送密钥:Authorization: Bearer <key>。
  • 只能在你的服务器端调用。切勿把密钥放进浏览器、手机 App 或公开仓库;带浏览器 Origin 头的请求会被拒绝(BROWSER_ORIGIN_FORBIDDEN)。
  • 密钥只在创建时显示一次,库里只存哈希,丢失无法找回,请新建。
  • 密钥带权限范围(sources:write、jobs:write、jobs:read、glossaries:write、series:write、webhooks:write、account:read),可选 IP 白名单、月度消费上限和到期时间。
  • 创建密钥需要邮箱已验证且积分余额大于 0;每个账号最多 10 个有效密钥。
  • 在控制台轮换密钥:新密钥立即生效,旧密钥再保留 24 小时。

积分计费

价格以积分计;花钱之前先用 POST /quotes 查看确切数字。

项目规则
翻译所选范围每字符 1 积分(整本,或 start_percent 到 end_percent)。
风格指南按全文长度加收 30%,Plus 套餐免收。指南最多 500 字。
术语表提取源文每字符 0.5 积分。
世界观源文每字符 0.1 积分。
预览免费:每账号每天(UTC)10 次,每次最多 10,000 字符。
  • 创建任务时冻结积分,成功后扣除,失败或取消则全额释放。
  • 余额不足会返回 INSUFFICIENT_CREDITS,并在 meta.top_up_url 给出充值链接。

术语表模式

任务里的 glossary 对象决定你的术语与自动提取如何配合。

模式行为
auto不提供术语表:由系统自行提取术语。
merge应用你的术语,系统补充它发现的术语;冲突时以你的为准。
strict只用你的术语,不自动新增。

系列工作流

  1. POST /series:创建系列(共享世界观和累积术语表)。
  2. POST /series/{id}/volumes:逐卷加入(已分析的 source)。
  3. POST /series/{id}/bootstrap:在锚点卷上运行世界观和术语表提取。
  4. POST /series/{id}/volumes/{volume_id}/glossary:为后续每一卷提取增量术语,并合并进系列术语表。
  5. POST /series/{id}/volumes/{volume_id}/translate:用系列世界观和冻结的术语表版本翻译该卷。

幂等

  • 所有写请求(POST、PATCH)必须带 Idempotency-Key 头:1-200 个不含空白的可见字符,例如 UUID。
  • 24 小时内用相同的键和请求体重复请求,会回放原响应,不会重复创建。
  • 相同的键但请求体不同返回 409 IDEMPOTENCY_KEY_MISMATCH;并发重复请求返回 409 IDEMPOTENCY_IN_PROGRESS,稍后重试即可。

异步任务与冷启动

  • 任务是异步的。工作进程冷启动时,任务可能排队几十秒到几分钟。
  • 轮询 GET /jobs/{id} 的频率不要超过响应里 poll_after_seconds 的值,或者直接用 Webhook 代替轮询。
  • 状态:queued、running、succeeded、failed、cancelled。只有 queued 的任务可以取消。

示例

每种任务类型都有可直接复制的完整示例。把 $KEY 换成你的 API key;响应来自测试环境的真实返回,已裁剪。

上传源文件并预分析

所有任务都从一个源文件(source)开始。上传免费:服务端统计字数、识别源语言并检查输入质量,暂存 7 天,期间可反复报价、创建多个任务而无需重新上传。

1. 上传文件并最多等待 30 秒

支持 .txt、.epub、.docx(≤ 50 MiB)。`?wait=30` 让请求等到分析完成(201)或超时(202,status 为 `analyzing`)。`target_language` 可选,不影响分析结果。

curl -X POST "https://novotranslator.com/api/b2b/v1/sources?wait=30" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -F "[email protected]" \
  -F "target_language=en"
{
  "id": "src_0mvri8g568XfrxRhqf6Az4C",
  "object": "source",
  "status": "ready",
  "filename": "novel.epub",
  "format": "epub",
  "size_bytes": 2794,
  "sha256": "74ce50caa62b3d258611dbd62d5a71ac6ad3044528b5ea97e3b2b829817bd1fd",
  "characters": 328,
  "words": null,
  "detected_language": { "code": "zh-CN", "confidence": 0.8333, "low_confidence": false },
  "input_quality": null,
  "error": null,
  "expires_at": "2026-11-04T02:37:55Z",
  "created_at": "2026-10-28T02:37:56Z"
}

2. 或以 JSON 直接提交文本

不带 `wait` 时立即返回 202,状态为 `analyzing`。`filename` 可选,缺少扩展名时自动补 `.txt`。文本源上限 2,000,000 字符。

curl -X POST "https://novotranslator.com/api/b2b/v1/sources" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"text": "第一章 雾港\n\n雾港的钟声在黄昏时响了七下……", "filename": "chapter-01.txt"}'
{
  "id": "src_0mvri8s1fNYJdJ4MDpr8QxB",
  "object": "source",
  "status": "analyzing",
  "filename": "chapter-01.txt",
  "format": "txt",
  "size_bytes": 974,
  "sha256": null,
  "characters": null,
  "words": null,
  "detected_language": null,
  "input_quality": null,
  "error": null,
  "expires_at": null,
  "created_at": "2026-10-28T02:38:11Z"
}

3. 轮询直到源文件就绪

GET 同样支持 `?wait=`(最长 30 秒)。终态为 `ready` 或 `failed`(看 `error.code`,如 NO_TRANSLATABLE_CONTENT)。`words` 只对以空格分词的语言给出,英文源会返回如 `"words": 41`。

curl "https://novotranslator.com/api/b2b/v1/sources/src_0mvri8s1fNYJdJ4MDpr8QxB?wait=20" \
  -H "Authorization: Bearer $KEY"
{
  "id": "src_0mvri8s1fNYJdJ4MDpr8QxB",
  "object": "source",
  "status": "ready",
  "filename": "chapter-01.txt",
  "format": "txt",
  "size_bytes": 974,
  "sha256": "9aeb9b5e0433de21778daf2b3bdae694cdf0c0fc320733b085b7ac0a6208b66d",
  "characters": 321,
  "words": null,
  "detected_language": { "code": "zh-CN", "confidence": 0.8333, "low_confidence": false },
  "input_quality": null,
  "error": null,
  "expires_at": "2026-11-04T02:38:11Z",
  "created_at": "2026-10-28T02:38:11Z"
}
  • 在 expires_at(7 天)之前,报价和建任务都复用同一个 source_id;过期(SOURCE_EXPIRED)后再重新上传。
  • `characters` 是计费的权威字数,报价与扣费都以它为准,而不是你本地统计的字数。
  • 对仍在 `analyzing` 的源建任务会返回 SOURCE_NOT_READY,并带 Retry-After: 2。

一次报价多个任务

一次报价可对同一源文件计算最多 4 个任务的价格并返回余额。报价不预留积分,30 分钟内有效。规则:翻译 = 所选范围字数 × 1 积分;自定义风格指南按全文加收 30%(Plus 免收);术语表 = 0.5 积分/字;世界观 = 0.1 积分/字;预览翻译免费(每日 10 次,≤ 10,000 字)。

1. 报价:术语表 + 翻译(前半部分,带风格指南)+ 世界观

顶层 `options` / `glossary` 作用于所有任务,单个任务内的同名字段覆盖它。本例翻译范围为 0–50%(328 字中的 164 字),但风格指南加收按全文计算:ceil(328 × 0.3) = 99。

curl -X POST "https://novotranslator.com/api/b2b/v1/quotes" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "source_id": "src_0mvri8g568XfrxRhqf6Az4C",
    "source_language": "zh",
    "target_language": "en",
    "jobs": [
      { "type": "glossary" },
      { "type": "translation", "options": {
          "style_guide": "Keep a restrained literary tone; romanize names in pinyin.",
          "scope": { "start_percent": 0, "end_percent": 50 } } },
      { "type": "worldview" }
    ]
  }'
{
  "id": "quo_0mvri9ezlgx1T4CTCRglnh1",
  "object": "quote",
  "source_id": "src_0mvri8g568XfrxRhqf6Az4C",
  "target_language": "en",
  "items": [
    { "type": "glossary", "characters": 328, "credits": 164,
      "breakdown": { "base_credits": 164, "style_guide_credits": 0, "style_guide_waived": false, "scope": null } },
    { "type": "translation", "characters": 164, "credits": 263,
      "breakdown": { "base_credits": 164, "style_guide_credits": 99, "style_guide_waived": false,
                     "scope": { "start": 0, "end_exclusive": 164 } } },
    { "type": "worldview", "characters": 328, "credits": 33,
      "breakdown": { "base_credits": 33, "style_guide_credits": 0, "style_guide_waived": false, "scope": null } }
  ],
  "total_credits": 460,
  "balance": 199521,
  "sufficient": true,
  "warnings": [],
  "expires_at": "2026-10-28T03:08:41Z",
  "created_at": "2026-10-28T02:38:41Z"
}

2. 用 quote_id 锁定价格

建任务时带上 `quote_id`。若任务价格与报价中对应项不一致(参数变了、报价过期或源文件不同),任务会被拒绝而不是按意外金额扣费。下例去掉了风格指南:

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type": "translation", "source_id": "src_0mvri8g568XfrxRhqf6Az4C", "source_language": "zh",
       "target_language": "en", "quote_id": "quo_0mvri9ezlgx1T4CTCRglnh1",
       "options": {"scope": {"start_percent": 0, "end_percent": 50}}}'
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
  "type": "…/api-docs#error-QUOTE_EXPIRED_OR_CHANGED",
  "title": "Quote expired or changed",
  "status": 409,
  "code": "QUOTE_EXPIRED_OR_CHANGED",
  "detail": "The price changed since the quote; create a new quote.",
  "param": "quote_id",
  "request_id": "req_0mvribqvn2vUvxz5TCEPeuo",
  "doc_url": "…/api-docs#error-QUOTE_EXPIRED_OR_CHANGED",
  "meta": { "quoted_credits": 263, "current_credits": 164 }
}
  • 报价免费,不需要 Idempotency-Key;参数一变就重新报价。
  • 建任务前先看 `sufficient`:任务创建时预扣(held),完成后结算。
  • 当声明的 source_language 与识别结果不一致时,`warnings` 中会出现 SOURCE_LANGUAGE_MISMATCH(见下文)。

语言代码与源语言确认

语言使用 GET /languages 返回的 BCP 47 代码,并接受常见别名:zh、zh-Hans → zh-CN,zh-Hant → zh-TW。source_language 默认为 auto。

1. 列出支持的语言

curl "https://novotranslator.com/api/b2b/v1/languages" -H "Authorization: Bearer $KEY"
{
  "object": "languages",
  "source": [
    { "code": "auto", "name": "Auto Detect", "native_name": "Auto" },
    { "code": "zh-CN", "name": "Chinese (Simplified)", "native_name": "简体中文" },
    { "code": "en", "name": "English", "native_name": "English" },
    { "code": "ja", "name": "Japanese", "native_name": "日本語" },
    "…"
  ],
  "target": ["…"],
  "aliases": { "zh": "zh-CN", "zh-Hans": "zh-CN", "zh-Hant": "zh-TW" }
}

2. 声明语言与识别结果不一致:409

报价只给警告;建任务时会以 SOURCE_LANGUAGE_CONFIRMATION_REQUIRED 拒绝,不扣积分。通常应改正 source_language(或改用 auto)。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type": "preview_translation", "source_id": "src_0mvri8g568XfrxRhqf6Az4C",
       "source_language": "ja", "target_language": "en"}'
HTTP/1.1 409 Conflict
Content-Type: application/problem+json

{
  "type": "…/api-docs#error-SOURCE_LANGUAGE_CONFIRMATION_REQUIRED",
  "title": "Confirm source language",
  "status": 409,
  "code": "SOURCE_LANGUAGE_CONFIRMATION_REQUIRED",
  "detail": "Detected zh-CN, but source_language is ja.",
  "param": "confirm_source_language",
  "request_id": "req_0mvria99sQa1g5ucnRnScBq",
  "doc_url": "…/api-docs#error-SOURCE_LANGUAGE_CONFIRMATION_REQUIRED",
  "meta": { "selected_language": "ja", "detected_language": "zh-CN" }
}

3. 坚持原选择:带 confirm_source_language 重发

仅在确认识别有误时使用(例如混合语言文本)。请求体已变化,需换一个新的 Idempotency-Key。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type": "preview_translation", "source_id": "src_0mvri8g568XfrxRhqf6Az4C",
       "source_language": "ja", "target_language": "en", "confirm_source_language": true}'
{
  "id": "job_0mvriafihuLX6Rxnycbt5k4",
  "object": "job",
  "type": "preview_translation",
  "status": "queued",
  "source_language": "ja",
  "target_language": "en",
  "credits": 0,
  "billing_state": "none",
  "poll_after_seconds": 5,
  "…": "…"
}

抽取世界观并复用

世界观任务通读整个源文件,生成一份译者说明:题材、时代背景、语域、叙述者身份、关键译名与术语指引。按全文字数 0.1 积分/字计费。之后把结果注入翻译任务(后续分卷、重译),即可保持译名和文风一致,且无需再次付费抽取。

1. 创建世界观任务

`target_language` 决定说明中译名参考面向的目标语言。返回 202、状态 `queued`;积分此时预扣,成功后结算。

curl -X POST "https://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.com/api/b2b/v1/jobs/job_0mvriardeM8hGujFyWfbGY0/worldview" \
  -H "Authorization: Bearer $KEY" | jq -r .worldview)

curl -X POST "https://novotranslator.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 即可。

从源文件抽取术语表

术语任务通读全文,返回人名、地名、门派、称谓、功法等术语及建议译名、备选译名、类别、性别和出现次数。按源文每字 0.5 积分计费(399 字 → 200 积分)。

1. 创建术语任务

创建时预留积分(`billing_state: held`),成功后扣除,失败或取消时释放。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type": "glossary", "source_id": "src_0mvri8vl8f7PDVEwlqpkm5B", "target_language": "en"}'
{
  "id": "job_0mvri97fqVgsuxDwMqNrsCz",
  "object": "job",
  "type": "glossary",
  "status": "queued",
  "source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
  "credits": 200,
  "billing_state": "held",
  "progress": { "stage": null, "percent": 0, "waiting_reason": null },
  "poll_after_seconds": 5,
  "created_at": "2026-10-28T02:38:31Z"
}

2. 轮询到成功,再读取术语

按 `poll_after_seconds` 间隔轮询 `GET /jobs/{id}`(本例不到一分钟完成)。`/glossary` 以公开格式返回术语;抽取出的词条在存入术语表资源前均为 `authority: suggested`。

curl "https://novotranslator.com/api/b2b/v1/jobs/job_0mvri97fqVgsuxDwMqNrsCz/glossary" \
  -H "Authorization: Bearer $KEY"
{
  "job_id": "job_0mvri97fqVgsuxDwMqNrsCz",
  "object": "glossary_result",
  "term_count": 15,
  "terms": [
    { "source": "苏清寒", "target": "Su Qinghan", "category": "person_name", "gender": "female",
      "note": "Senior disciple of the sect leader…", "count": 4, "authority": "suggested" },
    { "source": "凌霄城", "target": "Lingxiao City", "category": "proper_noun", "gender": null,
      "note": "The city where Lin Yi grew up…", "alternatives": ["Sky-Soaring City"], "count": 3, "authority": "suggested" },
    { "source": "藏经阁", "target": "Scripture Pavilion", "category": "cultural_concept", "gender": null,
      "note": "The sect's repository of scriptures…", "alternatives": ["Sutra Pavilion", "Library Pavilion"], "count": 2, "authority": "suggested" },
    { "source": "血煞门", "target": "Blood Fiend Sect", "category": "proper_noun", "gender": null,
      "note": "A demonic sect recently active near Lingxiao City…", "alternatives": ["Blood Fiend Gate"], "count": 2, "authority": "suggested" },
    "…"
  ]
}
  • 翻译前先审阅抽取结果:可以存成术语表资源(见下一个示例)修改后再交给翻译任务。
  • 术语任务始终读取全文;`options.scope` 只对翻译任务生效。

版本化的术语表资源

术语表资源(`gls_…`)保存你确认过的术语。每次修改都生成一个不可变的新版本,翻译任务记录所用的确切版本,重跑结果可复现。可以从术语任务、CSV 文件或内联 `terms` 创建。

1. 从术语任务结果创建术语表

从任务复制的词条标为 `authority: locked`(用户确认)。每个版本的 `origin` 记录其来源。

curl -X POST "https://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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 条。
  • 创建和修改术语表免费,只有使用它的任务才计费。

翻译任务中的三种术语模式

`glossary.mode` 决定翻译任务如何使用术语。`auto`(默认,可省略 `glossary`):管线自行维护一致性。`merge`:你的术语优先,管线仍会抽取并补充新术语。`strict`:只用你的术语、跳过自动抽取,适合出版社权威术语表。术语来自内联 `glossary.terms`、`glossary.glossary_id`(可选 `version`,默认当前版本),或两者同时提供。模式不影响价格。

1. merge + 内联术语

译文采用了请求中的 "Azure Cloud Sect" 与 "Crimson Blood Gate",同时保留了自动抽取的 "Lingxiao City" 等译名。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "translation",
    "source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
    "target_language": "en",
    "glossary": {
      "mode": "merge",
      "terms": [
        {"source": "林逸", "target": "Lin Yi", "category": "person_name", "gender": "male"},
        {"source": "青云宗", "target": "Azure Cloud Sect", "category": "proper_noun"},
        {"source": "血煞门", "target": "Crimson Blood Gate", "category": "proper_noun"}
      ]
    }
  }'
{
  "id": "job_0mvridrx9xs6YwBNBlcszRV",
  "object": "job",
  "type": "translation",
  "status": "queued",
  "credits": 399,
  "billing_state": "held",
  "…": "…"
}

2. strict + 固定版本的术语表

任务在 `glossary` 字段记录所用术语表 id 与版本。译文严格采用了导入的术语("Blood Fiend Sect"、"Taixuan Sword Art")。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "translation",
    "source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
    "target_language": "en",
    "glossary": {"mode": "strict", "glossary_id": "gls_0mvric0k0kq6EjO0gxRkPrD", "version": 1}
  }'
{
  "id": "job_0mvridxsxosPwA5dYyihn2U",
  "object": "job",
  "type": "translation",
  "status": "queued",
  "glossary": { "mode": "strict", "glossary_id": "gls_0mvric0k0kq6EjO0gxRkPrD", "version": 1, "inline_terms": 0 },
  "credits": 399,
  "billing_state": "held",
  "…": "…"
}
  • 推荐流程:术语任务 → 审阅 → 存为术语表资源 → 用 `merge` 翻译(定稿的出版社术语表用 `strict`)。
  • `glossary_id` 与内联 `terms` 可以同时传:内联词条叠加在该术语表版本之上(两者的 `source` 请勿重复)。内联术语最多 5,000 条。
  • `merge`/`strict` 未提供任何术语时返回 422 `GLOSSARY_INVALID`。报价免费:可先把同一个 `glossary` 对象发给 `POST /quotes` 校验。

带选项翻译一个源文件

翻译按所选范围的字数每字 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://novotranslator.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://novotranslator.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://novotranslator.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`,属正常排队,轮到后自动开始。

列出并下载产物

任务成功后、留存期结束前可以下载产物。下载会跳转到最长 120 秒有效的签名存储地址,每次下载请重新获取,不要保存链接。

1. 列出产物

curl "https://novotranslator.com/api/b2b/v1/jobs/job_0mvrid2ce1Vv9nvcqbyUkw8/files" \
  -H "Authorization: Bearer $KEY"
{
  "object": "list",
  "data": [{
    "file_id": "NVMVRID2O4ZS_output_ec08cf5334ea43c9",
    "filename": "Chapter 1 Entering Qingyun (chapter-1).range-0-50_bilingual.txt",
    "size_bytes": 1983,
    "kind": "translated"
  }],
  "has_more": false,
  "next_cursor": null
}

2. 下载(302 跳转)

`-L` 跟随跳转;curl 跳到其他域名时会自动去掉 `Authorization` 头,这正是期望的行为。

curl -L -o out.txt \
  "https://novotranslator.com/api/b2b/v1/jobs/job_0mvrid2ce1Vv9nvcqbyUkw8/files/NVMVRID2O4ZS_output_ec08cf5334ea43c9" \
  -H "Authorization: Bearer $KEY"
HTTP/1.1 302 Found
Location: https://….r2.cloudflarestorage.com/…?X-Amz-Expires=120&X-Amz-Signature=…

# out.txt (original_above)
第一章 青云入门
Chapter 1: Entering Qingyun

林逸站在青云宗的山门前,抬头望着那块写着“青云”二字的巨石。…
Lin Yi stood before the mountain gate of the Qingyun Sect, looking up at the massive stone carved with the words "Qingyun." …

3. 以 JSON 获取下载链接

curl "https://novotranslator.com/api/b2b/v1/jobs/job_0mvrid2ce1Vv9nvcqbyUkw8/files/NVMVRID2O4ZS_output_ec08cf5334ea43c9?redirect=false" \
  -H "Authorization: Bearer $KEY"
{
  "url": "https://….r2.cloudflarestorage.com/…?X-Amz-Expires=120&X-Amz-Signature=…",
  "filename": "Chapter 1 Entering Qingyun (chapter-1).range-0-50_bilingual.txt",
  "size_bytes": 1983,
  "expires_at": "2026-10-28T02:45:11Z"
}

免费预览翻译

`preview_translation` 免费翻译源文件开头,便于付费前检查质量:每次最多 10,000 字(`options.char_limit`),每账号每 UTC 日 10 次(见 `GET /account` 的 `limits.free_previews_per_day`)。产物为已译的开头部分加其余未译原文。

1. 创建预览

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type": "preview_translation", "source_id": "src_0mvri8vl8f7PDVEwlqpkm5B",
       "target_language": "en", "options": {"char_limit": 300}}'
{
  "id": "job_0mvrig576CHCY8cT3q7Qg0a",
  "object": "job",
  "type": "preview_translation",
  "status": "queued",
  "options": { "char_limit": 300, "output_format": "translation_only", "translate_filename": false },
  "credits": 0,
  "billing_state": "none",
  "poll_after_seconds": 5,
  "…": "…"
}
  • 轮询与下载方式与翻译任务相同。当日免费次数用完后返回 429 `DAILY_QUOTA_EXCEEDED`,UTC 零点后恢复。

取消任务、列出任务与积分

积分随任务流转:创建时冻结(`billing_state: held`),成功后扣除(`consumed`),失败或取消时全额释放(`released`)。只有 `queued` 状态的任务可以取消。

1. 取消排队中的任务

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs/job_0mvrie3t4wiz0fxr1IWp7yS/cancel" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)"
{
  "id": "job_0mvrie3t4wiz0fxr1IWp7yS",
  "object": "job",
  "type": "translation",
  "status": "cancelled",
  "credits": 399,
  "billing_state": "released",
  "completed_at": "2026-10-28T02:42:34Z",
  "…": "…"
}

2. 运行中的任务不能取消

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs/job_0mvrid2ce1Vv9nvcqbyUkw8/cancel" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)"
{
  "type": "https://novotranslator.com/api-docs#error-JOB_NOT_CANCELLABLE",
  "title": "Job not cancellable",
  "status": 409,
  "code": "JOB_NOT_CANCELLABLE",
  "detail": "Only queued jobs can be cancelled.",
  "param": null,
  "request_id": "req_0mvridezjBgGsAr5CxkbtHt"
}

3. 按条件列出任务并翻页

筛选条件:`type`、`status`、`series_id`、`created_after`(RFC 3339)。按创建时间倒序。`has_more` 为 true 时,带相同筛选条件并把 `next_cursor` 作为 `cursor` 继续请求。网页创建的任务同样会列出。

curl "https://novotranslator.com/api/b2b/v1/jobs?status=succeeded&limit=2" -H "Authorization: Bearer $KEY"
curl "https://novotranslator.com/api/b2b/v1/jobs?status=succeeded&limit=2&cursor=WyIyMDI2LTEwLTI4VDAyOjQyOjUzLjk5NVoiLCJqb2JfMG12cmlldG83UGlTM1g1a2FIZXVsS2siXQ" \
  -H "Authorization: Bearer $KEY"
{
  "object": "list",
  "data": [
    { "id": "job_0mvrig576CHCY8cT3q7Qg0a", "object": "job", "type": "preview_translation", "status": "succeeded", "…": "…" },
    { "id": "job_0mvrieto7PiS3X5kaHeulKk", "object": "job", "type": "translation", "status": "succeeded", "…": "…" }
  ],
  "has_more": true,
  "next_cursor": "WyIyMDI2LTEwLTI4VDAyOjQyOjUzLjk5NVoiLCJqb2JfMG12cmlldG83UGlTM1g1a2FIZXVsS2siXQ"
}

4. 积分不足 → 402

创建大任务前,可先看报价中的 `sufficient` 或 `GET /account` 的 `balance.total_credits`。返回此错误时不会冻结任何积分。

curl -X POST "https://novotranslator.com/api/b2b/v1/jobs" … # same request as above
{
  "type": "https://novotranslator.com/api-docs#error-INSUFFICIENT_CREDITS",
  "title": "Insufficient credits",
  "status": 402,
  "code": "INSUFFICIENT_CREDITS",
  "detail": "This job needs 320 credits.",
  "param": null,
  "request_id": "req_…",
  "meta": { "required_credits": 320, "top_up_url": "https://novotranslator.com/pricing" }
}
  • 用相同的 `Idempotency-Key` 和请求体重试 `POST /jobs`,会返回原任务而不会重复创建或扣费;幂等键保留 24 小时。
  • 写请求按 key 限流(见 `X-RateLimit-*` 响应头);遇到 429 时按 `Retry-After` 秒数等待后重试。
  • `DELETE /jobs/{id}` 可提前删除任务产物(隐私需要),任务记录与账单保留。

多卷系列翻译

系列让所有分卷共用一份世界观和一张不断累积的术语表,第 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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.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://novotranslator.com/api/b2b/v1/webhook_endpoints/whe_0mvri9p5niB6qBCANjOEjQ4/test" \
  -H "Authorization: Bearer $KEY"

curl "https://novotranslator.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://novotranslator.com/api/b2b/v1/webhook_endpoints/whe_0mvri9p5niB6qBCANjOEjQ4" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{ "status": "enabled" }'

curl "https://novotranslator.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` 去重,并始终重新读取任务获取当前状态。
  • 不要泄露端点密钥;一旦泄露,新建端点并删除旧端点。

错误、幂等与限流

所有错误都是 RFC 9457 `application/problem+json`,含稳定的 `code`、出错字段 `param` 和用于联系支持的 `request_id`。写请求都需要 `Idempotency-Key`(DELETE、报价以及 webhook 端点的 PATCH / 测试调用除外),网络重试不会重复建任务或重复扣费。

1. 错误格式

按 `code` 分支处理(见错误码表),不要依赖 `title` 或 `detail` 文本。可重试的错误为 409 `IDEMPOTENCY_IN_PROGRESS`、`SOURCE_NOT_READY`、429 与 5xx。

curl -X POST "https://novotranslator.com/api/b2b/v1/series" \
  -H "Authorization: Bearer $KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Bad", "target_language": "en", "glossary_mode": "loose" }'
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
  "type": "https://novotranslator.com/api-docs#error-INVALID_PARAMETER",
  "title": "Invalid parameter",
  "status": 400,
  "code": "INVALID_PARAMETER",
  "detail": "Invalid enum value. Expected 'merge' | 'strict', received 'loose'",
  "param": "glossary_mode",
  "request_id": "req_0mvridxjxTehHd67LwkPNz7",
  "doc_url": "https://novotranslator.com/api-docs#error-INVALID_PARAMETER"
}

2. 用 Idempotency-Key 安全重试

每个业务操作生成一个键,重试时始终复用。同键同请求体返回首次保存的响应(状态码与 ID 不变),并带 `Idempotent-Replayed: true`。同键不同请求体返回 409 `IDEMPOTENCY_KEY_MISMATCH`;写请求不带键返回 400 `IDEMPOTENCY_KEY_REQUIRED`。

IK=$(uuidgen)
curl -i -X POST "https://novotranslator.com/api/b2b/v1/series" -H "Authorization: Bearer $KEY" -H "Idempotency-Key: $IK" \
  -H "Content-Type: application/json" -d '{"name":"Idempotency demo","target_language":"en"}'
# retry (e.g. after a timeout) — same key, same body
curl -i -X POST "https://novotranslator.com/api/b2b/v1/series" -H "Authorization: Bearer $KEY" -H "Idempotency-Key: $IK" \
  -H "Content-Type: application/json" -d '{"name":"Idempotency demo","target_language":"en"}'
# same key, different body
curl -i -X POST "https://novotranslator.com/api/b2b/v1/series" -H "Authorization: Bearer $KEY" -H "Idempotency-Key: $IK" \
  -H "Content-Type: application/json" -d '{"name":"Idempotency demo 2","target_language":"en"}'
HTTP/1.1 201 Created
{ "id": "ser_0mvrid4s0TAE07g4Zo0T8sr", "object": "series", "name": "Idempotency demo", … }

HTTP/1.1 201 Created
Idempotent-Replayed: true
{ "id": "ser_0mvrid4s0TAE07g4Zo0T8sr", "object": "series", "name": "Idempotency demo", … }

HTTP/1.1 409 Conflict
Content-Type: application/problem+json
{ "code": "IDEMPOTENCY_KEY_MISMATCH", "status": 409, "title": "Idempotency-Key reused", "detail": "Idempotency-Key reused", "param": null, "request_id": "req_0mvridfjtLquimeSMXpZdok", … }

3. 限流

每个响应都带当前 key 窗口的 IETF `RateLimit` / `RateLimit-Policy` 头(以及 `X-RateLimit-*`);读、写分别计数(见 `GET /account` 的 `limits.read_per_minute` / `write_per_minute`)。遇到 429 `RATE_LIMITED` 等待 `Retry-After` 秒;5xx 用带抖动的指数退避。

curl -i "https://novotranslator.com/api/b2b/v1/account" -H "Authorization: Bearer $KEY"
HTTP/1.1 200 OK
RateLimit-Policy: "read-1m";q=120;w=60
RateLimit: "read-1m";r=118;t=20
X-RateLimit-Limit: 120
X-RateLimit-Remaining: 118
X-RateLimit-Reset: 20

# when the write window is exhausted:
HTTP/1.1 429 Too Many Requests
Content-Type: application/problem+json
Retry-After: 17
RateLimit-Policy: "write-1m";q=20;w=60
RateLimit: "write-1m";r=0;t=17
{ "code": "RATE_LIMITED", "status": 429, "title": "Rate limited", "detail": "Limit of 20 requests per minute exceeded.", "request_id": "req_…", … }

限流与档位

限流按密钥计,并取决于密钥所在档位。新密钥默认标准档(每个账号同时只跑 1 个重任务,其余排队);需要更高并发请联系我们开通合作伙伴档。

档位读 / 分钟写 / 分钟上传 / 天上传 GiB / 天运行中任务排队任务任务 / 天
标准档(默认)12020100111050
合作伙伴档(申请开通)30060100010350500

响应头

Header
RateLimit-Policy, RateLimitIETF 草案限流头:策略窗口与剩余额度。
X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset同样的信息,事实标准写法。
Retry-After需等待的秒数;随 429 返回(RATE_LIMITED、QUEUE_LIMIT_EXCEEDED、DAILY_QUOTA_EXCEEDED)。

遇到 429、5xx 和网络错误请指数退避;重试写请求时务必复用同一个 Idempotency-Key。

Webhook

  • 在控制台或用 POST /webhook_endpoints 注册 HTTPS 端点。签名密钥(whsec_...)只显示一次。
  • 投递遵循 Standard Webhooks 规范,带 webhook-id、webhook-timestamp、webhook-signature 三个头。
  • webhook-signature 为 v1,<base64 HMAC-SHA256>,签名内容是 `${id}.${timestamp}.${body}`;HMAC 密钥是 whsec_ 前缀之后 base64 字符串解码得到的字节。
  • 拒绝时间戳早于 5 分钟的请求,并按 webhook-id 去重。
  • 几秒内回复任意 2xx 即可。失败会在约 24 小时内按递增间隔重试;端点连续 3 天全部失败会被自动停用(可在控制台重新启用)。
  • 漏了事件?GET /events 可列出最近 30 天的事件。

事件类型

source.readysource.failedjob.queuedjob.runningjob.succeededjob.failedjob.cancelledseries.glossary.updatedaccount.credits_low

验证签名(Node.js)

import { createHmac, timingSafeEqual } from "node:crypto";

// secret: the "whsec_..." value shown once when you created the endpoint
// rawBody: the request body as the exact received string (do not re-serialize)
export function verifyWebhook(secret, headers, rawBody) {
  const id = headers["webhook-id"];
  const timestamp = Number(headers["webhook-timestamp"]);
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false; // 5 min tolerance

  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = createHmac("sha256", key)
    .update(`${id}.${timestamp}.${rawBody}`)
    .digest("base64");

  // the header may hold several space-separated "v1,<signature>" values
  return headers["webhook-signature"].split(" ").some((part) => {
    const [version, signature] = part.split(",");
    if (version !== "v1" || !signature) return false;
    const a = Buffer.from(signature);
    const b = Buffer.from(expected);
    return a.length === b.length && timingSafeEqual(a, b);
  });
}

接口一览

路径相对于 Base URL。完整 schema 见 OpenAPI 文档。 /api/b2b/v1/openapi.json

方法路径权限说明
GET/accountaccount:readAccount balance, tier and limits
GET/languagesjobs:readSupported source / target language codes
GET/usageaccount:readDaily usage (jobs, credits)
POST/sourcesidemsources:writeUpload a source and start pre-analysis
GET/sources/{id}jobs:readPre-analysis result: characters, words, detected language
DELETE/sources/{id}sources:writeDelete a staged source
POST/quotesjobs:writeQuote credits for one or more jobs (free, valid 30 min)
POST/jobsidemjobs:writeCreate a worldview / glossary / translation / preview job
GET/jobsjobs:readList jobs (task center)
GET/jobs/{id}jobs:readJob status, progress and cost
DELETE/jobs/{id}jobs:writeRevoke access to a finished job's artifacts
POST/jobs/{id}/cancelidemjobs:writeCancel a queued job (credits released)
GET/jobs/{id}/filesjobs:readList output files
GET/jobs/{id}/files/{file_id}jobs:read302 to a short-lived download URL (`?redirect=false` for JSON)
GET/jobs/{id}/glossaryjobs:readStructured terms of a glossary job
GET/jobs/{id}/worldviewjobs:readWorldview text of a worldview job
POST/glossariesidemglossaries:writeCreate a versioned glossary (terms, from_job_id, or CSV upload)
GET/glossariesjobs:readList glossaries
GET/glossaries/{id}jobs:readGet a glossary version (`?version=`)
PATCH/glossaries/{id}idemglossaries:writeUpsert / remove terms → new immutable version (If-Match)
DELETE/glossaries/{id}glossaries:writeDelete a glossary
GET/glossaries/{id}/exportjobs:readExport as CSV (workbench-compatible)
POST/seriesidemseries:writeCreate a series (shared worldview + cumulative glossary)
GET/seriesjobs:readList series
GET/series/{id}jobs:readSeries with volumes and their jobs
POST/series/{id}/volumesidemseries:writeAdd a volume (an analyzed source)
POST/series/{id}/bootstrapidemseries:writeRun worldview + glossary on the anchor volume
POST/series/{id}/volumes/{volume_id}/glossaryidemseries:writeIncremental terms for a volume (merged into the series glossary)
POST/series/{id}/volumes/{volume_id}/translateidemseries:writeTranslate a volume with the series worldview and frozen glossary version
PATCH/series/{id}/worldviewidemseries:writeRevise the series worldview
POST/webhook_endpointsidemwebhooks:writeRegister a webhook endpoint (secret shown once)
GET/webhook_endpointswebhooks:writeList webhook endpoints
GET/webhook_endpoints/{id}webhooks:writeEndpoint with recent deliveries
PATCH/webhook_endpoints/{id}webhooks:writeUpdate / re-enable an endpoint
DELETE/webhook_endpoints/{id}webhooks:writeDelete an endpoint
POST/webhook_endpoints/{id}/testwebhooks:writeSend a signed test event
GET/eventsjobs:readEvents of the last 30 days (catch up on missed webhooks)
GET/events/{id}jobs:readGet one event

错误码

错误使用 RFC 9457 problem+json(Content-Type: application/problem+json)。请依据稳定的 code 字段分支处理,不要依赖 title 或 detail 文本。每个响应都带 request_id,联系客服时请提供。

示例

HTTP/1.1 402 Payment Required
Content-Type: application/problem+json

{
  "type": "https://novotranslator.com/api-docs#error-INSUFFICIENT_CREDITS",
  "title": "Insufficient credits",
  "status": 402,
  "code": "INSUFFICIENT_CREDITS",
  "detail": "This job needs 120345 credits; 5000 available.",
  "param": null,
  "request_id": "req_...",
  "doc_url": "https://novotranslator.com/api-docs#error-INSUFFICIENT_CREDITS"
}
错误码HTTP标题可重试处理方式
INVALID_REQUEST400Invalid request否按 detail 修正请求体或参数。
INVALID_PARAMETER400Invalid parameter否修正 param 指出的字段。
UNSUPPORTED_FILE_FORMAT400Unsupported file format否改传 .txt / .epub / .docx。
UNSUPPORTED_LANGUAGE_PAIR400Unsupported language pair否选择受支持的语言对。
NO_TRANSLATABLE_CONTENT400No translatable content否源文件没有可翻译文本。
IDEMPOTENCY_KEY_REQUIRED400Idempotency-Key required否每个写请求都要带唯一的 Idempotency-Key 头。
IDEMPOTENCY_KEY_INVALID400Invalid Idempotency-Key否使用 1-200 个不含空白的可见字符。
API_KEY_MISSING401API key missing否请求头带上 Authorization: Bearer <key>。
API_KEY_INVALID401API key invalid否检查 key,或在开发者控制台新建。
API_KEY_REVOKED401API key revoked否改用未吊销的 key。
API_KEY_EXPIRED401API key expired否轮换或新建 key。
INSUFFICIENT_SCOPE403Insufficient scope否给 key 授予 meta.required_scope 所列权限。
IP_NOT_ALLOWED403IP not allowed否从白名单 IP 调用,或修改 key 设置。
ACCOUNT_SUSPENDED403Account suspended否联系客服。
BROWSER_ORIGIN_FORBIDDEN403Browser calls forbidden否从你的服务器调用,不要把 key 放进浏览器。
KEY_ISSUANCE_REQUIRES_BALANCE403Credits required否先充值积分再申请 key。
INSUFFICIENT_CREDITS402Insufficient credits否充值积分(meta.top_up_url)后重试。
KEY_SPEND_LIMIT_REACHED402Key spend limit reached否提高 key 月度上限或等下月。
RESOURCE_NOT_FOUND404Not found否检查 ID;其他账号的对象不可见。
ENDPOINT_REPLACED410Endpoint replaced否试点接口已替换,见 doc_url 中的迁移对照表。
IDEMPOTENCY_KEY_MISMATCH409Idempotency-Key reused否请求体不同时请换新的幂等键。
IDEMPOTENCY_IN_PROGRESS409Request in progress是几秒后用同一个幂等键重试。
QUOTE_EXPIRED_OR_CHANGED409Quote expired or changed否重新报价。
SOURCE_LANGUAGE_CONFIRMATION_REQUIRED409Confirm source language否带 confirm_source_language=true 重新提交。
SOURCE_NOT_READY409Source not ready是等源文件 status 变为 ready。
SOURCE_EXPIRED409Source expired否重新上传源文件。
JOB_NOT_CANCELLABLE409Job not cancellable否只有 queued 状态的任务能取消。
VERSION_CONFLICT409Version conflict否重新读取后用新的 If-Match 提交。
PAYLOAD_TOO_LARGE413Payload too large否减小上传体积。
GLOSSARY_INVALID422Glossary invalid否修正术语表词条。
SCOPE_INVALID422Scope invalid否使用 0 ≤ start_percent < end_percent ≤ 100。
STYLE_GUIDE_TOO_LONG422Style guide too long否style_guide 不超过 500 字。
RATE_LIMITED429Rate limited是等待 Retry-After 秒后重试。
QUEUE_LIMIT_EXCEEDED429Queue limit exceeded是等待排队任务开始执行。
DAILY_QUOTA_EXCEEDED429Daily quota exceeded是UTC 零点后重试。
INTERNAL_ERROR500Internal error是重试;持续出现请附 request_id 联系我们。
UPSTREAM_UNAVAILABLE502Upstream unavailable是退避后重试。
SERVICE_UNAVAILABLE503Service unavailable是退避后重试。

从试点版迁移

试点期 /tasks 下的接口已原地替换,现在返回 410 ENDPOINT_REPLACED。现有试点密钥继续可用并拥有 v1 的全部权限;在控制台轮换即可获得 v1 密钥。

试点版API v1
POST /tasksPOST /sources + POST /quotes + POST /jobs
GET /tasks/{id}GET /jobs/{id}
GET /tasks/{id}/downloadGET /jobs/{id}/files/{file_id}
GET /usage(试点格式)GET /usage:按天的用量列表,见 OpenAPI 文档
  • 响应封装:试点版把一切包在 {success, data} 里;v1 成功时直接返回资源本身,失败时返回 problem+json。
  • 所有写请求现在都必须带 Idempotency-Key 头。
  • 价格与积分:计量单位不变(积分),但创建任务前可以先获取报价。

更新日志

  • 2026-10v1 GA(与试点版不兼容)。新增 sources、quotes、jobs、glossaries、series、webhooks、events 和开发者控制台。