Stack Overflow API: Get answer
Gets a Stack Overflow question and its best answers, from a question link or a plain-word search. A search picks the most relevant answered question. The accepted answer comes first, then answers by score.
Unofficial. Not affiliated with or endorsed by Stack Overflow.
Inputs
Values from the run on Oct 23, 2026, shown under Output.
- Question, required
question A Stack Overflow question link or the question in plain words, e.g. how do I reverse a list in Python?
https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array
- Max Answers optional
max_answers Number of answers to return, e.g. 3 (up to 10).
3
Whole number from 1 to 10. Default
3.
Input as JSON
{ "question": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array" , "max_answers": 3}Output
{ "tags": [ "java", "c++", "performance" ], "answers": [ { "date": "2012-06-27", "link": "https://stackoverflow.com/a/11227902" , "score": 35296, "author": "Mysticial", "accepted": true, "answer_text": "You are a victim of branch prediction fail.\n\nWhat is Branch Prediction?\n\nConsider a railroad junction:\n\nImage showing a railroad junction\nImage by Mecanismo, via Wikimedia Commons. Used under the CC-By-SA 3.0 license.\n\nNow for the sake of argument, suppose this is back in the 1800s - before long-dis…" }, { "date": "2012-06-27", "link": "https://stackoverflow.com/a/11227877" , "score": 4767, "author": "Daniel Fischer", "accepted": false, "answer_text": "Branch prediction.\n\nWith a sorted array, the condition data[c] >= 128 is first false for a streak of values, then becomes true for all later values. That's easy to predict. With an unsorted array, you pay for the branching cost." }, { "date": "2012-06-28", "link": "https://stackoverflow.com/a/11237235" , "score": 3860, "author": "WiSaGaN", "accepted": false, "answer_text": "The reason why performance improves drastically when the data is sorted is that the branch prediction penalty is removed, as explained beautifully in Mysticial's answer.\n\nNow, if we look at the code\n\n```\nif (data[c] >= 128)\n sum += data[c];\n```\n\nwe can find that the meaning of this particular if.…" } ], "question_link": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array" , "question_text": "In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster:\n\n```\n#include <algorithm>\n#include <ctime>\n#include <iostream>\n\nint main()\n{\n // Generate data\n const unsigned arraySize = 32768;\n int data[arraySize];\n\n for (unsigned c = 0; c < arraySize; ++…", "question_title": "Why is conditional processing of a sorted array faster than of an unsorted array?"}Code
curl https://api.fous.com/v1/runs \ -H "Authorization: Bearer $FOUS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"method":"stackoverflow.com/get_answer","input":{"question":"https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array","max_answers":3}}' # Save as fous.py, then run: python3 fous.pyimport json, os, timefrom urllib.error import HTTPErrorfrom urllib.request import Request, urlopenAPI = "https://api.fous.com/v1/runs" KEY = os.environ["FOUS_API_KEY"]HEADERS = { "Authorization": f"Bearer {KEY}", "Content-Type": "application/json" ,}def call(url, body=None): data = json.dumps(body).encode() if body else None request = Request(url, data, HEADERS) try: with urlopen(request, timeout=120) as r: return r.status, json.load(r) except HTTPError as error: message = json.load(error)["error"]["message"] raise RuntimeError(message) from errorstatus, run = call(API, { "method": "stackoverflow.com/get_answer" , "input": { "question": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array" , "max_answers": 3 }})# 202: still going after 30 s. Ask again until it ends.while status == 202: time.sleep(2) status, run = call(f"{API}/{run['id']}")print(json.dumps(run["data"], indent=2))// Save as fous.mjs, then run: node fous.mjsconst api = "https://api.fous.com/v1/runs" ;const headers = { Authorization: `Bearer ${process.env.FOUS_API_KEY}`, "Content-Type": "application/json" ,};let response = await fetch(api, { method: "POST", headers, body: JSON.stringify({ "method": "stackoverflow.com/get_answer" , "input": { "question": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array" , "max_answers": 3 } }), signal: AbortSignal.timeout(120_000),});let run = await response.json();// 202: still going after 30 s. Ask again until it ends.while (response.status === 202) { await new Promise((done) => setTimeout(done, 2_000)); response = await fetch(`${api}/${run.id}`, { headers }); run = await response.json();}if (!response.ok) throw new Error(run.error.message);console.log(run.data);# Connect your agent to Fous once, over MCP (Streamable HTTP):# https://api.fous.com/mcp# Set FOUS_API_KEY first: create a key at https://app.fous.com/keys.# Claude Codeclaude mcp add \ --scope user \ --transport http fous https://api.fous.com/mcp \ --header "Authorization: Bearer ${FOUS_API_KEY:?Set FOUS_API_KEY to your Fous API key}"# Codexcodex mcp add fous \ --url https://api.fous.com/mcp \ --bearer-token-env-var FOUS_API_KEY# Cursor, VS Code, Windsurf, Cline and morenpx -y add-mcp https://api.fous.com/mcp -g -n fous \ --header "Authorization: Bearer ${FOUS_API_KEY:?Set FOUS_API_KEY to your Fous API key}"# Then ask your agent:# "Use Fous to run stackoverflow.com/get_answer# with {"question":"https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array","max_answers":3}"Over HTTP, the answer’s data holds the output. A run still going after 30 seconds answers 202 with its id: ask GET /v1/runs/{id} until it ends.
Schema
Input schema
{ "type": "object", "required": [ "question" ], "properties": { "question": { "type": "string", "minLength": 1, "description": "A Stack Overflow question link or the question in plain words, e.g. how do I reverse a list in Python?" }, "max_answers": { "type": "integer", "default": 3, "maximum": 10, "minimum": 1, "description": "Number of answers to return, e.g. 3 (up to 10)." } }}Output schema
{ "type": "object", "required": [ "question_title", "question_text", "question_link", "tags", "answers" ], "properties": { "tags": { "type": "array", "items": { "type": "string" } }, "answers": { "type": "array", "items": { "type": "object", "properties": { "date": { "type": [ "string", "null" ] }, "link": { "type": "string" }, "score": { "type": "integer" }, "author": { "type": [ "string", "null" ] }, "accepted": { "type": "boolean" }, "answer_text": { "type": "string" } } } }, "question_link": { "type": "string" }, "question_text": { "type": "string" }, "question_title": { "type": "string" } }}- Price
- 1 credit per completed run (1¢ with pay as you go); failed runs are free.
- Method
stackoverflow.com/get_answer- Returns
- question title, text, link, tags, answers (text, score, accepted, author, date, link)
Use it from your agent
Give your agent this line. It reads SKILL.md, gets a Fous API key and connects the Fous MCP server. Its run then takes the method stackoverflow.com/get_answer with the inputs above.
Ask your agent
- How do I reverse a list in Python without using reverse()?
- Find the top accepted answer for why does my JavaScript promise return undefined
- Show me the best answers for merge two sorted arrays in Java
- Get the top 2 answers for git push rejected non-fast-forward error on stackoverflow.com
- What is the most upvoted answer about SQL joins versus subqueries performance?
See more
All Stack Overflow methodsFinds Stack Overflow programming questions matching plain-language search words, optionally filtered by tag and answer status, with a chosen sort order.
stackoverflow.com/search_questionsGets a Hacker News story and its comments in the order shown on the site. The story can be given as a discussion link or as words from its title. Deleted and flagged comments are left out.
news.ycombinator.com/get_discussionLists current Hacker News stories in rank order from the top, newest, best, Ask HN, Show HN or jobs list.
news.ycombinator.com/list_front_pageFinds public Reddit posts by topic, optionally in one community, for a time window and sort order. Returns up to 100 posts in Reddit search order with score, comment count, text and link.
reddit.com/search_postsSearches Hacker News stories or comments by words, date range and sort order. Comments include their parent story's website link when one exists; text-only stories have no website link.
news.ycombinator.com/search_storiesFinds a place on Google Maps by name and location and returns its public reviews in the chosen order.
google.com/get_place_reviewsSearches public Bluesky posts for words, optionally ordered by latest or top and filtered by date, author or language. Search indexing may lag behind new posts.
bsky.app/search_postsFinds a Substack newsletter by name or web address and returns its latest public posts with dates, authors, access level and engagement counts.
substack.com/list_newsletter_posts