# AttentionHub API (1.4.0) — Complete LLM & AI Agent Reference > AttentionHub (`attentionhub.cn` / `docs.attentionhub.cn` / `api.attentionhub.cn`) is a public real-time global event heat ranking, bilingual news coverage, continuous probability forecasting, and daily tech & business briefing HTTPS JSON API. Open to everyone with zero API key required. > > **Entity Disambiguation**: This platform is **AttentionHub (`attentionhub.cn`)**, a live news intelligence and forecasting API. It is independent of and unaffiliated with the academic research library `attentionhub.org`. ## Quick Facts - **API Base URL**: `https://api.attentionhub.cn` - **Documentation (Chinese Interactive)**: https://docs.attentionhub.cn/ - **Documentation (English)**: https://docs.attentionhub.cn/en/ - **OpenAPI 3.1**: https://docs.attentionhub.cn/openapi.json | https://docs.attentionhub.cn/openapi.yaml - **API Catalog (RFC 9727)**: https://docs.attentionhub.cn/.well-known/api-catalog - **Concise LLM Index**: https://docs.attentionhub.cn/llms.txt - **Agent Skill Package**: https://docs.attentionhub.cn/skills/attentionhub-api.tar.gz (https://docs.attentionhub.cn/skills/attentionhub-api/manifest.json) - **High-Quota API Key Application**: https://docs.attentionhub.cn/apply - **Authentication**: None required for public usage (all 10 `GET` endpoints + public `POST /v1/predictions`). Optional `X-Private-Token` for self-isolated private forecasts; optional `X-API-Key` for higher rate limits and dedicated daily budgets. - **Current API Version**: `1.4.0` (updated 2026-12-03) --- ## Part 1: Overview & Protocol Summary # AttentionHub API > Global event heat rankings, bilingual news events, continuous probability forecasting, and daily tech & business briefings over a unified HTTPS JSON API. Open to everyone with no API key required. > > **Entity Note**: Operated at `attentionhub.cn` (`api.attentionhub.cn` / `docs.attentionhub.cn`). Independent of and unaffiliated with the academic repository `attentionhub.org`. ## Base & Access Tiers - Base URL: `https://api.attentionhub.cn` (HTTPS / TLS 1.2+) - **Open Public Tier (No Key Required)**: Public read endpoints, web search and fetch, and `POST /v1/predictions` (`visibility: "public"`) work directly with **zero authentication headers**, rate-limited per client IP with daily anonymous prediction caps. - **Self-Generated Private Scope (`X-Private-Token`, Optional, No Signup)**: To create and read `visibility: "private"` predictions without an API key, pass a locally generated high-entropy token (`32–128` chars `[A-Za-z0-9_-]`, at least `10` distinct characters) in `X-Private-Token`. Isolated server-side via salted hashing; does **not** raise anonymous IP rate limits or daily caps. - **High-Volume / Partner Tier (`X-API-Key`, Optional)**: Not required for basic usage; unlocks higher QPS and dedicated daily prediction budgets. Apply at https://docs.attentionhub.cn/apply (or `POST /v1/key-applications`). Passing an invalid or duplicate `X-API-Key` returns `401`. Never send both `X-API-Key` and `X-Private-Token` together (`400 AMBIGUOUS_CREDENTIALS`). - Never hardcode keys or private tokens in source code or expose `X-API-Key` in browser clients; read optionally from `ATTENTIONHUB_API_KEY` or `ATTENTIONHUB_PRIVATE_TOKEN`. - All `/v1/*` responses return `Cache-Control: private, no-store`. - Event cover images use absolute WebP URLs hosted on `https://img.attentionhub.cn` (or `null` when unavailable/filtered). ## Content Display Mode (`cn_safe`) - Default mode is safe (`cn_safe=true`) when `cn_safe` is omitted. - To request the full unfiltered view, pass the exact lowercase query parameter `?cn_safe=false` once. - Any other form (`False`, `0`, duplicate keys, array syntax) falls back to safe mode. - Pagination cursors are bound to the active `cn_safe` mode, credential scope, and query filters; clear `cursor` whenever changing filters, credentials, or display mode (`400 INVALID_QUERY` otherwise). - In safe mode, sensitive events or public predictions queried by ID return `200 { "id": "...", "cn_filtered": true }`. ## Endpoints ### Heat Ranking & Events - `GET /v1/rankings/heat?window=breaking|24h&category=all&limit=20&cursor=...` — Real-time (`breaking`) or 24-hour (`24h`) global event heat snapshot (refreshed every 5 minutes). Each item includes `id`, `rank`, `score`, `rank_delta`, `title`, `summary`, `cover_url`, `representative_sources`, plus v1.2 nullable `source_count`, `article_count`, and `latest_report_at` (mode-scoped to `cn_safe`). - `GET /v1/events/{id}` — Full bilingual event details including v1.3 `body: {zh, en}|null` + `body_status` (`current` | `stale` | `missing`), merged member articles, cover URL, `{ id, merged_into }` redirect when merged, or `{ id, cn_filtered: true }`. - `GET /v1/events?ids=id1,id2,...` — Batch lookup (`1–50` IDs) preserving input order; returns detail, `{ id, merged_into }`, `{ id, cn_filtered: true }`, or `{ id, not_found: true }`. ### Continuous Probability Predictions - `probability`, `probabilities`, and `delta` use a **`0.0–1.0` decimal scale** (e.g. `0.55` = `55%`, `delta: -0.07` = `-7pp`). Valid `status` values: `pending_initial`, `active`, `resolved`, `cancelled`, `invalid`. - `POST /v1/predictions` — Submit a verifiable future-event question (`{ "question": "...", "visibility": "public" | "private" }`, optional `Idempotency-Key` header strongly recommended). `visibility: "public"` works keyless; `visibility: "private"` requires self-generated `X-Private-Token` or `X-API-Key`. Body `cn_safe` is ignored (server-classified); query `?cn_safe=false` controls `similar_questions` visibility. Returns `202 Accepted` with `prediction_id`, `similar_questions`, and `poll_after_ms: 1000`. Relative time returns `422 INVALID_PREDICTION`, `reason: "relative_time_not_allowed"`. - `GET /v1/predictions?status=...&category=...&updated_since=...&sort=recent|updated&limit=20&cursor=...` — Paginated list of public predictions plus private predictions matching the caller's `X-Private-Token` or `X-API-Key`. Each summary includes v1.2 nullable `title: {zh, en}`, `latest_delta`, and `latest_reason: {zh, en}` (fall back to `question` when `title` is `null`). - `GET /v1/predictions/search?q=...&mode=keyword|semantic&limit=20&status=...` — Keyword search or natural-language semantic search (falls back to keyword with `degraded: true` on timeout). - `GET /v1/predictions/{id}` — Poll target after `202` until `status != "pending_initial"`; returns `probability`, `contract`, `related_markets`, plus v1.2 nullable `title`, `latest_delta`, `latest_reason`, and `resolution_recap` (`{ summary: {zh, en} | null, judgment_count, sources: [{ id, source, url, published_at, title, title_zh, summary, summary_zh }] }` on resolved forecasts, v1.3). Private predictions belonging to another token/account return `404`. - `GET /v1/predictions/{id}/history?limit=50&before_id=...` — Reverse-chronological probability history points with `delta`, `reason`, v1.2 nullable `reason_zh`, and v1.3 structured bilingual `evidence[]` (`{ id, source, url, published_at, title, title_zh, summary, summary_zh }`, or `{ id, cn_filtered: true }` in safe mode). ### Daily Tech & Business Briefings (`08:00 UTC+8 / Asia/Shanghai`) - `GET /v1/briefings/latest?lang=both|zh|en` (alias `/v1/briefings/daily/latest`) — Latest published daily briefing (`version` param rejected with `400`). - `GET /v1/briefings/{date}?version=1&lang=both|zh|en` (alias `/v1/briefings/daily/{date}`) — Specific `YYYY-MM-DD` issue with optional immutable `version >= 1`. - `GET /v1/briefings?limit=20&cursor=...&lang=both|zh|en` (alias `/v1/briefings/daily`) — Paginated archive of past issues. ### Web Search and Page Extraction - `GET /v1/web/search?q=NASA+Artemis` or `POST /v1/web/search` with JSON — keyless search with `mode=auto|fast|aggregate`, `topic=general|news`, optional `time_range`, `lang`, `limit`, and `include_content`. A successful response may include partial provider results. - `POST /v1/web/fetch` with `{"url":"https://example.org/"}` — return title and text from a public HTTPS page. - Both routes default to the safe view. Pass `?cn_safe=false` for full. CLI commands are `web-search` and `web-fetch`. They share anonymous 10/min (burst 5) or API-key 60/min (burst 20). ### High-Quota API Key Applications - `POST /v1/key-applications` — Submit a high-quota `X-API-Key` application (`{ "email", "discovery_channel", "use_case" }`; web form hosted at https://docs.attentionhub.cn/apply). Rate limited `3 req/hour` per IP; returns `201 Created` with `{ application_id, status: "pending", created_at }` or `409 APPLICATION_ALREADY_PENDING`. ## Rate Limits & Quotas - General read endpoints (`/v1/rankings/heat`, `/v1/events*`, `/v1/predictions` GET, `/v1/predictions/{id}*`): Open IP `10 req/s` (burst `20`); High-Quota `X-API-Key` `30 req/s` (burst `60`). - Prediction submission (`POST /v1/predictions`): Open IP `6 req/min` (burst `2`), `20/IP/day`, `200/day` global anonymous cap; High-Quota `X-API-Key` `30 req/min` (burst `10`) with dedicated daily quota. Max body `16 KiB`. - Prediction search (`GET /v1/predictions/search`): Open IP `3 req/s` (burst `5`); High-Quota `X-API-Key` `10 req/s` (burst `15`). - Daily briefings (`GET /v1/briefings*`): Open IP `3 req/s` (burst `8`); High-Quota `X-API-Key` `10 req/s` (burst `20`). - On `429 RATE_LIMITED`, honor `Retry-After`; on `429 PREDICTION_BUDGET_EXHAUSTED`, do not retry. ## Error Handling - Branch programmatically on `error.code` (and `error.reason` on `422`): - `400` `INVALID_QUERY` / `INVALID_REQUEST` / `INVALID_IDEMPOTENCY_KEY` / `INVALID_PRIVATE_TOKEN` / `PRIVATE_TOKEN_REQUIRED` / `AMBIGUOUS_CREDENTIALS` — invalid parameter, expired/mismatched cursor, weak/malformed `X-Private-Token`, `private` without credential, or sending both `X-API-Key` and `X-Private-Token`. - `401` `UNAUTHORIZED` — invalid, revoked, or duplicate `X-API-Key` (never triggered when `X-API-Key` is omitted). - `404` `NOT_FOUND` / `RECORD_NOT_FOUND` — resource/issue not found or inaccessible private prediction. - `409` `IDEMPOTENCY_CONFLICT` / `APPLICATION_ALREADY_PENDING` — reused `Idempotency-Key` with changed body, or duplicate pending key application within 24h. - `422` `INVALID_PREDICTION` — undecidable question or relative time (`reason: "relative_time_not_allowed"`). - `429` `RATE_LIMITED` / `PREDICTION_BUDGET_EXHAUSTED` — retry with `Retry-After` on rate limit; do not retry on daily budget exhaustion. - `503` `DEPENDENCY_UNAVAILABLE` — transient upstream issue (`retryable: true`); retry with capped exponential backoff. ## Machine-Readable Docs & Agent Skill Package - OpenAPI 3.1 JSON: https://docs.attentionhub.cn/openapi.json - OpenAPI 3.1 YAML: https://docs.attentionhub.cn/openapi.yaml - Agent Skill Package (`.tar.gz`, complete folder with `SKILL.md`, `scripts/attentionhub.py`, `references/`, `examples/`): https://docs.attentionhub.cn/skills/attentionhub-api.tar.gz - Agent Skill Package (`.zip`): https://docs.attentionhub.cn/skills/attentionhub-api.zip - Skill Manifest & SHA-256 Checksums: https://docs.attentionhub.cn/skills/attentionhub-api/manifest.json - Skill Entry (`SKILL.md`): https://docs.attentionhub.cn/skills/attentionhub-api/SKILL.md - High-Quota Key Application Page: https://docs.attentionhub.cn/apply - Full LLM Reference (complete contracts, errors, workflows & FAQ): https://docs.attentionhub.cn/llms-full.txt - RFC 9727 API Catalog: https://docs.attentionhub.cn/.well-known/api-catalog - English Documentation: https://docs.attentionhub.cn/en/ - Interactive Reference (Chinese): https://docs.attentionhub.cn/ --- ## Part 2: Complete Endpoint Contracts & Pagination # AttentionHub Endpoint Contract Reference - **Base URL**: `https://api.attentionhub.cn` (HTTPS / TLS 1.2+) - **Access Tiers**: - **Open Public (Default — No Header)**: Public read endpoints, `GET/POST /v1/web/search`, `POST /v1/web/fetch`, and `POST /v1/predictions` (`visibility: "public"`) require **no authentication header**; governed by per-IP rate limits and anonymous daily prediction caps. - **Private Predictions (`X-Private-Token`, Self-Generated)**: Optional single header (`32–128` chars `[A-Za-z0-9_-]`, at least `10` distinct characters) generated locally by the caller. Isolates `visibility: "private"` predictions via server-salted hashing without registration; does **not** raise anonymous IP rate limits or daily caps. - **High-Volume / Partner (`X-API-Key`, Optional)**: Single header (`32–128` chars `[A-Za-z0-9_-]`) unlocking higher QPS, dedicated daily prediction budgets, and account-scoped private predictions. Apply at `https://docs.attentionhub.cn/apply`. Passing an invalid or duplicate `X-API-Key` returns `401`. Never send both `X-API-Key` and `X-Private-Token` together (`400 AMBIGUOUS_CREDENTIALS`). - **Cache**: all `/v1/*` responses return `Cache-Control: private, no-store` - **Cover Images**: absolute WebP URLs on `https://img.attentionhub.cn` (or `null` when unavailable/filtered) ## Display Mode (`cn_safe`) - Default when omitted: safe view (`cn_safe=true`). - Full unfiltered view: pass exact lowercase `?cn_safe=false` once in the query string. - Any other form (`False`, `0`, duplicate keys, `cn_safe[0]=false`) falls back to safe mode. - Pagination cursors are opaque and bound to `cn_safe`, active query filters, and credential scope. Clear `cursor` whenever switching modes, filters, or credentials (`400 INVALID_QUERY` otherwise). ## Heat Ranking & Events (3 Operations) ### `GET /v1/rankings/heat` - Query: - `window` (`breaking` | `24h`, required): `breaking` surfaces sudden real-time spikes; `24h` reflects sustained 24-hour significance. - `category` (default `all`, max 128 chars): e.g. `all`, `tech`, `business`, `geopolitics`. If unsure of a slug, query `all` and filter client-side. - `limit` (`1–100`, default `20`), `cursor`, `cn_safe`. - Response: `{ window, snapshot_id, cn_safe, items: [{ id, category, cn_safe, title: {zh, en}, summary: {zh, en}, rank, score, rank_delta, cover_url, representative_sources (max 3), source_count (int|null, v1.2), article_count (int|null, v1.2), latest_report_at (ISO-8601|null, v1.2) }], next_cursor }`. - Snapshots update every 5 minutes. `heat` does not include article URLs; call `GET /v1/events` for links and member coverage. ### `GET /v1/events/{id}` - Path: `id` (canonical event ID or merged historical ID, `1–128` chars). Query: `cn_safe`. - Response (`200`, three possible shapes): - Full detail: `{ id, category, severity? (optional), title: {zh, en}, summary: {zh, en}, body: {zh, en}|null (v1.3, populated only when body_status=="current"), body_status ("current"|"stale"|"missing", v1.3), first_published_at, latest_report_at, cn_safe, cover_url, members: [{ id, source, url, title: {zh, en}, summary: {zh, en}, published_at, perspective? }] }`. Note `zh` / `en` values may be `null`. - Merged pointer: `{ id, merged_into }` — re-query with `merged_into`. - Filtered shell (safe mode on sensitive event): `{ id, cn_filtered: true }`. ### `GET /v1/events` - Query: `ids` (required, comma-separated `1–50` IDs), `cn_safe`. - Response: `{ items: [...] }` preserving input order; each entry is `EventDetail`, `{ id, merged_into }`, `{ id, cn_filtered: true }`, or `{ id, not_found: true }`. ## Continuous Probability Predictions (5 Operations) - **Scale**: `probability`, `probabilities`, and `delta` use a **`0.0–1.0` decimal scale** (e.g. `0.55` = `55%`, `0.08` = `8%`, `delta: -0.07` = `-7 percentage points`). Multi-outcome or binary forecasts may also populate `probabilities` (map of option → `0.0–1.0`, e.g. `{"yes": 0.55, "no": 0.45}`). - **Lifecycle `status` enum**: `pending_initial` | `active` | `resolved` | `cancelled` | `invalid`. ### `POST /v1/predictions` - Headers: `Content-Type: application/json`, optional `Idempotency-Key` (`1–128` printable ASCII, strongly recommended), optional `X-Private-Token` (required when `visibility: "private"` without `X-API-Key`), or optional `X-API-Key` (high-quota tier). - Query: optional `cn_safe` (controls whether `similar_questions` includes unfiltered public predictions). - Body (max `16 KiB`): `{ "question": "...", "visibility": "public" | "private" }` (legacy alias `text` is also accepted). Any `cn_safe` field in the request **body** is ignored; the server classifies `cn_safe` automatically. - Response (`202 Accepted`): `{ prediction_id, status: "pending_initial" | "active", similar_questions (max 5): [{ id, question, similarity }], poll_after_ms: 1000 }`. - Follow-up: poll `GET /v1/predictions/{prediction_id}` every `poll_after_ms` until `status != "pending_initial"` (include the same `X-Private-Token` / `X-API-Key` if `visibility: "private"`). ### `GET /v1/predictions` - Query: `status`, `category` (max 40 chars), `updated_since` (ISO-8601 UTC), `sort` (`recent` | `updated`, default `recent`), `limit` (`1–100`, default `20`), `cursor`, `cn_safe`. - Response: `{ snapshot_at, items: [PredictionSummary], next_cursor }`. Returns public predictions; when `X-Private-Token` or `X-API-Key` is provided, also includes private predictions belonging to that scope. - `PredictionSummary`: `{ id, question, title: {zh, en}|null (v1.2), category, status, visibility, cn_safe, deadline_at, deadline_granularity, probability, probabilities, latest_delta (number|null, v1.2), latest_reason: {zh, en}|null (v1.2), as_of, updated_at, resolution_outcome, stale }`. Fall back to `question` when `title` is `null`. ### `GET /v1/predictions/search` - Query: `q` (`1–240` chars, required), `mode` (`keyword` | `semantic`, default `keyword`), `limit` (`1–50`, default `20`), `status`, `cn_safe`. - Response: `{ items: [PredictionSummary], mode, degraded }`. When `mode=semantic` degrades on timeout, `degraded: true` and keyword results are returned. ### `GET /v1/predictions/{id}` - Path: `id` (UUID). Query: `cn_safe`. - Response (`200`): `PredictionDetail` (`PredictionSummary` + `contract` structured resolution criteria + `related_markets` reference market quotes that never override primary `probability` + `resolution_recap: { summary: {zh, en}|null, judgment_count, sources: [{ id, source, url, published_at, title, title_zh, summary, summary_zh }] }|null` on resolved forecasts, v1.2/v1.3), or `{ id, cn_filtered: true }` in safe mode. Private predictions belonging to another token or account return `404`. ### `GET /v1/predictions/{id}/history` - Path: `id` (UUID). Query: `limit` (`1–100`, default `50`), `before_id` (int64 from `next_before_id`), `cn_safe`. - Response (`200`): `{ id, items: [{ id, as_of, probability, probabilities, delta, reason, reason_zh (string|null, v1.2), evidence: [{ id, source, url, published_at, title, title_zh, summary, summary_zh }] (v1.3) }], next_before_id }`, or `{ id, cn_filtered: true }` in safe mode (in safe mode, historical points citing restricted/retracted reports are also omitted). ## Daily Tech & Business Briefings (3 Operations) Published daily at **`08:00 UTC+8 (Asia/Shanghai)`** with `tech` and `business` sections. When `lang=both` (default), text fields (`headline`, `summary_md`, `what_happened`, `why_it_matters`) are `{ zh, en }` objects; when `lang=zh` or `lang=en`, they flatten to plain strings. ### `GET /v1/briefings/latest` (alias `/v1/briefings/daily/latest`) - Query: `lang` (`both` | `zh` | `en`, default `both`), `cn_safe`. Never pass `version` to `/latest` (`400 INVALID_QUERY`). - Response (`BriefingDetail`): `{ briefing_date, edition: "safe" | "full", version, source_snapshot_at?, status, headline, summary_md, generated_at, superseded_by_version, briefing: { items: [{ event_id, section, headline, what_happened, why_it_matters, evidence_ids (1–3) }] } }`. ### `GET /v1/briefings/{date}` (alias `/v1/briefings/daily/{date}`) - Path: `date` (`YYYY-MM-DD`; invalid calendar dates like `2026-02-30` return `400 INVALID_QUERY`; unpublished dates return `404`). - Query: `version` (optional integer `>= 1`), `lang`, `cn_safe`. ### `GET /v1/briefings` (alias `/v1/briefings/daily`) - Query: `limit` (`1–100`, default `20`), `cursor`, `lang`, `cn_safe`. - Response: `{ edition, cn_safe, snapshot_at, items: [BriefingSummary], next_cursor }` (`BriefingSummary` has all top-level metadata including `headline` and `summary_md`, without `briefing.items`). ## OpenAPI 3.1 & High-Quota Application - OpenAPI JSON / YAML: `https://docs.attentionhub.cn/openapi.json` · `https://docs.attentionhub.cn/openapi.yaml` - Apply for High-Quota `X-API-Key`: `https://docs.attentionhub.cn/apply` ## Web Search and Extraction ### GET /v1/web/search and POST /v1/web/search - Send parameters as a query string with GET or a JSON object with POST. `q` is required (1–200 characters). POST bodies are limited to 8 KiB. - `mode`: `auto` (default, language and topic routing), `fast` (one main provider with fallback), or `aggregate` (parallel providers within a 7-second request budget). - `topic`: `general` (default) or `news`. `time_range`: optional `day`, `week`, `month`, or `year`. `lang`: `auto` (default), `zh`, or `en`. - `limit`: 1–30 (default 10). Set `include_content=true` for page text when supplied by a provider. Pass `cn_safe=false` in the query string to use full mode. - Response: `{query, mode, lang, cn_safe, items, providers}`. Items contain `{url, title, summary, source, published_at, engines, score, content?}`. Publication time can be null. An HTTP 200 can contain partial provider coverage or zero matching items; inspect `providers` if coverage matters. ### POST /v1/web/fetch - Send `{"url":"https://example.org/"}` (public HTTPS only, 8 KiB JSON body limit). Pass `cn_safe=false` in the query string to request full mode. - Response: `{url, title, content, source, published_at, provider, cn_safe}`. `content` is extracted text; publication time can be null. A filtered page returns `404 WEB_CONTENT_UNAVAILABLE`. --- ## Part 3: Rate Limits, Quotas & Error Handling Matrix # Rate Limits, Error Codes & Retry Discipline All `/v1/*` responses include `Cache-Control: private, no-store`. ## Rate Limits & Quotas | Tier | Routes | Open Public (Per IP, No Key) | High-Quota `X-API-Key` (Per Key) | Notes | |---|---|---|---|---| | General Read | `GET /v1/rankings/heat`, `GET /v1/events*`, `GET /v1/predictions`, `GET /v1/predictions/{id}*` | `10 req/s` (burst `20`) | `30 req/s` (burst `60`) | Self-generated `X-Private-Token` stays in the open IP tier | | Prediction Submit | `POST /v1/predictions` | `6 req/min` (burst `2`), `20`/IP/day, `200`/day global anon cap | `30 req/min` (burst `10`), dedicated account daily cap | Max body `16 KiB`; apply for high quota at `https://docs.attentionhub.cn/apply` | | Prediction Search | `GET /v1/predictions/search` | `3 req/s` (burst `5`) | `10 req/s` (burst `15`) | Debounce interactive UI queries (e.g. `300ms`) | | Daily Briefings | `GET /v1/briefings*`, `GET /v1/briefings/daily*` | `3 req/s` (burst `8`) | `10 req/s` (burst `20`) | Covers both `/briefings*` and `/briefings/daily*` | ## Error Response Envelopes Standard envelope (read, auth, and rate-limit responses): ```json { "request_id": "90567bd0-591c-4469-944b-631fc9e1e49e", "error": { "code": "INVALID_QUERY", "message": "Cursor does not match the display mode, window, category or retained snapshot", "retryable": false, "details": {} } } ``` Compact write-error envelope (`POST /v1/predictions` on `400` / `409` / `422` / `429`): ```json { "error": { "code": "INVALID_PREDICTION", "reason": "relative_time_not_allowed" } } ``` Always branch programmatically on `error.code` (and inspect `error.reason` on `422`). When using `scripts/attentionhub.py`, all errors are written as structured JSON to `stderr` (`stdout` remains clean). ## Status Code Action Matrix | HTTP | `error.code` | Cause | Agent Action | |---|---|---|---| | `400` | `INVALID_QUERY` / `INVALID_REQUEST` / `INVALID_IDEMPOTENCY_KEY` | Out-of-range param, invalid calendar date (`2026-02-30`), expired or cross-mode cursor, `version` on `/latest`, or malformed `Idempotency-Key` | Fix inputs or drop `cursor` and restart from page 1; never retry verbatim | | `400` | `INVALID_PRIVATE_TOKEN` | Duplicate `X-Private-Token`, wrong length/charset, or low entropy (`< 10` distinct chars) | Generate a strong token with `gen-private-token` (`32–128` chars `[A-Za-z0-9_-]`) | | `400` | `PRIVATE_TOKEN_REQUIRED` | Submitted `visibility: "private"` without `X-Private-Token` or `X-API-Key` | Set `ATTENTIONHUB_PRIVATE_TOKEN` (from `gen-private-token`) or switch to `visibility: "public"` | | `400` | `AMBIGUOUS_CREDENTIALS` | Sent both `X-API-Key` and `X-Private-Token` in the same request | Send at most one credential header | | `401` | `UNAUTHORIZED` | Invalid, revoked, or duplicated `X-API-Key` (never returned when `X-API-Key` is omitted) | Fix or unset `ATTENTIONHUB_API_KEY`; public usage requires no key | | `404` | `NOT_FOUND` / `RECORD_NOT_FOUND` | Unknown ID/issue date or private prediction owned by a different `X-Private-Token` / account | Inform user cleanly; confirm matching `X-Private-Token` if checking a private forecast | | `409` | `IDEMPOTENCY_CONFLICT` | Same `Idempotency-Key` reused with a different request body | Keep identical payload on retries; generate a fresh `Idempotency-Key` for modified questions | | `422` | `INVALID_PREDICTION` | Empty/undecidable question or relative time (`reason: "relative_time_not_allowed"`) | Rewrite with objective resolution criteria and an explicit absolute date (`YYYY-MM-DD`) | | `429` | `RATE_LIMITED` | Per-second / per-minute rate limit exceeded | Wait `Retry-After` seconds (or capped backoff) before retrying | | `429` | `PREDICTION_BUDGET_EXHAUSTED` | Per-IP (`20/day`), global anonymous (`200/day`), or account daily prediction quota reached | **Do not retry**; inform the user and mention `https://docs.attentionhub.cn/apply` if high volume is needed | | `503` | `DEPENDENCY_UNAVAILABLE` | Transient upstream overload (`retryable: true`) | Retry with capped exponential backoff (`1s`, `2s`, `4s`); only retry `POST` if `Idempotency-Key` was sent | ## Web Search and Fetch Search and fetch share the web quota. Anonymous callers get 10 requests per minute per IP (burst 5). API-key callers get 60 requests per minute per account (burst 20). Honor `Retry-After` on `429 RATE_LIMITED`. Search and fetch POST bodies have an 8 KiB limit. | HTTP | Code | Client action | | --- | --- | --- | | 400 | `INVALID_REQUEST`, `INVALID_URL` | Check parameters and use a public HTTPS URL. | | 404 | `WEB_CONTENT_UNAVAILABLE` | Use another public source. | | 413 | `PAYLOAD_TOO_LARGE` | Send a smaller JSON body. | | 503 | `WEB_SEARCH_UNAVAILABLE`, `WEB_FETCH_UNAVAILABLE` | Use capped backoff for temporary provider failures. | --- ## Part 4: End-to-End Integration & Agent Workflow Examples # Common Agent Workflows Replace `` with the folder containing `SKILL.md`. All public workflows run with **zero API key**. Keep default compact JSON (omit `--pretty`) to minimize context tokens. ## 1. Morning Tech & Business Briefing (Pre/Post `08:00 UTC+8`) 1. Fetch the latest issue: ```bash python3 "/scripts/attentionhub.py" briefing --lang zh ``` 2. **Always check `briefing_date` against today's date in `UTC+8 (Asia/Shanghai)`**: - If `briefing_date` matches today: summarize `summary_md` and key `briefing.items`. - If `briefing_date` is yesterday (e.g., before `08:00 UTC+8`) or `/latest` returns `404`: explicitly tell the user today's `08:00 UTC+8` issue is not out yet, share yesterday's highlights if helpful, and supplement with live breaking/24h events: ```bash python3 "/scripts/attentionhub.py" heat --window breaking --category all --limit 10 ``` 3. To inspect past archive dates: ```bash python3 "/scripts/attentionhub.py" briefings --limit 5 --lang zh ``` ## 2. Investigate Top Breaking Global Events with Source Links 1. Pull 5 breaking events (extra buffer in case an item is merged or `cn_filtered`): ```bash python3 "/scripts/attentionhub.py" heat --window breaking --limit 5 ``` 2. Batch-fetch full details, source links, and automatically resolve any `merged_into` pointers while capping `members` to keep token usage lean: ```bash python3 "/scripts/attentionhub.py" events ,, --follow-merged --max-members 5 ``` 3. If any item returns `"cn_filtered": true` in default safe mode, report it transparently rather than silently re-running with `--full` unless the user explicitly asks for the unfiltered view. ## 3. Search Before Submitting a Public or Private Prediction 1. Search first with semantic mode: ```bash python3 "/scripts/attentionhub.py" predict-search "ECB December 2026 rate cut" --mode semantic --limit 5 ``` - If `degraded: true` (semantic search fell back to keyword), do **not** assume empty results mean no duplicate exists—retry with short English/Chinese keywords (e.g. `"ECB"` or `"欧央行 降息"`) before creating. - Check `status` (e.g. ignore `resolved`/`cancelled` when looking for active forecasts). 2. If creating a new **public** forecast (zero key required): - Rewrite any relative timeframe ("next month", "within 30 days") into an explicit absolute date (`YYYY-MM-DD`). - Confirm resolution criteria and visibility (`public` vs `private`) with the user. - Submit and wait for initial completion: ```bash python3 "/scripts/attentionhub.py" predict-submit \ "Will the European Central Bank cut its deposit facility rate by at least 25bp before 2026-12-31?" \ --visibility public \ --wait ``` 3. If the user wants a **private** forecast (no signup needed): - If `ATTENTIONHUB_PRIVATE_TOKEN` (and `ATTENTIONHUB_API_KEY`) is not yet set, generate one once locally and ask the user to persist it safely in `ATTENTIONHUB_PRIVATE_TOKEN`: ```bash python3 "/scripts/attentionhub.py" gen-private-token ``` - Then submit with `ATTENTIONHUB_PRIVATE_TOKEN` exported (never echo the token value in responses): ```bash python3 "/scripts/attentionhub.py" predict-submit \ "Will our target vendor ship SDK v3 before 2026-09-30?" \ --visibility private \ --wait ``` - Always use the same `ATTENTIONHUB_PRIVATE_TOKEN` on follow-up `predict-list`, `predict-get`, and `predict-history` calls. 4. Report `probability` on its **`0.0–1.0` decimal scale** converted cleanly for humans (`0.55` = `55%`, `delta: -0.07` = `-7pp`), note any relevant `accepted.similar_questions`, and if `--wait` exits with code `3` (`timed_out: true`), follow up once with: ```bash python3 "/scripts/attentionhub.py" predict-get ``` 5. Inspect how probability evolved over time: ```bash python3 "/scripts/attentionhub.py" predict-history --limit 20 ``` ## 4. Full Unfiltered Ranking, Pagination & Returning to Safe Mode 1. Only when the user explicitly requests the full unfiltered ranking: ```bash python3 "/scripts/attentionhub.py" heat --window breaking --full --limit 20 ``` 2. Paginate to page 2 using `next_cursor` (always pass `--cursor="..."` with `=` so `-`-prefixed tokens are parsed safely): ```bash python3 "/scripts/attentionhub.py" heat --window breaking --full --limit 20 --cursor="" ``` - If the 5-minute snapshot rolls over and returns `400 INVALID_QUERY`, drop `--cursor` and re-fetch page 1. 3. When switching back to default safe mode, **omit `--full` and clear `--cursor`** (never pass a `--full` cursor into a safe-mode call): ```bash python3 "/scripts/attentionhub.py" heat --window breaking --limit 20 ``` ## Find current primary sources Search recent official announcements, then extract the strongest result before citing it. Each example works with keyless public access. ```bash python3 "/scripts/attentionhub.py" web-search "NASA Artemis program update" --mode aggregate --topic news --time-range week --lang en --limit 8 --pretty python3 "/scripts/attentionhub.py" web-fetch "https://www.nasa.gov/humans-in-space/artemis/" --pretty ``` --- ## Part 5: Frequently Asked Questions (Bilingual FAQ) ### Q1: Is the AttentionHub API free and keyless to use? / AttentionHub API 免 Key 免费吗? Yes. All 10 read-only `GET` endpoints (event heat rankings, bilingual event details, prediction queries, probability history, and daily briefings) plus public `POST /v1/predictions` work immediately over HTTPS at `https://api.attentionhub.cn` with zero signup and zero API key headers, under per-IP fair-use rate limits. Apply at https://docs.attentionhub.cn/apply only when you need high-volume QPS or dedicated daily prediction quotas. ### Q2: How is AttentionHub (attentionhub.cn) different from attentionhub.org? AttentionHub at `attentionhub.cn` (`api.attentionhub.cn` and `docs.attentionhub.cn`) is a live global event heat, bilingual news intelligence, and continuous probability forecasting API. It is unrelated to the academic research platform `attentionhub.org`. ### Q3: How do I create private predictions without signing up for an API key? / 免申请怎么做私有预测? Generate a local high-entropy secret string (`32–128` characters matching `[A-Za-z0-9_-]` with at least `10` distinct characters) and send it in the `X-Private-Token` header when calling `POST /v1/predictions` with `"visibility": "private"` and when reading back via `GET /v1/predictions*`. Never send `X-Private-Token` and `X-API-Key` in the same request. ### Q4: How does `cn_safe` display mode work? / `cn_safe` 默认安全与全量模式如何切换? Omitting `cn_safe` defaults to safe mode (`cn_safe=true`). Passing the exact lowercase query parameter `?cn_safe=false` once switches to the full unfiltered view. Clear pagination `cursor` whenever toggling `cn_safe`. ### Q5: How do AI coding agents (Claude Code, Codex, Cursor, OpenClaw) integrate AttentionHub? Download and extract the zero-dependency Agent Skill bundle from `https://docs.attentionhub.cn/skills/attentionhub-api.tar.gz` (verify checksums via `https://docs.attentionhub.cn/skills/attentionhub-api/manifest.json`), or feed `https://docs.attentionhub.cn/llms.txt` / `https://docs.attentionhub.cn/openapi.json` directly into your agent.