> For the complete documentation index, see [llms.txt](https://docs.wproofreader.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wproofreader.com/v6.12.0/api-reference/text-autocomplete-api.md).

# Text autocomplete API

`autocomplete` takes input text and returns possible completions.

**Command name:** `autocomplete`\
**Success status:** `200 OK`

### On this page

* [Common parameters](#common-parameters)
* [Parameters](#parameters)
* [Request examples](#request-examples)
* [Response schema](#response-schema)
* [Errors](#errors)

**Related**: [Overview](/v6.12.0/api-reference/overview.md), [Supported languages](/v6.12.0/features/supported-languages.md)

### Common parameters

`cmd` selects the command to run.

| Name  | Type   | Required | Description             |
| ----- | ------ | -------- | ----------------------- |
| `cmd` | string | Yes      | Must be `autocomplete`. |

These parameters work with any `cmd`.

| Name           | Type    | Required   | Description                                                        |
| -------------- | ------- | ---------- | ------------------------------------------------------------------ |
| `serviceid`    | string  | Cloud only | Cloud API key. Required for Cloud requests. Not used on-premises.  |
| `short_answer` | boolean | No         | JSON only. When `true`, shortens JSON keys to reduce payload size. |

See [Overview](/v6.12.0/api-reference/overview.md#common-parameters) for details.

### Parameters

These are parameters specific to `cmd=autocomplete`.

| Name   | Type   | Required | Description                                                                                                                       |
| ------ | ------ | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `text` | string | Yes      | Text to complete. The completion is returned as a suffix string. It can start with whitespace.                                    |
| `lang` | string | Yes      | Language code. Use a language where autocomplete is enabled. See [Supported languages](/v6.12.0/features/supported-languages.md). |

### Request examples

#### Example: completion found

Request:

{% tabs %}
{% tab title="GET" %}

```http
GET https://endpoint/api?cmd=autocomplete&lang=en_US&text=Welcome%20to
```

{% endtab %}

{% tab title="POST" %}

```http
POST https://endpoint/api
Content-Type: application/json

{
  "cmd": "autocomplete",
  "lang": "en_US",
  "text": "Welcome to"
}
```

{% endtab %}
{% endtabs %}

Response (`200 OK`):

{% tabs %}
{% tab title="JSON" %}
Use defaults: `format=json`, `short_answer=false`.

```json
{
  "result": {
    "suggestions": [
      " the"
    ]
  }
}
```

{% endtab %}

{% tab title="Short JSON" %}
Add `short_answer=true`.

```json
{
  "r": {
    "s": [
      " the"
    ]
  }
}
```

{% endtab %}
{% endtabs %}

#### Example: no suggestions

Request:

{% tabs %}
{% tab title="GET" %}

```http
GET https://endpoint/api?cmd=autocomplete&lang=en_US&text=Thank%20you
```

{% endtab %}

{% tab title="POST" %}

```http
POST https://endpoint/api
Content-Type: application/json

{
  "cmd": "autocomplete",
  "lang": "en_US",
  "text": "Thank you"
}
```

{% endtab %}
{% endtabs %}

Response (`200 OK`):

{% tabs %}
{% tab title="JSON" %}

```json
{
  "result": {
    "suggestions": []
  }
}
```

{% endtab %}

{% tab title="Short JSON" %}

```json
{
  "r": {
    "s": []
  }
}
```

{% endtab %}
{% endtabs %}

### Response schema

The response is always an object with a single `result`.

#### JSON (`short_answer=false`)

```json
{
  "result": {
    "suggestions": [
      " the"
    ]
  }
}
```

* `result` (object)\
  Always present.
* `result.suggestions` (array of strings)\
  May be empty. Each item is a completion suffix to append to `text`.

#### Short JSON (`short_answer=true`)

Key mapping:

* `result` → `r`
* `suggestions` → `s`

### Errors

Errors use the shared error format from [Overview](/v6.12.0/api-reference/overview.md#errors).

#### Language code not found (`400 Bad Request`)

```json
{
  "error": true,
  "message": "Language code not found."
}
```

#### Language has no autocomplete support (`403 Forbidden`)

```json
{
  "error": true,
  "message": "Command 'autocomplete' for language 'es_ES' is not enabled or unsupported."
}
```
