Zhihu Q&A Mining API Workflow | SandBase
Read one known Zhihu question or its first answer feed. Validate card targets, preserve unknown fields, and avoid unverified pagination or automatic chaining.

A Zhihu question link is enough to start a focused research task. You may want to confirm what the question asks and how much discussion surrounds it, or read the first answer feed. These are different requests. You do not need to fetch a hot list, automatically select its first item, or run a three-step pipeline before inspecting one known question.
This 2026-11-08 repair checks current free inspect and public response references for question detail and question answers. It makes no paid business request and does not claim a fresh successful run. The earlier article’s illustrative JSON and Python are preserved with their original 2026-09-27 context below. For the wider catalog, see the Zhihu public data API hub.
Key takeaway
- Already have a question ID: choose one detail request or one answer-feed request.
- Detail is a question record at
outputs[0].data; emptydetailandexcerptcan be normal.- Answers are feed cards at
outputs[0].data.data. Only cards markedtarget_type: "answer"contain an answer undertarget.- Start the feed with
limit: 5,offset: 0,order: "default"; omit cursor and session ID and stop after that response.
Choose the read that answers your question
| Reader task | Exact endpoint | This example sends |
|---|---|---|
| Confirm the question title and available metadata | Question detail | question_id |
| Inspect the first feed and extract answer records | Question answers | question_id, limit: 5, offset: 0, order: "default" |
Take the numeric ID from a known public question URL, such as 37811449 in https://www.zhihu.com/question/37811449. Supply the ID string, not the entire link. A question ID and an answer ID are different identifiers; do not substitute an answer URL’s final number just because both look numeric.
The detail schema declares only required question_id. The answers schema also requires that ID, describes limit defaulting to 5 and offset to 0, and lists default or updated sorting. This example fixes the first-screen choice explicitly rather than importing unrelated search filters. Choosing default does not promise a chronological list or a ranking by truth or expertise. Sending a limit does not prove that every response contains that many answer records.
Use your current key or hand the task to an agent
With an existing key, store SANDBASE_API_KEY locally and install requests in the project’s Python environment. Do not paste the key into prompts, source files or logs. The example reads the environment and stops before network access if the key is missing.
If an agent is already connected to SandBase, ask it to inspect the selected endpoint and reuse its connection. Specify the known ID, the chosen task and the one-request limit. A useful instruction is: “Read the first answer feed for this question; separate answer targets from other cards, keep unknown fields unknown, and stop before any follow-up request.” There is no need to recreate the project or run discovery against every endpoint.
For a new integration, give the agent the setup skill and the Markdown quickstart, followed by that concrete task. The human quickstart covers account/key setup. Creating a key does not verify the target’s availability or the remaining free allowance.
One bounded Python request
The default below reads detail only. Its numeric input guard and its requirement for a matching string ID and nonempty title are local completeness checks based on the reference shape, not a promise about every upstream response. Optional metadata remains optional.
import os
import re
import requests
def first_request(task, question_id):
if task not in ("detail", "answers"):
raise ValueError("Choose detail or answers")
if not isinstance(question_id, str) or not re.fullmatch(r"[0-9]+", question_id):
raise ValueError("question_id must be a numeric ID string, not a URL")
params = {"question_id": question_id}
if task == "answers":
params.update(limit=5, offset=0, order="default")
key = os.environ.get("SANDBASE_API_KEY", "").strip()
if not key:
raise ValueError("Set SANDBASE_API_KEY locally")
try:
response = requests.post(
f"https://api.sandbase.ai/v1/api/zhihu/web/question-{task}",
headers={"Authorization": f"Bearer {key}"},
json=params, timeout=(10, 90), allow_redirects=False,
)
if not 200 <= response.status_code < 300:
raise RuntimeError(f"HTTP {response.status_code}; no retry performed")
body = response.json()
except ValueError:
raise RuntimeError("Response was not valid JSON") from None
except requests.RequestException:
raise RuntimeError("Network request failed; no retry performed") from None
if not isinstance(body, dict) or body.get("status") != "completed":
raise RuntimeError("Request did not complete")
outputs = body.get("outputs")
if not isinstance(outputs, list) or not outputs or not isinstance(outputs[0], dict):
raise RuntimeError("Missing documented outputs[0].data")
payload = outputs[0].get("data")
if not isinstance(payload, dict):
raise RuntimeError("Missing business payload object")
if task == "detail":
if payload.get("id") != question_id:
raise RuntimeError("Question ID missing or mismatched")
title = payload.get("title")
if not isinstance(title, str) or not title.strip():
raise RuntimeError("Question title missing")
else:
cards = payload.get("data")
if not isinstance(cards, list):
raise RuntimeError("Missing answer feed array")
for card in cards:
if not isinstance(card, dict):
raise RuntimeError("Malformed feed card")
if card.get("target_type") == "answer":
if not isinstance(card.get("target"), dict) or not card["target"]:
raise RuntimeError("Missing answer target object")
return payload
def answer_records(payload):
# Use only after first_request has validated the feed.
return [card["target"] for card in payload["data"]
if card.get("target_type") == "answer"]
if __name__ == "__main__":
result = first_request("detail", "37811449")
print(result["title"])For the answer task, replace the final two lines with result = first_request("answers", "19550225") and print(len(answer_records(result))). That prints the count of extracted answer targets, not the count of every feed card or the question’s total answers. These are alternative examples, not successive steps. Both IDs come from current public schema examples; neither request was executed for this repair.
answer_records is local processing of an already validated response. It does not call the network, retrieve full answer text, profile authors, follow links or download images. Keep the returned payload if you need to inspect omitted card types or pagination metadata later; the helper returns it unchanged.
Validate the envelope before interpreting the feed
The code stops on redirects, HTTP errors, authentication/permission failures, quota/payment errors, timeouts and invalid JSON. It uses connect/read timeouts and does not automatically retry an operation that could consume quota or money. Its errors omit the key and raw response body. Decide whether to resend after understanding the failure.
A completed response must contain an object at the documented outputs[0].data. A missing output is an error, not {} or an empty list. No legacy top-level output is accepted, and no provider code: 0, ok: 1 or success flag is invented for these reference shapes.
Question detail is already the question record. The current reference shows a matching string id, a title and optional counts, with empty strings for both detail and excerpt. Those two empty fields are not evidence that the request failed or that the question has no answers. The helper checks identity and title without requiring description text or converting a missing counter to zero.
The answer endpoint needs a different mapper. Its business data array contains feed cards, with an answer inside target when target_type equals answer. The wrapper’s type can be question_feed_card; it is not the answer record itself. A malformed answer-marked card with no target object is rejected. Other card types stay in the original payload but are omitted from the extracted answers. A valid empty array is an empty feed, while a missing array is a structure error.
A separate ad_info block appears in the current public reference. It is advertising metadata, not an answer. This example neither counts it as a response nor follows its tracking URLs. Unknown card kinds are not silently relabeled as answers; zero extracted answers from a nonempty mixed feed does not prove that the question has no answers.
What the current references actually show
The public detail README contains a trimmed real response for question 37811449: title 有哪些优雅的 Windows 10 壁纸? (a question about elegant Windows 10 wallpapers), 90 answers, 9 comments and 2,912 followers, with empty description fields. Those are reference-sample values, not fresh measurements from this update. The sample also contains a creation timestamp and review flags; a missing visit_count must remain unknown even if a field table describes it.
The public answers reference for 19550225 shows the card/target distinction, an author object nested under the answer, response-derived cursor information, paging.is_end: false and session.id. It is trimmed, so it cannot establish complete answer text, every field or the number of untrimmed items. Author follower counts and identity badges describe returned metadata; they are not proof of correctness or a license to rank expertise automatically. No personal profile data is copied into the new example.
For storage, separate question metadata from sampled answer records. Keep the question ID and observation time, mark omitted fields as unknown, and retain provenance for any extracted text. A count of sampled answers is different from the question’s advertised total. Summarizing that sample is another task; this helper does not invoke an LLM or present a sample as the community’s full view.
Historical hot-list reference from the original article. Its old generated cURL includes a model field; do not copy that into the current endpoint-parameter-only request. Hot-list execution was not revalidated and is not a prerequisite for a known question.
Why the old pagination advice was wrong
The previous tutorial said to increase offset instead of reading response fields. That is not adequate guidance for the current question-answer reference. The schema describes both cursor and session_id as extracted from the response. README Notes associates continuation with the returned cursor and session.id, and identifies paging.is_end as the end signal.
This repair does not test continuation, so it supplies no next-page code. On the first request, cursor and session ID are omitted; they are not invented, reused from a different question or copied from a trimmed reference. If you later implement pagination, verify the actual untrimmed response and selected endpoint contract first. A shortened paging.next URL is unsuitable as a live request target, and the current helper never follows it automatically.
The old code’s limit of 20 is preserved in the archive as part of its original example. The current first-screen code explicitly uses 5. Neither number creates a guarantee that the requested count will be honored or that a short page ends the question. Offset alone is not evidence of a correct continuation state.
Historical question-detail parameter/reference screenshot. The current free reference check supports the selected ID input; this image is not a new request result.
Price, quota and scope
Free inspect on 2026-11-08 lists a base price of $0.001 for each selected endpoint. Both are eligible for the organization’s shared 100 daily calls across eligible APIs, resetting at 00:00 UTC. Eligibility is not remaining quota; this repair did not inspect your allowance, account balance or actual charge.
The default example makes one request. Choosing answers instead still makes one. Deliberately running both would estimate $0.002 at the listed base prices before quota treatment; it is not a prerequisite and is not what the default code does. Every extra page, retry, answer-detail read or author lookup needs a separate decision and budget. The earlier multi-question loop is not the onboarding cost.
Earlier article material, preserved with limits
The retained cover illustrates the old hot-list-to-question-to-answer idea. Its topics, counts and answer text are conceptual artwork, not measured rankings or evidence that this repair executed that pipeline. The original article published on 2026-09-27 included the following illustrative JSON. It was not accompanied by a newly verified run in this repair, and its identifier is not proof of current business execution:
{
"id": "fad23166-43be-45dc-a1e8-8a2e60050349",
"status": "completed",
"model": "zhihu/web/question-answers",
"outputs": [
{
"data": {
"data": [
{ "type": "answer", "target": { "…": "…" } }
]
}
}
]
}In particular, the old schematic type: "answer" must not replace the current target_type test. The current public reference uses a question_feed_card wrapper and keeps the answer in target. The historical JSON is preserved unchanged for traceability, not supplied as a current parser fixture.
The historical Python archive keeps all four original blocks per locale byte-for-byte with hashes. Its helper silently substituted empty outputs; its hot-list selection could turn a missing ID into the literal string "None"; and its combined loop could issue one hot-list call plus up to ten detail calls. The illustrated three-stage path required three selected reads before follow-ups. None of those automatic calls belongs to the new bounded entry point.
Historical question-answers reference. Its paging parameters are navigation context, not proof that increasing offset alone works; current continuation needs response-derived state and remains untested here.
FAQ
Do I need a Zhihu login? These selected public read endpoints use a SandBase key. They do not authorize posting or access to private/account-only material. They are separate from account-authorized actions through Zhihu’s official channels.
Why is an empty excerpt accepted?
The current detail sample contains empty detail and excerpt strings alongside a valid question ID and title. Missing metadata is not the same as a failed envelope, and it should not become invented text.
Why did five requested items produce fewer extracted answers? The limit is a request parameter, not a verified exact-result guarantee. The helper only counts answer-marked targets, omitting other cards and advertising metadata. Inspect the returned feed before interpreting the count.
Can an agent collect the whole question automatically? This example stops after one response. A full collection needs separately verified continuation, response mapping and budget. It cannot be inferred from a successful first screen or a question’s total-answer count.
Next steps
Give your agent a known question ID and choose one task. Validate the returned structure, then decide whether the available metadata or answer sample is sufficient. Open question detail or question answers to start; use the API hub for the broader catalog.
Found this useful? Share it