# 引用检索

> 草案

`GET https://paperpurr.com/v1/citations/lookup`

按 DOI、arXiv 编号、网址或标题查找文献，返回可以直接写进参考文献的书目信息。

## 查询参数

- `query` (string，必填) — DOI、arXiv 编号、网址，或 2–300 个字的标题 / 引用文字。整个参数最长 2048 个字符。

| 填什么 | 怎么查 |
| --- | --- |
| DOI（`10.` 开头，或 `doi.org` 链接） | 先查 Crossref，没有再查 OpenAlex |
| arXiv 编号或 `arxiv.org` 链接 | arXiv |
| 其他网址 | 读取页面的书目元数据 |
| 标题或引用文字 | 同时查 Crossref 和 OpenAlex，按匹配程度排序 |

## 请求示例

curl:

```bash
curl "https://paperpurr.com/v1/citations/lookup?query=Attention%20Is%20All%20You%20Need" \
  -H "Authorization: Bearer $PAPERPURR_API_KEY"
```

Python:

```python
import os
import requests

r = requests.get(
    "https://paperpurr.com/v1/citations/lookup",
    headers={"Authorization": f"Bearer {os.environ['PAPERPURR_API_KEY']}"},
    params={
        "query": "Attention Is All You Need"
    },
)
print(r.json())
```

JS:

```javascript
const r = await fetch("https://paperpurr.com/v1/citations/lookup?query=Attention%20Is%20All%20You%20Need", {
  headers: {
    Authorization: `Bearer ${process.env.PAPERPURR_API_KEY}`,
  },
});
console.log(await r.json());
```

## 响应

```json
{
  "results": [
    {
      "title": "Attention Is All You Need",
      "authors": [
        "Ashish Vaswani",
        "Noam Shazeer",
        "Niki Parmar"
      ],
      "year": 2017,
      "venue": "Advances in Neural Information Processing Systems",
      "doi": "10.48550/arXiv.1706.03762",
      "url": "https://arxiv.org/abs/1706.03762",
      "source": "arxiv"
    }
  ],
  "usage": {
    "units": 1,
    "remaining": 498
  },
  "request_id": "req_c40a7e1932bd5f08a4e6c71d"
}
```

- `results` (object[]，必填) — 最多 8 条，按匹配程度排序；没查到时是空数组。
  - `title` (string，必填) — 标题
  - `authors` (string[]，必填) — 作者，最多 50 位
  - `year` (integer | null，必填) — 出版年份，不知道时是 `null`
  - `venue` (string，必填) — 期刊、会议或出版方
  - `doi` (string，必填) — DOI，没有时是空字符串
  - `url` (string，必填) — 链接
  - `source` (string，必填) — 书目来源：`crossref`、`openalex`、`arxiv` 或 `web`
- `usage.units` (integer，必填) — 这次计的单位，固定为 1
- `usage.remaining` (integer，必填) — 扣完后本月剩余的试用单位
- `request_id` (string，必填) — 请求 ID

## 可能的错误

| 状态码 | code | 原因 | 怎么处理 |
| --- | --- | --- | --- |
| `400` | `missing_parameter` | 缺少必填参数，`param` 指出是哪个 | 补上这个参数 |
| `400` | `invalid_parameter` | 参数格式或取值不对，`param` 指出是哪个 | 按接口文档的类型和范围改 |
| `400` | `unknown_parameter` | 传了接口不认识的参数（查询参数或请求体字段） | 删掉它，或检查拼写 |
| `400` | `url_blocked` | 检索的网址不允许抓取（内网、本机等地址） | 改用 DOI、arXiv 编号或标题 |
| `402` | `insufficient_balance` | 本月试用额度不够这次请求要用的单位 | 查 `/v1/usage`，减少条数或等下个月重置；词数包发布时开卖 |
| `429` | `rate_limit_exceeded` | 撞上了某一层限流（按 IP、按密钥或按账号），`message` 说明是哪一层 | 按 `Retry-After` 的秒数等待后重试；多个进程共用一把密钥时把请求排队 |
| `502` | `upstream_unavailable` | Crossref、OpenAlex、arXiv 都没查成 | 稍后重试，这次不计费 |
| `503` | `busy` | 服务繁忙；计量暂时写不进去时，计费调用也回它，不会扣费 | 退避后重试 |

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

## 计量

- 每次成功的检索计 1 单位，没查到结果也计；上游都没响应（`502`）时不计。
- 只发送你填的 `query`，不需要上传论文正文。

下一页: [参考文献核验](https://paperpurr.com/docs/verify.md)
