# 参考文献核验

> 草案

`POST https://paperpurr.com/v1/citations/verify`

把参考文献逐条和 Crossref、OpenAlex 的书目比对，标出一致、有出入或没找到。

## 请求参数

- `references` (string[]，必填) — 1–20 条，每条是一整条参考文献、最多 2000 个字符。格式不限（APA、MLA、IEEE、GB/T 7714 等）。

## 请求示例

curl:

```bash
curl -X POST "https://paperpurr.com/v1/citations/verify" \
  -H "Authorization: Bearer $PAPERPURR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"references":["Smith, J. (2020). Title. Journal, 12(3), 45-67.","Lee, K. (2018). Writing with sources. Academic Press.","张三. 学术写作导论[M]. 北京: 高等教育出版社, 2019."]}'
```

Python:

```python
import os
import requests

r = requests.post(
    "https://paperpurr.com/v1/citations/verify",
    headers={"Authorization": f"Bearer {os.environ['PAPERPURR_API_KEY']}"},
    json={
        "references": [
            "Smith, J. (2020). Title. Journal, 12(3), 45-67.",
            "Lee, K. (2018). Writing with sources. Academic Press.",
            "张三. 学术写作导论[M]. 北京: 高等教育出版社, 2019."
        ]
    },
)
print(r.json())
```

JS:

```javascript
const r = await fetch("https://paperpurr.com/v1/citations/verify", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.PAPERPURR_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "references": [
      "Smith, J. (2020). Title. Journal, 12(3), 45-67.",
      "Lee, K. (2018). Writing with sources. Academic Press.",
      "张三. 学术写作导论[M]. 北京: 高等教育出版社, 2019."
    ]
  }),
});
console.log(await r.json());
```

## 响应

200:

```json
{
  "results": [
    {
      "index": 0,
      "status": "matched",
      "match": {
        "title": "Title",
        "authors": [
          "J. Smith"
        ],
        "year": 2020,
        "venue": "Journal",
        "doi": "10.1234/journal.2020.045",
        "url": "https://doi.org/10.1234/journal.2020.045",
        "source": "crossref"
      }
    },
    {
      "index": 1,
      "status": "mismatch",
      "diffs": [
        {
          "field": "year",
          "ours": "2018",
          "found": "2019"
        }
      ],
      "match": {
        "title": "Writing with Sources",
        "authors": [
          "K. Lee"
        ],
        "year": 2019,
        "venue": "Academic Press",
        "doi": "10.5555/wws.2019",
        "url": "https://doi.org/10.5555/wws.2019",
        "source": "crossref"
      }
    },
    {
      "index": 2,
      "status": "skipped",
      "reason": "cjk"
    }
  ],
  "usage": {
    "units": 2,
    "remaining": 495
  },
  "request_id": "req_51d0c8aa3e9f4b2c7d16a0e8"
}
```

400:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_parameter",
    "message": "references 要是非空的字符串数组",
    "param": "references",
    "request_id": "req_6a2f90d4e1b7c3a85d02f9e4"
  }
}
```

402:

```json
{
  "error": {
    "type": "billing_error",
    "code": "insufficient_balance",
    "message": "本月试用额度不足：这次需要 3 单位，剩余 2",
    "param": null,
    "request_id": "req_2c7e1f0a9b3d45e6c8a1f7d2"
  }
}
```

- `results` (object[]，必填) — 和 `references` 一一对应
  - `index` (integer，必填) — 对应第几条，从 0 开始
  - `status` (string，必填) — `matched`、`mismatch`、`not_found`、`skipped` 或 `error`，见下表
  - `reason` (string) — 只在 `skipped` 时出现：`cjk`、`web` 或 `short`
  - `diffs` (object[]) — 只在 `mismatch` 时出现：对不上的字段
    - `field` (string，必填) — `year`、`authors`、`title` 或 `doi`
    - `ours` (string) — 引用里写的
    - `found` (string) — 库里的
    - `other` (string) — 只在 `doi` 差异时出现：引用里的 DOI 实际指向的那篇的标题
  - `match` (object) — 库里最接近的一条，字段同[引用检索](https://paperpurr.com/docs/lookup)的 `results[]`
- `usage.units` (integer，必填) — 这次计的单位：实际查过的条数
- `usage.remaining` (integer，必填) — 扣完后本月剩余的试用单位
- `request_id` (string，必填) — 请求 ID

## 核验结果

| status | 含义 | 计费 |
| --- | --- | --- |
| `matched` | 和库里的书目一致 | 是 |
| `mismatch` | 找到了，但年份、作者、标题或 DOI 有出入，见 `diffs` | 是 |
| `not_found` | 在 Crossref、OpenAlex 都没找到 | 是 |
| `skipped` | 没有核验，原因见 `reason` | 否 |
| `error` | 这一条没查成，可以单独重试 | 否 |

| reason | 含义 |
| --- | --- |
| `cjk` | 中文、日文、韩文条目。这两个库对它们覆盖不全，暂时不核验 |
| `web` | 网页类条目，书目信息太少 |
| `short` | 太短，不像一条完整的参考文献（比如空行、小标题） |

## 可能的错误

| 状态码 | code | 原因 | 怎么处理 |
| --- | --- | --- | --- |
| `400` | `missing_parameter` | 缺少必填参数，`param` 指出是哪个 | 补上这个参数 |
| `400` | `invalid_parameter` | 参数格式或取值不对，`param` 指出是哪个 | 按接口文档的类型和范围改 |
| `400` | `unknown_parameter` | 传了接口不认识的参数（查询参数或请求体字段） | 删掉它，或检查拼写 |
| `400` | `invalid_json` | 请求体不是 JSON 对象 | 用 `Content-Type: application/json` 发送一个对象 |
| `413` | `too_many_references` | `references` 超过 20 条 | 拆成每批最多 20 条 |
| `413` | `body_too_large` | 请求体太大 | 减少条数或缩短内容 |
| `402` | `insufficient_balance` | 本月试用额度不够这次请求要用的单位 | 查 `/v1/usage`，减少条数或等下个月重置；词数包发布时开卖 |
| `429` | `rate_limit_exceeded` | 撞上了某一层限流（按 IP、按密钥或按账号），`message` 说明是哪一层 | 按 `Retry-After` 的秒数等待后重试；多个进程共用一把密钥时把请求排队 |
| `503` | `busy` | 服务繁忙；计量暂时写不进去时，计费调用也回它，不会扣费 | 退避后重试 |

鉴权错误见[鉴权](https://paperpurr.com/docs/auth)，完整列表见[错误码](https://paperpurr.com/docs/errors)。

## 计量

- 按实际查过的条数计：`matched`、`mismatch`、`not_found` 各 1 单位，`skipped` 和 `error` 不计。
- 提交前按条数预占额度：本月剩余不够这一批的条数时整批返回 `402`，不会只核验一部分；查完按实际条数结算。
- 只发送你列出的条目，不需要上传论文正文。

下一页: [用量与余额](https://paperpurr.com/docs/usage.md)
