oslew docs
Console
Menu

Autocomplete

GET /v1/autocomplete suggests places and addresses while someone is still typing. It is asuggestion, not an answer: it says which names the text so far could become, ranked by how likely each is to be the one meant, and it claims nothing about any of them. The answer comes afterwards, fromgeocoding or validation, once the person has chosen.

curl
curl -G "https://api.oslew.com/v1/autocomplete" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'q=Museo Sou' \
  --data-urlencode 'near=19.4406,-99.2047' \
  --data-urlencode 'limit=5'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.autocomplete("Museo Sou", near="19.4406,-99.2047", limit=5)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.autocomplete("Museo Sou", { near: "19.4406,-99.2047", limit: 5 });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 299
ratelimit-reset: 1

{
  "query": "Museo Sou",
  "name": "Museo Sou",
  "context": null,
  "near": [
    19.4406,
    -99.2047
  ],
  "results": [
    {
      "doc": 348329,
      "name": "Museo Soumaya",
      "lat": 19.44062110346353,
      "lon": -99.20465953606559,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Miguel Hidalgo",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 2,
      "extra": 0,
      "prominence": 5,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 348400,
      "name": "Museo Jumex",
      "lat": 19.440393312940376,
      "lon": -99.20370756260536,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Miguel Hidalgo",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 2,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 365706,
      "name": "Soundspeedmx",
      "lat": 19.493992651778623,
      "lon": -99.24491233766965,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Naucalpan de Juárez",
        "region": null,
        "country": "MX",
        "category": "storage_facility",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 0,
      "prominence": 0,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 1930310,
      "name": "CALLE SOL",
      "lat": 19.451611114473653,
      "lon": -99.24551844723197,
      "precision": "street",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "México",
        "region": null,
        "country": "MX",
        "category": null,
        "postcode": "53570",
        "street": "CALLE SOL"
      },
      "matched": 1,
      "extra": 1,
      "prominence": 0,
      "provenance": {
        "name": "overture-addresses",
        "release": "2026-08-19.0",
        "license": "permissive (per-source, see record)"
      }
    },
    {
      "doc": 1930317,
      "name": "CALLE SOL",
      "lat": 19.45169432510208,
      "lon": -99.2456916222276,
      "precision": "street",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "México",
        "region": null,
        "country": "MX",
        "category": null,
        "postcode": "53570",
        "street": "CALLE SOL"
      },
      "matched": 1,
      "extra": 1,
      "prominence": 0,
      "provenance": {
        "name": "overture-addresses",
        "release": "2026-08-19.0",
        "license": "permissive (per-source, see record)"
      }
    }
  ],
  "mode": "all",
  "examined": 316,
  "postings": 42,
  "segments": 2,
  "took_us": 1399
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

The last word is a prefix

Every word but the last must match a whole word of a name, after the same normalising geocoding does — accents and case folded, punctuation dropped, abbreviations expanded. The last word is a prefix: Museo Souasks for names with the word museo and a word starting sou. It is expanded to the dictionary terms it starts, at most 256 of them, the most prominent and most common first.

Read the example with that in mind:

  • Museo Soumaya matches both words — matched: 2, extra: 0 — and is first.
  • Museo Jumex matches one, museo, and has one word the query did not cover (extra: 1). It comes next because its prominence, 2, is the highest among the one-word matches.
  • Soundspeedmx matches only the prefix. Every result with one matched word ranks below every result with two, however famous.
  • CALLE SOL is a repair, not a completion — see below.

examined is how many candidates the search scored: 316 for Museo Sou, against 24 for the single finished word in the next example. A short last word expands to many terms, and each brings its documents. That is the cost side of the minimum length below; the quality side is the cap — a one- or two-letter prefix reaches only the 256 most prominent and most common words it starts, so it finds the famous and misses the obscure until more is typed.

A house number is a word like any other, so it completes too: Calle Sol 12 can offer both number 12 and number 128 of a Calle Sol, each an address point at rooftop precision.

When nothing starts with what was typed

If no name in an index has a word beginning with the letters typed — within the near cell, when one is given — the last word is repaired as though it were misspelt: one edit, or two neighbouring letters swapped, for words of three letters or more. That is how Sou reaches CALLE SOL in the addresses, where no street word starts sou. The answer's mode is the best any index reached, and a completion carries no mode of its own, so a repaired suggestion is not marked as one. If that matters, compare the suggestion's name with what was typed before showing it.

