# Ask endpoints

> Create a question, wait for the answer with long polling, cancel it, and receive the signed callback.

These endpoints push a question to a device and hand the answer back. For a guided introduction and the MCP tools, see [Ask and wait for an answer](/docs/agents/ask).

| Method | Path | What it does |
|---|---|---|
| `POST` | `/ask` | Create a question and push it |
| `GET` | `/ask/{question_id}` | Read the question, optionally waiting for the answer |
| `DELETE` | `/ask/{question_id}` | Cancel the question |

## POST /ask [#post-ask]

Creates a question and pushes it to the device as a time-sensitive notification. Accepts JSON, form data, or query parameters. Query parameters win over the body. Counts as one push.

<TypeTable
  type={{
    device_key: { type: "string", description: "The device to ask.", required: true },
    title: { type: "string", description: "The question, shown as the notification title. Up to 200 characters.", required: true },
    body: { type: "string", description: "More context under the question. Up to 2,000 characters." },
    options: { type: "string[]", description: "Up to 4 choices, each up to 30 characters, all different. In a form or query, use a comma-separated string." },
    allow_text: { type: "boolean", description: "Allow a typed answer. You need options, allow_text, or both." },
    placeholder: { type: "string", description: "Hint in the text field. Up to 60 characters." },
    timeout: { type: "integer", description: "Seconds until the question expires, 60 to 604800.", default: "3600" },
    callback_url: { type: "string", description: "An http or https URL. Opush POSTs the answered question here once." },
    group: { type: "string", description: "Inbox group for the question." },
  }}
/>

```bash
curl https://opu.sh/ask \
  -H "Content-Type: application/json" \
  -d '{"device_key":"YOUR_KEY","title":"Merge PR #42?","options":["Merge","Close"],"callback_url":"https://example.com/opush"}'
```

### Response: 201 Created [#response-201-created]

```json
{
  "question_id": "q_aLvBJaVvMvbingXOp9eapf",
  "answer_url": "https://opu.sh/ask/q_aLvBJaVvMvbingXOp9eapf",
  "expires_at": "2026-11-04T10:30:00Z",
  "callback_secret": "ocs_…"
}
```

| Field | Description |
|---|---|
| `question_id` | `q_` plus 22 characters. It's also the secret for reading the answer. |
| `answer_url` | Where to `GET` or `DELETE` the question |
| `expires_at` | When the question expires |
| `callback_secret` | Only when you passed `callback_url`. Use it to check the callback signature. |

## GET /ask/\{question_id\} [#get-askquestion_id]

Returns the question. With `wait`, the request stays open until the status is no longer `pending` or the time runs out.

| Query | Description |
|---|---|
| `wait` | Seconds to wait, 0 to 50. Default 0 (reply right away). |

### Response: 200 OK [#response-200-ok]

```json
{
  "question_id": "q_aLvBJaVvMvbingXOp9eapf",
  "status": "answered",
  "title": "Merge PR #42?",
  "body": null,
  "options": ["Merge", "Close"],
  "allow_text": false,
  "created_at": "2026-11-04T09:30:00Z",
  "expires_at": "2026-11-04T10:30:00Z",
  "answer": { "option": "Merge", "option_index": 0, "text": null, "answered_at": "2026-11-04T09:30:41Z" }
}
```

| Field | Description |
|---|---|
| `status` | `pending`, `answered`, `expired`, or `cancelled` |
| `answer` | `null` until answered. Otherwise `option` and `option_index` (both `null` for a text-only answer), `text` (`null` if none), and `answered_at`. |

Only the first answer is accepted. Questions are deleted 30 days after they were asked (once they have ended), and then return `404`.

## DELETE /ask/\{question_id\} [#delete-askquestion_id]

Cancels a pending question and removes its notification from the phone. Returns the question in the same format as `GET`. If the question had already ended, nothing changes and you get its current state.

## Callback [#callback]

When the question is answered, Opush sends one `POST` to `callback_url`:

```http
POST /opush HTTP/1.1
Content-Type: application/json
User-Agent: Opush/1.0
X-Opush-Signature: sha256=5c1f…

{"question_id":"q_…","status":"answered","title":"Merge PR #42?", …}
```

- The body is the same JSON as `GET /ask/{question_id}`.
- `X-Opush-Signature` is `sha256=` plus the hex HMAC-SHA256 of the raw body, keyed with `callback_secret`. Compare it in constant time. Examples are in [Ask and wait](/docs/agents/ask#get-a-callback).
- It's sent once with a 10-second timeout and isn't retried. If you miss it, poll `GET /ask/{question_id}`.
- Expired and cancelled questions don't trigger a callback.

## Errors [#errors]

```json
{ "error": { "code": "invalid_request", "message": "at most 4 options" } }
```

| Status | Code | When |
|---|---|---|
| `400` | `invalid_request` | Missing `device_key` or `title`, invalid `options`, no `options` and no `allow_text`, `timeout` out of range, invalid `callback_url`, or a body that isn't a JSON object |
| `401` | | Enterprise server with Basic Auth, without credentials (push response format) |
| `404` | `not_found` | Unknown device key or question |
| `429` | `rate_limited` | Too many pushes. Wait for `Retry-After` |
| `503` | `device_unreachable` | The device can't be reached (open Opush on it) |
| `503` | `upstream_error` | The push failed, or the server is busy |
