# 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.

- Page: https://fous.com/methods/stackoverflow.com/get-answer
- Method: `stackoverflow.com/get_answer`, version 1
- Website: stackoverflow.com
- Returns: question title, text, link, tags, answers (text, score, accepted, author, date, link)
- Effect: read (it gets data and changes nothing)
- Sign-in: none needed
- Cost: 1 credit per completed run (1¢ with pay as you go); failed runs are free
- Verified: Nov 2, 2026

## Inputs

| Field | Type | Required | In the run below | Description |
|---|---|---|---|---|
| `question` | string | yes | `"https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorte…` | A Stack Overflow question link or the question in plain words, e.g. how do I reverse a list in Python? |
| `max_answers` | integer | no | `3` | Number of answers to return, e.g. 3 (up to 10). Default 3. |

## Output

From a run on Oct 23, 2026, shortened. Its input:

```json
{
  "question": "https://stackoverflow.com/questions/11227809/why-is-conditional-processing-of-a-sorted-array-faster-than-of-an-unsorted-array",
  "max_answers": 3
}
```

Its output:

````json
{
  "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?"
}
````

## Run it

From code, with a Fous API key in `FOUS_API_KEY`; the answer's `data` holds the output:

```bash
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}}'
```

From an AI agent connected to the Fous MCP server: its `run` with the same method and input. To connect one, give it `set up https://fous.com/SKILL.md`.

## 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?

## Input schema

```json
{
  "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

```json
{
  "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"
    }
  }
}
```

## See more

- [Stack Overflow API: Search questions](https://fous.com/methods/stackoverflow.com/search-questions.md): Finds Stack Overflow programming questions matching plain-language search words, optionally filtered by tag and answer status, with a chosen sort order.
- [Hacker News API: Get discussion](https://fous.com/methods/news.ycombinator.com/get-discussion.md): Gets 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.
- [Hacker News API: List stories](https://fous.com/methods/news.ycombinator.com/list-front-page.md): Lists current Hacker News stories in rank order from the top, newest, best, Ask HN, Show HN or jobs list.
- [Reddit API: Search posts](https://fous.com/methods/reddit.com/search-posts.md): Finds 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.
- [Hacker News API: Search stories](https://fous.com/methods/news.ycombinator.com/search-stories.md): Searches 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.
- [Google API: Get place reviews](https://fous.com/methods/google.com/get-place-reviews.md): Finds a place on Google Maps by name and location and returns its public reviews in the chosen order.
- [Bluesky API: Search posts](https://fous.com/methods/bsky.app/search-posts.md): Searches 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.
- [Substack API: List newsletter posts](https://fous.com/methods/substack.com/list-newsletter-posts.md): Finds a Substack newsletter by name or web address and returns its latest public posts with dates, authors, access level and engagement counts.
- [All Stack Overflow methods](https://fous.com/methods/stackoverflow.com.md)
