
Perplexity Time Machine API 怎么用?按指定日期查网页历史快照
普通搜索能筛「这篇文章是什么时候发的」,但网页后来改过,搜索引擎返回的仍可能是新内容。Perplexity Time Machine 解决的是另一个问题:以某个历史时间为截止点,搜索当时可以看到的内容,而不是把今天的网页按日期排序。 可以用它复盘产品公告、对照旧文档,或避免测试智能体时读到事后信息。
这篇讲的是 Perplexity 的 Search API 和 Context API,不是 Perplexity 网页搜索框中的日期筛选。
三种需求,不要用错参数
| 你要做什么 | 用什么 |
|---|---|
| 找某段时间发布的文章 | Search API 日期过滤 |
| 找某个时间点以前的页面版本 | Search API 的 snapshot_as_of |
| 读取找到的页面当时的正文 | 将 URL 交给 Context API,并传入同一个 snapshot_as_of |
快照时间指 Perplexity 保存页面副本的时间,不是页面上写的发布日期。它返回符合条件的旧副本,不保证每个网页、每个时间点都能查到。给搜索设置截止点,随后却读取当前正文,会把后来新增的信息带进复盘。

用 Python 对比现在和 30 天前的结果
需要 Perplexity API Key 和 perplexityai 0.50.0 或更新版本。通过环境变量 PERPLEXITY_API_KEY 提供自己的 Key,不要把密钥写在示例里。安装命令:
python -m pip install --upgrade 'perplexityai>=0.50.0'
下面用公开的 Python 官网测试。同一句查询先搜当前,再搜 30 天前,最后读取历史搜索里的网页。代码按官方接口示例编写;输出取决于快照覆盖,本文没有预填返回结果。
from datetime import datetime, timedelta, timezone
from perplexity import Perplexity
client = Perplexity()
cutoff = datetime.now(timezone.utc) - timedelta(days=30)
search_args = {
"query": "latest stable Python release",
"search_domain_filter": ["python.org"],
"max_results": 3,
}
current = client.search.create(**search_args)
historical = client.search.create(**search_args, snapshot_as_of=cutoff)
for label, response in (("当前搜索", current), ("历史搜索", historical)):
print(f"
{label}")
for result in response.results:
print(result.title, result.url)
if historical.results:
response = client.context.create(
urls=[result.url for result in historical.results],
snapshot_as_of=cutoff,
formats=["markdown"],
)
for result in response.results:
print(result.status.type, result.url)
if result.status.type == "ok":
if result.metadata:
print(result.metadata.title)
if result.markdown:
print(result.markdown[:800])
else:
print("截止时间前没有匹配的历史结果。")
怎么指定某一天?把 cutoff 换成 datetime.fromisoformat("2026-11-01T23:59:59+08:00"),就表示北京时间 11 月 1 日的最后一秒。日期换成你想复查的那天,且必须在最近 365 天内。做回归测试时,用固定日期,不要用随运行日期变化的「30 天前」。
怎么判断输出有用?除了标题和链接,还要检查历史正文有没有出现截止日之后才发布的信息。当前和历史两次返回同一个 URL,不代表正文也一样;也可能确实没有改过。做研究记录时,把查询词、截止时间和原始链接一起留存。
常见报错和限制
| 现象 | 怎么处理 |
|---|---|
| HTTP 400,时间格式不对 | 使用带时区的 RFC 3339 时间或带时区的 Python datetime。北京时间当天结束不能写成当天 23:59:59Z,要用 23:59:59+08:00 |
| HTTP 400,时间超范围 | 截止时间不能在未来,也不能早于 365 天前 |
| HTTP 400,同时传了日期过滤 | 历史搜索不能和 search_recency_filter、发布日期或更新时间过滤、People Search 一起用 |
历史结果比 max_results 少,或者正文返回 no_content |
不代表线上原网页不存在。记录缺少快照;需要严格历史复盘时,不要默默换成当前页面 |
| 请求过快 | 带 snapshot_as_of 的 Search 有独立限流,官方默认每秒 1 次。先用少量查询跑通,再按限流说明批量跑 |
Context 的历史快照保留正文文本,不保留原版 HTML 或链接列表;可请求 Markdown 或 highlights。想找几年以前的网页,或想看历史页面的排版,这个 API 不适合。
参考:Search API 的 Time Machine · Context API 历史正文 · AI345 Perplexity 使用指南

京ICP备2024094994号-29