A finished word

curl
curl -G "https://api.oslew.com/v1/autocomplete" \
  -H "Authorization: Bearer $GEO_API_KEY" \
  --data-urlencode 'q=Museo ' \
  --data-urlencode 'near=19.4406,-99.2047' \
  --data-urlencode 'limit=5'
Python
from oslew import Client

# The key is read from GEO_API_KEY.
client = Client(base_url="https://api.oslew.com")

answer = client.autocomplete("Museo ", near="19.4406,-99.2047", limit=5)
TypeScript
import { Client } from "@oslew/client";

// The key is read from GEO_API_KEY.
const client = new Client({ baseUrl: "https://api.oslew.com" });

const answer = await client.autocomplete("Museo ", { near: "19.4406,-99.2047", limit: 5 });
Response
HTTP/1.1 200 OK
content-type: application/json
ratelimit-limit: 100
ratelimit-remaining: 298
ratelimit-reset: 1

{
  "query": "Museo ",
  "name": "Museo",
  "context": null,
  "near": [
    19.4406,
    -99.2047
  ],
  "results": [
    {
      "doc": 348329,
      "name": "Museo Soumaya",
      "lat": 19.44062110346353,
      "lon": -99.20465953606559,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Miguel Hidalgo",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 5,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 348400,
      "name": "Museo Jumex",
      "lat": 19.440393312940376,
      "lon": -99.20370756260536,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Miguel Hidalgo",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 2,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 363808,
      "name": "Museo Tlatilca",
      "lat": 19.47909264584034,
      "lon": -99.23201194126051,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Naucalpan de Juárez",
        "region": null,
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 0,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 356964,
      "name": "Museo Tezozómoc",
      "lat": 19.496763243826795,
      "lon": -99.20690969990365,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Azcapotzalco",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 0,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    },
    {
      "doc": 346752,
      "name": "Museo Autoservicio",
      "lat": 19.443274519618697,
      "lon": -99.19955362835819,
      "precision": "poi",
      "precision_m": 6.756173533775122,
      "hierarchy": {
        "locality": "Miguel Hidalgo",
        "region": "CMX",
        "country": "MX",
        "category": "museum",
        "postcode": null,
        "street": null
      },
      "matched": 1,
      "extra": 1,
      "prominence": 0,
      "provenance": {
        "name": "overture-places",
        "release": "2026-08-19.0",
        "license": "CDLA-Permissive-2.0"
      }
    }
  ],
  "mode": "all",
  "examined": 24,
  "postings": 24,
  "segments": 2,
  "took_us": 1336
}

A real response, captured from the service at commit b8f4bde-dirty. Timing fields such as took_us differ on every call.

With one word, every result carries it, and they are ordered by prominence: Museo Soumaya (5), Museo Jumex (2), then three museums with none. This is the typical shape of a query one word long: the names that carry the word, famous first.

Parameters

ParameterDefaultIs
qrequiredThe text so far. Everything after the last comma is a context term — see below.
nearnonelat,lon. Keeps only what lies in the same city-sized cell as the point.
limit5Suggestions to return, clamped to 1–50.

near is a filter, not a bias

near keeps only what lies in the same level-10 cell as the point — about 10 km across, roughly a city (see cells and levels). Three consequences follow from it being a cell and a filter:

  • It is the cell containing the point, not a circle around it. A user near the cell's edge will not be offered a place a few hundred metres away on the other side of that edge.
  • It does not order by distance. Inside the cell, the ranking below decides; near only decides what is eligible.
  • It does not widen. If nothing in the cell matches, the answer is an empty list, not the best match elsewhere.

Without near the whole index is searched and prominence does the work, which is right for a search box that means "anywhere" and wrong for a delivery form in one city. Pass the user's position when you have it, or the centre of the map they are looking at, or the centre of the city they chose earlier in the form.

Ranking

  1. matched, most first: how many query words the name covered, the typed prefix counting as one.
  2. prominence, highest first: 0–15, log₂ of the place's Wikidata sitelinks where it is matched, else 0.
  3. extra, fewest first: words in the name the query did not cover.

Geocoding ranks the last two the other way round, and that is deliberate. A finished query for museowants the place called exactly that, so the shorter name wins. A half-typed mus wants the museum everyone means, so the famous one wins, even though its name is longer. Matching more of the words still outranks either.

No confidence, and why

Geocoding's confidence is calibrated: it is the observed precision of answers of the same shape on a scored set of finished queries (see reading a result). A prefix is not a finished query. Museo Sou has no right answer yet, only likelier and less likely continuations, and a number that looked like a probability would be one nobody had measured. So a completion carries no confidence, and no tied_at_top either.

A completion is deliberately smaller than a geocoding result:

FieldIs
name, lat, lonWhat to show, and where it is.
precision, precision_mpoi for a place. For an address row, what the row is, as in geocoding: rooftop for an address point with its number, street for a street.
hierarchyLocality, region, country, category, postcode and street, as the row records them; missing parts are null.
matched, extra, prominenceThe three ranking keys, so you can see why the order is what it is.
provenanceDataset, release and licence code of this row.
docThe row's position in its segment. Not a stable id: do not store it, and there is no route that looks a row up by it.

There is no normalized address, no confidence, no why and noattributes. At the top level the answer echoes query, the name andcontext it searched with, and near, and reports mode,examined, postings, segments and took_us.

Text after a comma

As in geocoding, the text after the last comma is a context term. Unlike geocoding, it is used raw. It must equal, after normalising, a value a row records — a place's locality, region or country, or an address's locality, postcode or country. There is no resolution through the divisions layer, no ISO-code matching, no containment test, no context_resolution in the answer, and no fallback when nothing matches.

That has two effects a form will meet:

  • Suggestions disappear while the context is being typed. Soumaya, Miguel Hid matches nothing, because Miguel Hid is not a locality any row records; the list comes back when the word is complete.
  • Only the row's own spelling works. A place whose row records its region as CMX is found by , CMX and not by , Ciudad de México — which geocoding would resolve through the divisions layer without trouble.

So for a free-typing box, send the text before the first comma and express "where" with near. Keep the whole text for the geocode that follows the selection, where context is resolved properly. A context term does help when your form already holds an exact value — a postcode field filled in before the street, say:Calle Sol, 53570 keeps only the addresses in that postcode.

The integration pattern

A search box that works well does four things, and each has a reason:

  • Debounce, 150–250 ms. Send only when typing pauses. A suggestion is useful when the person stops to look, not between two keystrokes, and every request takes a token from yoursearch bucket whether anyone sees its answer or not.
  • A minimum length, about three characters. Below it the prefix expands to the most common words it starts and the list is noise, at the highest cost per request (examined above).
  • Cancel the request in flight. Answers do not arrive in the order they were asked for; a slow answer to Mus must not replace a fast one to Museo S. Cancelling fixes the order. It does not save anything: the request has already taken its token, which is why the debounce, not the cancelling, is what keeps a search box within its rate.
  • Fail quietly. On a 429 or any error, show no suggestions and let the person keep typing. A suggestion that arrives after a retry is a suggestion for text that no longer exists.
TypeScript
// In the browser. It talks to your own server, never to the API.
const input = document.querySelector<HTMLInputElement>("#place")!;
const MIN_CHARS = 3;
const DEBOUNCE_MS = 200;
let timer: ReturnType<typeof setTimeout> | undefined;
let inflight: AbortController | undefined;

input.addEventListener("input", () => {
  clearTimeout(timer);
  timer = setTimeout(suggest, DEBOUNCE_MS);
});

async function suggest() {
  const q = input.value.split(",")[0];        // "where" goes in near, not after a comma
  inflight?.abort();                          // an older answer must not land after a newer one
  if (q.trim().length < MIN_CHARS) return render([]);
  inflight = new AbortController();
  try {
    const res = await fetch(`/api/suggest?q=${encodeURIComponent(q)}`, { signal: inflight.signal });
    render(res.ok ? (await res.json()).results : []);
  } catch (e) {
    if ((e as Error).name !== "AbortError") render([]);
  }
}

Keep the key on your server

A key grants every product its plan includes, with no referrer or IP restriction, so a key in a web page is a key anyone can copy (see authentication). The service also sends no CORS headers: a browser will refuse a cross-origin call to it anyway. The browser calls your server; your server calls the API. A minimal proxy is a dozen lines:

Python
# pip install flask — the oslew client itself has no dependencies
from flask import Flask, jsonify, request
from oslew import Client, GeoError

app = Flask(__name__)
client = Client(base_url="https://api.oslew.com")  # the key comes from GEO_API_KEY, on the server

@app.get("/api/suggest")
def suggest():
    q = request.args.get("q", "")[:200]
    near = request.args.get("near")  # the user's position or the map's centre, if you have one
    if len(q.strip()) < 3:
        return jsonify(results=[])
    try:
        answer = client.autocomplete(q, near=near, limit=5)
    except GeoError:
        return jsonify(results=[])  # fail quietly: a late suggestion is worth nothing
    return jsonify(results=[
        {"name": r["name"], "locality": r["hierarchy"]["locality"],
         "postcode": r["hierarchy"]["postcode"], "lat": r["lat"], "lon": r["lon"]}
        for r in answer["results"]
    ])
TypeScript
import { createServer } from "node:http";
import { Client } from "@oslew/client";

const client = new Client({ baseUrl: "https://api.oslew.com" }); // the key comes from GEO_API_KEY, on the server

createServer(async (req, res) => {
  const url = new URL(req.url ?? "/", "http://localhost");
  if (req.method !== "GET" || url.pathname !== "/api/suggest") {
    res.writeHead(404).end();
    return;
  }
  const q = (url.searchParams.get("q") ?? "").slice(0, 200);
  const near = url.searchParams.get("near") ?? undefined; // the user's position or the map's centre
  let results: object[] = [];
  if (q.trim().length >= 3) {
    try {
      const answer = await client.autocomplete(q, { near, limit: 5 });
      results = answer.results.map((r) => ({
        name: r.name, locality: r.hierarchy.locality, postcode: r.hierarchy.postcode, lat: r.lat, lon: r.lon,
      }));
    } catch {
      // fail quietly: a late suggestion is worth nothing
    }
  }
  res.writeHead(200, { "content-type": "application/json" }).end(JSON.stringify({ results }));
}).listen(8080);

Two things the proxy is for, beyond hiding the key. It passes on only what the browser should control —q and near, with limit fixed — so a page cannot ask for fifty results a keystroke. And it is now a public endpoint that spends your key's rate, so put it behind whatever already identifies your users — a session, a per-user rate limit — or anyone can empty your bucket through it. Theaddress form example puts the whole flow together.

On selection, ask for the full answer

When the person picks a suggestion, call /v1/geocode — or/v1/validate for an address they have completed with a number — and keep that answer, not the completion. Four reasons:

  • The completion has no normalized address to store, and no confidence or tied_at_top to branch on.
  • Geocoding resolves context through the divisions layer and falls back when it cannot; autocomplete does neither.
  • A street suggestion is a street, not a delivery address. The person still has to add the number, and validation is what says whether that number exists on that street.
  • doc is not an id you can come back with. The text is.

Send the chosen name with something that pins it — its postcode or locality as context — and the samenear:

Python
from oslew import Client

client = Client(base_url="https://api.oslew.com")

def resolve(choice: dict, near: str | None = None):
    where = choice["postcode"] or choice["locality"]
    q = f"{choice['name']}, {where}" if where else choice["name"]
    answer = client.geocode(q, near=near, limit=5)
    if not answer["results"] or answer["tied_at_top"] > 1:
        return None  # the choice did not pin one place: show the candidates instead
    return answer["results"][0]  # normalized, confidence, precision, provenance

That is one request to the address product per completed search — from a different bucket, so a burst of typing never slows it down.

Why search is its own product

A completed address costs one geocode and anywhere from five to fifteen autocomplete requests, one for each pause in typing. Sold together, from one bucket, the typing would crowd out the geocoding. As its own product, autocomplete — with nearby places — has its own bucket: a burst of typing in one form never makes a geocode elsewhere wait. Size the plan by how many people type at once, not by how many addresses you resolve: with a 200 ms debounce one person typing steadily sends at most five requests a second, and usually far fewer. See products and plans for which plans include search and at what rate.

Endpoints

GET/v1/autocompletesearch

Complete text being typed: the last token is a prefix, prominence ranks before name length, and no confidence is claimed.