# Answer a run's questions

Source: https://docs.coderhelm.com/api/reference/runs/answer-run

`POST /api/runs/{run_id}/answer`

Answers the questions a `needs_input` run asked (its `questions`) and continues the work: the answers are posted on the ticket or issue as a reply from you, kept on the run, and the ticket starts again as a new run whose plan reads them word for word. The old run becomes `retried` with `continued_run_id` set. A run that isn't `needs_input` any more (answered, retried or closed meanwhile) is refused with `409`.

## Authentication

A team API key: `Authorization: Bearer chk_...`. The key needs the `runs` scope. See [Authentication](https://docs.coderhelm.com/api/authentication).

## Parameters

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `run_id` | string | yes | The run's id. |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `answers` | array of GivenAnswer | yes | One entry per question answered. Questions left out (or blank) stay open; at least one needs an answer. |
| `answers[].answer` | string | yes | The answer, in plain words. At most 4000 characters. |
| `answers[].question_id` | string | yes | The question's `id` from the run's `questions`. |

## Responses

### 200

The work continues with the answers.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `comment_url` | string or null | no | The reply on the ticket or issue, when its address is known. |
| `posted` | boolean | yes | Whether the answers were posted on the ticket or issue. |
| `run_id` | string | yes | The id of the run that continues the work. It shows in `GET /api/runs/{run_id}` once it starts, within seconds. |
| `status` | string | yes | `continuing`: the ticket is queued again with the answers. |

Headers: `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`.

### 400

No answer written, an answer too long, or a question the run didn't ask.

### 401

The key is missing, malformed, revoked or expired, or the person who made it left the team.

### 403

The key lacks the scope this endpoint needs (`missing_scope`).

### 404

No run with this id in the team.

### 409

The run isn't waiting for an answer, or asked nothing to answer here.

### 429

Over the key's rate limit (`rate_limited`), or, for endpoints that start work, over the team's monthly token limit (`token_limit_reached`).

Headers: `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`, `Retry-After`.

### 500

Something failed on CoderHelm's side. Safe to retry reads.

## Example request

cURL:

```bash
curl -X POST 'https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/answer' \
  -H "Authorization: Bearer $CODERHELM_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "answers": [
    {
      "answer": "Production only. Staging keeps the old limit.",
      "question_id": "q1"
    }
  ]
}'
```

TypeScript:

```ts
const res = await fetch("https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/answer", {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CODERHELM_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
      "answers": [
        {
          "answer": "Production only. Staging keeps the old limit.",
          "question_id": "q1"
        }
      ]
    }),
});
if (!res.ok) {
  const { error, code } = await res.json();
  throw new Error(`${res.status} ${code}: ${error}`);
}
const data = await res.json();
```

Python:

```python
import os
import requests

headers = {
    "Authorization": f"Bearer {os.environ['CODERHELM_API_KEY']}",
}
body = {
    "answers": [
        {
            "answer": "Production only. Staging keeps the old limit.",
            "question_id": "q1",
        },
    ],
}
res = requests.request("POST", "https://api.coderhelm.com/api/runs/01JB8X6F4M2C9QZ3T7V5W1K0HA/answer", headers=headers, json=body)
if not res.ok:
    raise RuntimeError(f"{res.status_code}: {res.json().get('error')}")
data = res.json()
```

## Example response

```json
{
  "comment_url": "https://github.com/acme/web/issues/42#issuecomment-2211",
  "posted": true,
  "run_id": "01JB8Z3N5Q7S9V1X3Z5B7D9F1H",
  "status": "continuing"
}
```
