# 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](/api-reference/overview.md), [Supported languages](/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](/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](/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](/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."
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wproofreader.com/api-reference/text-autocomplete-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
