# Ask the assistant

`POST /v1/ask`

Answers a question about the workspace by looking it up with the methods of this API. A change is never carried out by asking: the answer holds the change it proposes, and sending that back as run carries it out.

Needs the scope: `workspace:read`

## Body parameters

- `messages` (object[], required): The conversation so far, oldest first. The last message is the question. Up to 40 items.
- `messages[].role` (string, required): Who said it: `user` or `assistant`. One of: `user`, `assistant`.
- `messages[].text` (string, required): What was said. Up to 4,000 characters.
- `page` (string): The screen the person is on, so the answer can be about it. Up to 200 characters.
- `run` (object): A change the assistant proposed and the person confirmed. With it the change is made and no model is asked.
- `run.call` (string, required): The name of the method to run, such as `domains.create`. Up to 80 characters.
- `run.input` (Record<string, unknown>, required): The input for that method.

## Returns

- `object` ("ask_answer"): Always `ask_answer`.
- `text` (string): The answer, as plain text.
- `steps` (object[]): The methods that were run to find the answer.
- `steps[].call` (string): The method that was run.
- `steps[].title` (string): The method in a few words.
- `steps[].ok` (boolean): Whether it worked.
- `proposal` (object | null): A change the assistant wants to make and is waiting for a yes on, or `null`.
- `proposal.call` (string): The method the assistant wants to run.
- `proposal.title` (string): The method in a few words.
- `proposal.description` (string): What running it would do.
- `proposal.effect` (string): What it does to your data: `write`, `send` or `destroy`. One of: `read`, `write`, `send`, `destroy`.
- `proposal.input` (Record<string, unknown>): The input it would be run with.
- `result` (Record<string, unknown> | null): What a confirmed change returned, or `null`.

## Example

cURL:

```bash
curl -X POST "$OPENSEND_API_URL/v1/ask" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "messages": [
    {
      "role": "user",
      "text": "Which domains are not verified yet?"
    }
  ]
}'
```

TypeScript:

```ts
await opensend.ask.send({
  messages: [
    {
      role: 'user',
      text: 'Which domains are not verified yet?',
    },
  ],
})
```

CLI:

```bash
opensend ask send \
  --messages '[{"role":"user","text":"Which domains are not verified yet?"}]'
```

Answer:

```json
{
  "object": "ask_answer",
  "text": "Two domains are not verified yet: news.example.com is pending and example.org failed its last check.",
  "steps": [
    {
      "call": "domains.list",
      "title": "List domains",
      "ok": true
    }
  ],
  "proposal": null,
  "result": null
}
```
