语言版本: English
打开:
Settings → Local API
可以看到以下配置项:
EnabledRead-Only ModePortBase URLTrusted Folders(仅在Read-Only Mode关闭时显示)
默认端口是 29467,可配置范围是 1024 到 65535。
常见默认地址:
http://127.0.0.1:29467
API 前缀:
http://127.0.0.1:29467/api/v1
如果你修改了端口,现有客户端需要重新连接到新地址。
Read-Only Mode 默认开启。只有你的集成需要 POST /api/v1/papers 或 PUT /api/v1/papers/{id}/pdf 时才需要关闭。如果你还要通过 pdfPath 附带 PDF,请把上层目录加入 Trusted Folders。
curl http://127.0.0.1:29467/api/v1/status示例响应:
{
"ok": true,
"apiVersion": "1",
"appVersion": "1.0.0 (123)",
"capabilities": ["search", "paper-detail", "csl-item", "plugin-hosting"],
"readOnly": true,
"baseURL": "http://127.0.0.1:29467",
"browserExtensionEnabled": true
}说明:
ok为true代表服务可访问apiVersion是当前 HTTP API 版本appVersion是当前 Lattice 应用版本capabilities是当前实例支持的功能列表readOnly反映公开/api/v1API 当前的Read-Only Mode状态baseURL是客户端应使用的 localhost 基地址browserExtensionEnabled反映设置页中的 Browser Extension 开关,但这套文档仍然只关注公开的/api/v1与/plugins面
如果写入能力已开启,capabilities 里还会出现:
["create-paper", "create-paper-v2"]如果原始 PDF 字节上传也已经可用,capabilities 里还会出现:
"pdf-upload"建议规则:
- 先看
/status.capabilities,再决定是否展示写入 UI 或发送写入请求 - 把
pdf-upload视为PUT /api/v1/papers/{id}/pdf是否可用的唯一准确信号 - 不要假设所有写接口在所有机器上都可用
curl "http://127.0.0.1:29467/api/v1/search?q=graph%20neural%20network&limit=5"如果 q 为空,接口会返回最近加入文献库的条目。
拿到搜索结果中的 id 之后:
curl http://127.0.0.1:29467/api/v1/papers/550E8400-E29B-41D4-A716-446655440000该接口返回面向引用场景的完整文献快照,同时内嵌 cslItem,可直接交给 CSL 处理器。
当你的 UI 需要写入时的选择器时,可以调用:
curl http://127.0.0.1:29467/api/v1/collections
curl http://127.0.0.1:29467/api/v1/tags/collections 返回包含 id、name、path、depth 的文献集对象。
/tags 返回包含 id、name 以及可选 colorHex 的标签对象。
GET /api/v1/metadata 至少接受一个查询参数:doi、arxivId、isbn、title 中的任意一个:
curl "http://127.0.0.1:29467/api/v1/metadata?doi=10.48550/arXiv.1706.03762"
curl "http://127.0.0.1:29467/api/v1/metadata?title=Attention%20Is%20All%20You%20Need"当你的集成只有轻量标识符、但想先预填创建或替换表单时,这个端点会很有用。
如果 /status.capabilities 中包含 create-paper:
curl -X POST http://127.0.0.1:29467/api/v1/papers \
-H "Content-Type: application/json" \
-d '{
"title": "Attention Is All You Need",
"authors": "Vaswani, Ashish; Shazeer, Noam",
"year": 2017,
"doi": "10.48550/arXiv.1706.03762",
"paperType": "inproceedings",
"strategy": "skip",
"enrich": true
}'典型成功响应:
{
"id": "550E8400-E29B-41D4-A716-446655440000",
"title": "Attention Is All You Need",
"authors": "Vaswani, Ashish; Shazeer, Noam",
"year": 2017,
"doi": "10.48550/arXiv.1706.03762",
"pdfAttached": false,
"enrichmentStatus": "pending",
"warnings": [],
"alreadyExists": false,
"conflict": null
}strategy 默认值是 "skip"。
"skip"在检测到重复 DOI 或规范化标题时返回409 Conflict"replace"会更新现有文献,并返回200 OK与alreadyExists: true
POST /api/v1/papers 也接受 pdfPath,用于附带磁盘上已存在的 PDF。
使用前请先确认:
- 已关闭
Read-Only Mode - 已把该 PDF 的上层目录加入
Trusted Folders - 如果路径不在任何 Trusted Folder 内,接口仍会创建元数据文献,但会返回
pdfAttached: false和对应 warning
示例:
curl -X POST http://127.0.0.1:29467/api/v1/papers \
-H "Content-Type: application/json" \
-d '{
"title": "Attention Is All You Need",
"pdfPath": "/Users/me/Papers/attention.pdf"
}'如果 /status.capabilities 中包含 pdf-upload,则可以在文献已存在后再上传原始 PDF 字节:
curl -X PUT "http://127.0.0.1:29467/api/v1/papers/550E8400-E29B-41D4-A716-446655440000/pdf" \
-H "Content-Type: application/pdf" \
--data-binary @/Users/me/Papers/attention.pdf注意:
- 请求体必须是原始 PDF 字节,且
Content-Type必须是application/pdf - 如果该文献已经附带了 PDF,且你没有传
?force=true,接口会返回409 - 如果当前没有可用的 PDF 上传落盘目标,接口会返回
503
GET /api/v1/papers/{uuid} 返回的是 citation snapshot,不是完整的内部文献对象。
它当前不会返回:
abstractcollectionstagspdfPathpdfURLlatticeURL
这意味着:
- 如果你只需要打开 Lattice 中的该文献,可以用返回的
id自行拼出lattice://paper/{id} - 如果你需要真实 PDF 文件路径,当前 Local API 不提供
pdfPath目前只是POST /api/v1/papers的输入字段,不会被读接口回显/metadata是单独的元数据解析端点,不等同于GET /api/v1/papers/{uuid}
直接请求完整 URL:
const baseURL = "http://127.0.0.1:29467/api/v1";
const status = await fetch(`${baseURL}/status`).then((r) => r.json());如果你的前端页面由 Lattice 自己托管在 /plugins/{name}/... 下,推荐使用相对路径:
const response = await fetch("/api/v1/status");这样插件页面和 API 天然同源,不需要自己处理跨域问题。
Local API 的设计目标是“本机集成”,不是公网服务。
- 只监听本机回环地址
- 默认只允许本地浏览器来源访问
- 支持
GET、POST、PUT和OPTIONS POST /api/v1/papers与PUT /api/v1/papers/{id}/pdf都仍然需要用户手动开启公开写入能力;其中 PDF 字节上传还要求pdf-upload
这意味着:
- 远程机器无法直接访问这套 API
- 普通浏览器页面如果不在本地来源上,默认不能直接跨域访问
- 最稳妥的 Web 集成方式是直接使用
/plugins/{name}/...托管插件页面
- Lattice 是否正在运行
Enabled是否打开- 端口是否已经改动
- 你的请求地址是不是仍指向旧端口
- 如果你的宿主集成使用了 manifest、入口 URL 缓存或安装脚本,修改端口后是否已经重新生成或重新安装
- 如果
POST /api/v1/papers返回403,检查Read-Only Mode是否仍然开启 - 如果文献创建成功但
pdfAttached是false,查看warnings数组里的 Trusted Folders、文件类型或文件不存在原因 - 如果
PUT /api/v1/papers/{id}/pdf返回503,检查当前 Lattice 是否配置了可用的 PDF 上传目标