# Google Autocomplete

`POST https://api.serpkite.com/v1/autocomplete` · Credits: 0.5

Query suggestions as the user types. Useful for keyword research and query expansion.

Google's query suggestions for a prefix. Half a credit per call, which makes it cheap for keyword research and query expansion before a search.

## Request body

| Parameter | Type | Default | Description |
| --- | --- | --- | --- |
| `q` **required** | string |  | The search query. Required. Up to 2,048 characters. |
| `country` | string | `us` | Country to search from, as a two-letter ISO code (us, gb, de, in…). |
| `language` | string | `en` | Interface language, as a language code (en, de, fr, pt-BR…). |
| `format` | string | `json` | Response format. markdown is LLM-ready prose; compact is JSON with only the fields agents need. One of: `json`, `compact`, `markdown`. |

## Example request

cURL:

```bash
curl https://api.serpkite.com/v1/autocomplete \
  -H "Authorization: Bearer $SERPKITE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q":"how to learn","country":"us"}'
```

TypeScript:

```ts
import { SerpKite } from "serpkite";

const sk = new SerpKite(); // reads SERPKITE_API_KEY
const res = await sk.autocomplete({ q: "how to learn", country: "us" });
console.log(res.results.map((s) => s.value));
```

Python:

```python
from serpkite import SerpKite

sk = SerpKite()  # reads SERPKITE_API_KEY
res = sk.autocomplete("how to learn", country="us")
print([s.value for s in res.results])
```

## Response fields

| Field | Type | Description |
| --- | --- | --- |
| `request` | object | The normalised request, with defaults filled in: `endpoint`, `engine`, `q`, `country`, `language`, `location`, `num`, `page`, `device`, `autocorrect`… |
| `results[]` | array | `value`: the suggested query. |
| `meta` | object | `request_id`, `credits_used`, `cached`, `cached_at`, `engine` (the provider that answered), `route` (provider attempts, see [Search providers](https://serpkite.com/docs/providers)), `latency_ms`, `parse_quality` (`ok`, `partial`, `empty`), `resolved_urls`. |

## Example response

```json
{
  "request": {
    "endpoint": "autocomplete",
    "engine": "google",
    "q": "how to learn",
    "country": "us",
    "language": "en"
  },
  "results": [
    {
      "value": "how to learn python"
    },
    {
      "value": "how to learn spanish"
    },
    {
      "value": "how to learn guitar"
    },
    {
      "value": "how to learn to code"
    }
  ],
  "meta": {
    "request_id": "req_01J8ZK4M6Q2V7",
    "credits_used": 0.5,
    "cached": false,
    "engine": "google",
    "latency_ms": 1034,
    "parse_quality": "ok",
    "resolved_urls": true
  }
}
```

## Errors

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | `invalid_request` | A parameter is missing or invalid. |
| 401 | `unauthorized` | The API key is missing, invalid or revoked. |
| 402 | `insufficient_credits` | Your balance is too low. Buy a pack or wait for the monthly free grant. |
| 429 | `rate_limited` | Too many requests per second for your plan. Retry after the Retry-After header. |
| 503 | `upstream_error` | Google could not be fetched or parsed. Not billed; retry after Retry-After. |

All errors: https://serpkite.com/docs/errors

## Notes

- `format: "markdown"` is not available for this endpoint; the JSON is already small.

## Related

- [Tool calling for agents](https://serpkite.com/docs/guides/agents-tool-calling)