技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
serpapi-hello-world【数据与研究】Run a controlled first Google search through an official SerpAPI client and validate metadata before consuming result sections. Use when proving a new integration end to end. Trigger with "run a SerpAPI smoke test".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Prove authentication, transport, search status, and schema handling with one bounded query and a redacted receipt.
SERPAPI_KEY loaded from an approved server-side secret storeUse Read, Glob, and Grep to inspect local setup, WebFetch to verify current Google Search parameters, Write or Edit for the smoke-test code and redacted receipt, and Bash(python3:*) or Bash(npm:*) only to run the approved check.
Google Search uses engine=google and query parameter q. JSON responses expose search_metadata.status, a search ID, search parameters, and optional result sections. A successful search may legitimately contain no organic results.
Pass the private key from SERPAPI_KEY through the official client. Never interpolate it into source, logs, exceptions, fixtures, screenshots, or receipts.
location, hl, and gl values when geographic reproducibility matters.engine=google, q, and the minimum necessary parameters.search_metadata.status == "Success"; treat missing result sections as optional schema branches.Return the approved request shape, search status, result-section counts, search ID, redacted receipt location, and any schema assumptions that need fixtures.
| Condition | Response |
|---|---|
| HTTP 400 | Correct the engine-specific parameters; do not retry unchanged. |
| HTTP 401 or 403 | Stop and repair authorization without printing the key. |
| HTTP 429 | Inspect Account API before deciding whether to wait or increase allowance. |
| HTTP 5xx or timeout | Retry a bounded number of times with jitter and preserve the search ID if present. |
Success with no organic results | Inspect other documented sections and the engine-specific _state; do not label it an API failure. |
import os
import serpapi
client = serpapi.Client(api_key=os.environ["SERPAPI_KEY"], timeout=15)
result = client.search({
"engine": "google",
"q": "coffee",
"location": "Austin, Texas, United States",
"hl": "en",
"gl": "us",
})
assert result["search_metadata"]["status"] == "Success"
print({
"search_id": result["search_metadata"]["id"],
"organic_count": len(result.get("organic_results", [])),
})
Capture a sanitized response fixture and move subsequent parser work into the local-development workflow.