SERP API
POST /api/serp 运行 Google 搜索并将结果页面作为 JSON 返回:自然搜索结果及其指向的地址、Google AI Overview、广告以及页面上的其他模块。您的套餐按搜索次数计费,而非点数,失败的搜索不计费。
请求
POST https://eu.api.foura.ai/api/serp
在 X-API-Key header 中发送您的 API key,这与其他 endpoint 使用的 key 相同。参见 身份验证。
curl -X POST https://eu.api.foura.ai/api/serp \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
--max-time 90 \
-d '{"q": "coffee grinder", "country": "us", "language": "en", "timeout_ms": 85000}'
--max-time 90 和 timeout_ms: 85000 遵循 计时和超时 中的建议。查询的首次搜索需要几十秒,因此请同时设置两者。
Request 字段
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
q |
string | 是 | - | 搜索词,按在 Google 中输入的方式填写,包含运算符(site:、引号、after:)。1 到 2,048 个字符。别名:query。 |
country |
string | 否 | us |
两位国家代码(ISO 3166-1),不区分大小写。搜索会从该国家发起,Google 接收到的代码为 gl。英国可接受 uk,返回为 gb。别名:gl。 |
language |
string | 否 | en |
语言代码,例如 en、de 或 pt-BR,作为 hl 发送给 Google。别名:hl。 |
page |
integer | 否 | 1 |
结果的第几页,1 到 10。第 2 页从第 11 条结果开始。 |
filter |
integer | 否 | 1 |
Google 的相似结果过滤。1 会隐藏与已展示内容高度相似的结果,与 Google 默认行为一致。0 会包含这些结果,通常能获取到 1 返回为空的页面。"0" 和 "1" 也支持字符串格式。 |
freshness |
string | 否 | - | 仅返回过去 hour、day、week、month 或 year 内的结果。 |
verbatim |
boolean | 否 | false |
完全按输入的字词搜索(Google 的精准匹配模式)。别名:strictQuery。 |
tbs |
string | 否 | - | Google 原生 tbs 代码,例如 qdr:w2、li:1 或日期范围 cdr:1,cd_min:1/1/2026,cd_max:1/31/2026(月/日/年),会与 freshness 和 verbatim 合并。仅限字母、数字以及 _ : . , - /,最多 200 个字符。 |
surface |
string | 否 | all |
all 为 Google 的“全部”标签页。web 为 Google 的“网页”标签页,仅包含自然搜索结果和广告。 |
udm |
string | 否 | - | Google 的视图编号,作为 udm 发送,例如 14。会覆盖 surface。也可使用数字。 |
timeout_ms |
integer | 否 | 120000 |
整个搜索的时间预算,单位为毫秒,30000 到 170000。 |
ai_overview |
boolean | 否 | true |
当页面存在 Google AI Overview 时予以返回。false 会排除该内容,在 Google 延迟加载概览的页面上可节省数秒。search_information.ai_overview_state 仍会返回。 |
html |
boolean | 否 | false |
同时在 html 中返回 Google 提供的原始结果页面。 |
boost |
integer | 否 | 1 |
2 能更快获取结果地址,计为两次搜索。1 计为一次。参见 What Counts as a Search。 |
exitState |
string | 否 | - | 将发起搜索的位置限制在 country 的某个地区。 |
exitCity |
string | 否 | - | 将发起搜索的位置限制在 country 的某个城市。 |
exitAsn |
string | 否 | - | 按 AS 编号将发起搜索的位置限制在某个网络,仅填数字(例如 8866)。也可使用数字格式。 |
exitOs |
string | 否 | - | 发起搜索的设备类型:windows、android、ios 或 mac。 |
exitState 与 exitCity 各接受一个词(字母、数字、_ 或 .),即 Playground 的 SERP 标签页中为每个国家/地区列出的相同词汇。如果 FourA 无法从您指定的位置发起搜索,则搜索失败且不计入用量。
API 无法识别的字段将被忽略。当您同时发送名称及其别名时(例如 q 和 query),以名称为准。
Google 无法组合的控制项
Google 仅能单独应用精准搜索或时间筛选条件,无法同时生效。当您同时请求两者时(verbatim 或 li:1,搭配 freshness 或 qdr: 代码),时间筛选条件会作为 after:<date> 放入查询中传递,按从今天(UTC)倒推的完整天数计算。search_parameters.google_q 会显示 Google 实际接收到的查询。
以下组合将被直接拒绝并返回 400 错误,而不是静默丢弃某个控制项:
- 精准搜索搭配过去一小时(
freshness: "hour"或qdr:h),因为该项没有日期形式。 - 精准搜索同时搭配两个时间筛选条件。
- 在已包含
after:的查询中,将精准搜索与时间筛选条件搭配使用。 - 精准搜索搭配日期范围(
cdr:1搭配cd_min或cd_max)。 - 日期范围搭配另一个时间筛选条件(
freshness或qdr:代码)。
响应
/api/serp 响应的 HTTP 状态代表搜索结果:成功返回内容为 200,其余情况返回错误自身的状态码(参见 错误)。响应体中的 status 始终携带相同的状态码数值。Single、Proxy 和 Auto 的机制不同:它们均返回 HTTP 200,并在响应体中传递处理结果。
{
"status": 200,
"search_parameters": {
"q": "coffee grinder",
"country": "us",
"language": "en",
"page": 1,
"filter": 1,
"boost": 1
},
"search_metadata": {
"id": "8f3e2a14-7b6c-4d1a-9e2f-5a3b8c1d4e7f",
"took_ms": 54210,
"session": "reused",
"attempts": 1,
"credits": 0,
"google_url": "https://www.google.com/search?q=coffee+grinder&hl=en&gl=us"
},
"search_information": {
"organic_results_state": "results",
"next_page": 2,
"google_has_next": true,
"end_reason": null,
"omitted_similar_results": false,
"links_unresolved": 0,
"ai_overview_state": "present"
},
"ai_overview": {
"text_blocks": [
{
"type": "paragraph",
"text": "A burr grinder crushes beans between two plates, which gives a more even grind than a blade grinder.",
"citations": [
{
"source": "Example Coffee",
"link": "https://www.example.org/burr-vs-blade",
"redirect_link": "https://www.google.com/...",
"more_sources": 0,
"sources": [
{
"source": "Example Coffee",
"title": "Burr vs. Blade Grinders",
"snippet": "...",
"link": "https://www.example.org/burr-vs-blade",
"redirect_link": "https://www.google.com/...",
"cited": true
}
],
"sources_complete": true
}
]
}
],
"sources": [
{
"source": "Example Coffee",
"title": "Burr vs. Blade Grinders",
"snippet": "...",
"link": "https://www.example.org/burr-vs-blade",
"redirect_link": "https://www.google.com/...",
"cited": true
}
],
"citations_complete": true,
"truncated": false,
"loaded": "in_page",
"links_unresolved": 0
},
"organic_results": [
{
"position": 1,
"title": "The Best Coffee Grinders, Tested",
"link": "https://www.example.com/reviews/coffee-grinders",
"redirect_link": "https://www.google.com/...",
"displayed_link": "https://www.example.com › reviews › coffee-grinders",
"source": "Example Reviews",
"snippet": "We ground the same beans in 20 burr and blade grinders ...",
"date": "Oct 14, 2026",
"page_position": 1
}
],
"ads": [],
"shopping_ads": [],
"related_searches": ["best burr coffee grinder", "coffee grinder for espresso"],
"people_also_ask": ["Is a burr grinder worth it?"],
"local_results": [],
"knowledge_graph": null,
"top_stories": []
}
顶级字段
| 字段 | 类型 | 说明 |
|---|---|---|
status |
integer | 成功响应为 200。HTTP 状态码包含相同数值。 |
search_parameters |
object | 实际应用的请求内容。始终包含 q、country、language、page、filter 和 boost;与默认值不同时包含 freshness、verbatim、surface 和 ai_overview;传入时包含四个位置字段;由您的控制参数生成时包含 tbs、udm 和 google_q。boost 是您发送的值,方便您核对每项搜索。 |
search_metadata |
object | id 为请求 ID,与 X-FourA-Request-Id 响应头一致。took_ms 为搜索耗时。google_url 为请求映射到的 Google 搜索。session(reused、new 或 none)与 attempts 供技术支持使用。credits 为 0,与 X-FourA-Credits 响应头一致,因为搜索以搜索次数计费。 |
search_information |
object | 当前结果页的相关信息。参见 Search Information。 |
organic_results |
array | 结果列表,按 Google 原序排列。当 Google 未找到结果或响应了其他查询时为空。参见 Organic Result。 |
rewritten_query_results |
array | 仅当 Google 响应了不同于您输入的查询时出现。包含 Google 为该替代查询展示的条目,这些并非您查询的结果。 |
ai_overview |
object | Google 的 AI Overview,在页面包含且您未传入 ai_overview: false 时提供。参见 AI Overview。 |
ads |
array | 搜索结果上方和下方的文字广告。 |
shopping_ads |
array | 购物广告。 |
related_searches |
string[] | Google 在页面底部推荐的相关搜索。 |
people_also_ask |
string[] | "大家还在问" 下的问题。Google 在点击时才加载其答案,因此页面本身不包含对应内容。 |
local_results |
array | 本地搜索结果中的地点信息。 |
knowledge_graph |
object or null | 知识面板,页面无对应内容时为 null。 |
top_stories |
array | 焦点新闻。 |
html |
string | 配合 html: true 使用时,提供 Google 返回的原始结果页面。 |
ai_overview_html |
string | 配合 html: true 使用时,提供 Google 在页面加载后延迟获取的 AI Overview 标记内容。 |
当 Google 响应不同于您所请求的查询时,ai_overview 以及从 ads 到 top_stories 的数据块会被省略,因为它们对应的是该替代查询。
搜索信息
| 字段 | 类型 | 说明 |
|---|---|---|
organic_results_state |
string | results 或 empty。状态码为 200 的空白页面是 Google 的正常响应,并非失败。 |
next_page |
integer 或 null | 此 API 提供的下一页:将其作为 page 传递。不存在下一页时为 null,end_reason 会说明原因。 |
google_has_next |
boolean | Google 页面包含下一页的链接。 |
end_reason |
string 或 null | 当设置了 next_page 时为 null。page_limit:第 10 页是此 API 提供的最后一页,即使 Google 链接了更多页面。no_next_link:Google 未显示下一页链接,但这并不一定代表到达末尾,因此请求下一页可能仍会返回结果。query_rewritten:Google 回答了另一个查询。 |
omitted_similar_results |
boolean | Google 省略了与已显示结果高度相似的内容。发送 filter: 0 以包含它们。 |
organic_results_tab |
string | 当你请求“全部”标签页但自然结果来自 Google 的“网页”标签页时为 web:出现在第 2 到 10 页、site: 查询以及“全部”标签页列表与“网页”标签页不同的第一页上。在第一页上,所有其他内容仍来自“全部”标签页。其他情况下不存在。 |
links_unresolved |
integer | 无法找到目标地址的自然搜索结果。其 link 为 null。 |
ai_overview_state |
string | present;pending(Google 在页面加载后加载概览,且此响应不包含该内容);unavailable(Google 表示没有可用的概览);absent(Google 未提供任何内容);rewritten_query(概览回答的是 answered_query,因此未提供)。 |
query_rewritten |
boolean | 当 Google 回答了另一个查询(例如去除了引号的查询或拼写更正后的查询)时为 true。 |
answered_query |
string | Google 实际回答的替代查询,与 query_rewritten 一同提供。 |
site_scope |
object | 在 site: 查询中:sites(请求的站点)、in_scope、out_of_scope 以及 unknown(按目标跳转位置划分的自然结果),以及 retried_on_fresh_session(由于结果指向站点外部,搜索再次运行)。 |
自然结果
| 字段 | 类型 | 说明 |
|---|---|---|
position |
integer | 在整个搜索中的位置:(page - 1) x 10 + page_position。 |
page_position |
integer | 在本页上的位置,从 1 开始。 |
title |
string | 结果标题。 |
link |
string or null | 结果指向的地址。无法找到时为 null,计入 links_unresolved。 |
redirect_link |
string | 结果在 Google 页面上的地址,属于 Google 重定向。 |
displayed_link |
string or null | Google 显示的地址,例如 https://www.example.com › reviews。 |
source |
string or null | Google 显示的网站名称。 |
snippet |
string or null | 标题下方的文本。 |
date |
string or null | Google 显示的日期或发布时间,例如 Apr 28, 2026 或 3 days ago,完全按显示内容及页面语言呈现。绝不猜测。 |
missing_terms |
string[] | 当 Google 提示结果不包含某些词时存在:显示这些词。 |
in_scope |
boolean or null | 在 site: 查询中:link 是否指向所请求的网站内部。当 link 为 null 时为 null。 |
AI 概览
| 字段 | 类型 | 说明 |
|---|---|---|
text_blocks |
array | 按顺序排列的回答。每个块包含 type(paragraph、heading 或 list),段落或标题使用 text,列表使用 items。citations 列出块内的来源标签,列表还会增加 item_citations,即每个项目专属的标签。 |
sources |
array | 回答的所有来源:source、title、snippet、link、redirect_link,以及在回答中的标签引用它时的 cited: true。 |
product_cards |
array | 回答中的产品卡片(source、title、snippet)。它们不包含地址,因此不在 sources 中。 |
citations_complete |
boolean | 当标签统计的来源数多于页面承载的数量时为 false。 |
truncated |
boolean | 页面中仅包含回答的开头部分。 |
loaded |
string | in_page,或者当 Google 在页面加载后填入概览时为 async。 |
links_unresolved |
integer | 无法找到目标的来源和引用数量。 |
引用包含 source、link、redirect_link、more_sources(标签上的 "+N")、sources(标签代表的每个来源,均同时存在于 ai_overview.sources)以及 sources_complete。
其他区块
| 区块 | 字段 |
|---|---|
ads |
position (在其区块的广告中,从 1 开始), block (top 或 bottom), title, advertiser, displayed_link, domain, link (广告所到达的页面,按广告所带内容,或 null), description, sitelinks (每个均包含 title, description, link) |
shopping_ads |
position, price, merchant, domain |
local_results |
position, title, rating (数字), reviews (按显示内容), details (名称下方的行:类型、地址、营业时间), place_id |
knowledge_graph |
title, subtitle, description, attributes (每个均包含 key, label, value) |
top_stories |
position, title, source, published_at (Unix 秒), link, redirect_link |
FourA 从页面读取广告和购物广告,绝不访问其链接。购物广告没有商品名称或着陆页地址,因为页面未包含这些内容。
结果分页
每个页面都是一次独立的搜索,并单独计费。跟随 search_information.next_page 直至其为 null:
import requests
API = "https://eu.api.foura.ai/api/serp"
H = {"X-API-Key": "YOUR_API_KEY", "Content-Type": "application/json"}
page = 1
while page:
r = requests.post(API, headers=H, timeout=90, json={
"q": "coffee grinder",
"country": "us",
"page": page,
"timeout_ms": 85000,
})
body = r.json()
if r.status_code != 200:
print(page, r.status_code, body.get("error"))
break
for row in body["organic_results"]:
print(row["position"], row["link"] or row["redirect_link"], row["title"])
page = body["search_information"]["next_page"]
使用 filter: 1 时,许多查询在几页后便不再返回结果。需要更深页面的结果时,请发送 filter: 0。
计入搜索的条件
搜索在我们返回响应时计费,或者在请求到达 Google 后由您主动关闭连接时计费。携带 boost: 2 发送的搜索按两次计算。
- **计入:**返回 HTTP 200 的响应,包括无结果的响应以及 Google 针对其他查询返回结果的情况。
- **计入:**请求到达 Google 后且在
timeout_ms耗尽前,由您主动关闭连接退出的搜索。 - **不计入:**失败的搜索(任何 4xx 或 5xx),包括因套餐额度限制而被拒绝的请求,以及因
timeout_ms耗尽而由 FourA 终止的搜索。 - **
boost:**只要计费,boost: 2每次均按两次搜索计算,无论响应速度多快。boost: 1或未设置boost则计为一次。boost: 3会被拒绝并返回 400。
搜索不会消耗套餐中的其他任何资源:不消耗点数,也不消耗流量。Billing 中的 Searches this period 卡片会显示已用额度,Overview、Metrics 和 Activity 中的 SERP 开关可查看您的搜索记录。
套餐、加油包与限制
公开套餐每月包含的搜索次数如下:
| 套餐 | 每月包含的搜索次数 |
|---|---|
| Free | 100 |
| Developer | 1,000 |
| Startup | 10,000 |
| Business | 30,000 |
额外搜索额度以 1,000 次为单位打包提供,价格取决于您的套餐(参见 Pricing)。可通过 Billing > Plan & Usage 下 Searches this period 卡片上的 Buy searches 进行购买。加油包有效期为 12 个月,并显示在 Top-ups 列表中。每月优先扣除套餐自带的搜索额度,超出部分才会消耗加油包。Automatic Top-Up 也可以购买搜索额度。Free 套餐不提供加油包购买。详情请参阅 Billing & Subscriptions。
搜索额度用尽后,新的搜索请求将被拒绝并返回 429,直到下个月额度刷新或您购买更多额度。已经在运行的搜索会继续执行并计费。
套餐还会限制同时运行的搜索数以及每分钟发起的搜索数。搜索使用套餐为 Browser 请求设置的并发数上限,以及为 Single 请求设置的每分钟请求数上限,但额度与这些请求分开计算。各项套餐的具体数值请参阅 Pricing。
耗时与超时
针对某个查询的首次搜索目前通常需要约 50 到 70 秒。使用 boost: 2 时,约半数请求可在 25 秒内完成。在一天内重复搜索的查询返回速度通常更快。这些是当前的参考数值,不构成保证。
请设置至少 90 秒的客户端超时时间,并发送 timeout_ms: 85000。默认的 timeout_ms 为 120000,长于 90 秒的客户端超时时间,因此请每次都主动发送该参数。
将 timeout_ms 设置为比客户端自身超时短几秒。因 timeout_ms 耗尽而由 FourA 终止的搜索不收取任何费用。而在请求到达 Google 后由客户端放弃的搜索仍会计费。
在 Playground 中体验
控制台的 Playground 包含一个 SERP 标签页,它会发送本页上的所有字段并显示该 request 的 curl。boost 在该页面默认开启,因此一次 Playground 搜索计为两次。
错误
首先读取 HTTP 状态码。失败的搜索还会在 body 中携带 status 和 error,数值相同;而在开始后失败的搜索还会返回 search_parameters(以及 search_metadata,500 错误除外)。搜索开始前的拒绝(缺少或无效的 key、套餐限制)会携带 error 且不带 status,而 413 响应不是 JSON。这些均不计为一次搜索。
| 状态码 | 含义 |
|---|---|
| 400 | 字段验证失败,或所选控件无法组合使用。error 会指出具体字段:<field>: <reason>。 |
| 401 | 缺少 API key 或 key 无效。 |
| 413 | JSON request body 超过 100 KB。 |
429 带 X-FourA-Limit |
达到套餐限制:月度搜索量、并发搜索量或每分钟搜索量。 |
429 不带 X-FourA-Limit |
Google 拒绝了此搜索。请重试。 |
| 500 | 我们系统内部出现问题。请重试。 |
| 502 | 大部分结果链接无法追踪,或搜索在时限内未从 Google 获取到结果页面。请重试。 |
| 503 | FourA 暂时无法处理该搜索。若设置了 Retry-After,请在其后重试。 |
| 504 | Upstream timeout:搜索未在时限内完成。请重试。 |
搜索 body 中返回的其他 4xx 或 5xx 是 Google 响应的状态码。请稍后重试。
400 示例
{ "status": 400, "error": "boost: boost must be 1 or 2" }
{ "status": 400, "error": "page: Too big: expected number to be <=10" }
{ "status": 400, "error": "country: country must be a two-letter code (ISO 3166-1), e.g. us, de" }
{ "status": 400, "error": "Google cannot combine verbatim with the past hour: ask for verbatim, or for the past hour, or freshness \"day\"" }
来自套餐的 429
套餐限额会设置 X-FourA-Limit 和 Retry-After,且响应 body 的结构如 Rate Limits 中所述,不包含 status 字段:
{
"error": "Search limit reached: 1,000 of 1,000 searches used this billing period. Buy more or wait for the next period.",
"reason": "plan_limit_serp",
"documentation": "https://foura.ai/prices",
"used": 1000,
"allowance": 1000,
"retry_after_seconds": 86400,
"resets_at": "2026-12-14T09:12:00.000Z"
}
reason |
拒绝原因 | 附加字段 | 解决方案 |
|---|---|---|---|
plan_limit_serp |
本月搜索配额已用完。未包含配额的套餐显示为 Your plan includes no searches. Buy searches or upgrade to search. |
used, allowance, retry_after_seconds, resets_at |
购买资源包,升级套餐,或等待 resets_at。 |
plan_limit_concurrency |
当前运行的搜索数已达到套餐上限。 | limit, in_flight, retry_after_seconds |
减少同时进行的搜索数量。 |
plan_limit_rate |
套餐每分钟搜索次数已耗尽。 | limit_per_minute, current_rate, retry_after_seconds |
等待 Retry-After,然后降低请求频率。 |
502:无法访问结果链接
当页面中的大部分结果链接无法访问时,搜索将直接失败,而不是返回无法打开的数据行:
{
"status": 502,
"error": "Google's result links could not be followed (6 of 10); ask again",
"search_parameters": { "q": "coffee grinder", "country": "us", "language": "en", "page": 1, "filter": 1, "boost": 1 },
"search_metadata": { "id": "...", "took_ms": 81240, "session": "new", "attempts": 1, "credits": 0, "google_url": "https://www.google.com/search?q=coffee+grinder&hl=en&gl=us" }
}
当仅缺少少数链接时,搜索即有结果:这些行包含 link: null,且 search_information.links_unresolved 会对它们进行计数。