> ## Documentation Index
> Fetch the complete documentation index at: https://docs.htsapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Autocomplete

> Low-latency suggestions for code/description typeahead search

Fast prefix search for UI typeahead. Returns suggestions based on code or description matches. Optimized for real-time search experiences.

## Parameters

| Parameter | Type    | Required | Description                                      |
| --------- | ------- | -------- | ------------------------------------------------ |
| `q`       | string  | Yes      | Search query (min 2 chars, max 200 chars)        |
| `limit`   | integer | No       | Maximum number of results (default: 10, max: 20) |

## Example Request

```bash theme={null}
curl -X GET "https://htsapi.com/v1/autocomplete?q=telephone&limit=10" \
  -H "Authorization: Bearer your_hts_api_key"
```

## Example Response

```json theme={null}
{
  "suggestions": [
    {
      "code": "8517.12.00",
      "description": "Telephone sets, including telephones for cellular networks or for other wireless networks",
      "score": 95
    },
    {
      "code": "8517.11.00",
      "description": "Base stations",
      "score": 80
    },
    {
      "code": "8517.62.00",
      "description": "Machines for the reception, conversion and transmission or regeneration of voice, images or other data",
      "score": 75
    }
  ]
}
```

## Behavior

* **Code queries**: If the query starts with a number, searches by code prefix
* **Text queries**: If the query starts with text, performs full-text search on descriptions
* **Scoring**: Results are scored by relevance (higher is better)

## Use Cases

* Typeahead search boxes
* Quick code lookup
* Search suggestions
* Real-time search experiences


## OpenAPI

````yaml GET /autocomplete
openapi: 3.0.1
info:
  title: HTS API
  description: >-
    An API for HTS and HS Codes - Enabling supply chain organizations to scale
    with reliable data
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://htsapi.com/v1
security:
  - bearerAuth: []
paths:
  /autocomplete:
    get:
      summary: Autocomplete
      description: >-
        Fast prefix search for UI typeahead. Returns suggestions based on code
        or description matches.
      parameters:
        - name: q
          in: query
          required: true
          description: Search query (minimum 2 characters)
          schema:
            type: string
            minLength: 2
            maxLength: 200
        - name: limit
          in: query
          description: 'Maximum number of results (default: 10, max: 20)'
          schema:
            type: integer
            minimum: 1
            maximum: 20
            default: 10
      responses:
        '200':
          description: Autocomplete suggestions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AutocompleteResponse'
        '400':
          description: Bad request - Query too short or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    AutocompleteResponse:
      type: object
      properties:
        suggestions:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
                nullable: true
              description:
                type: string
              score:
                type: integer
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        message:
          type: string
        retry_after:
          type: integer
          description: Seconds to wait before retrying (for 429 errors)
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: 'API key as Bearer token. Format: Bearer your_hts_api_key'

````