Use case
Address autocomplete and validation in a checkout form
Address autocomplete in a checkout works best as two calls at two moments: suggestions while the shopper types, routed through your own backend because the API key must never reach the browser, and a validation check when the form is submitted, whose verdict decides whether to accept the address, offer a correction or ask about one part. With oslew both run on the Search plan — suggestions on the Search rate, validation on the Address rate — so a burst of typing never spends the tokens the check at submit needs.
Last reviewed
A delivery address is the one field in a checkout where a typo costs real money later: a parcel returned, a courier’s second attempt, a support call. It is also the field shoppers find most tedious to type. The pattern below addresses both. Suggestions help the shopper pick an address the data knows instead of inventing a spelling; a check at submit catches what slipped through and says precisely which part to ask about.
Two moments, two calls
The form makes different requests at different times, to two products:
- While the shopper types, the page asks your server for suggestions, and your server asks the autocomplete API. That spends the Search product’s rate.
- When the shopper submits, the page sends the whole form to your server, which sends it to the address validation API and turns the verdict into the form’s next step. That spends the Address product’s rate.
Keeping them on separate products matters at busy moments. A sale can put hundreds of people in the address field at once, and their typing should never be able to make the check at submit wait for a token.
While the shopper types
The browser side is a small script with four habits:
- Wait for a pause. Start a short timer on each keystroke and send only when it expires, a couple of hundred milliseconds after the last key. A quick typist then sends one request per pause rather than one per letter.
- Wait for three characters or so. Shorter prefixes match too much to help.
- Discard stale answers. Abort the previous request when a new one starts, and ignore any answer that arrives after a newer question was asked, or a slow reply to an early prefix can overwrite a fresher list.
- Treat names as text. Place names come from open data, so insert them as text content, never as markup.
On the server, ask for a few more suggestions than you will show and keep the address kinds — address points, interpolated positions, address rows and streets — dropping named places, because a delivery form does not want the museum. A form that ships to businesses by name can keep places. When the shopper picks a suggestion, fill in the town, postcode and country from the suggestion’s recorded hierarchy, which saves typing and spelling in the fields that validation will check next.
The proxy between the page and the API
The browser cannot hold the key. The service sends no cross-origin headers, so a browser refuses the call anyway, and a key has no scopes or referrer restrictions — whoever copies it from a page can use every product on the plan. So the page calls your server, and your server is a narrow proxy, not an open one:
- Two routes with fixed parameters. The page supplies the text and nothing else; the server sets the endpoint and the result limit. Nobody can use your route to spend your key on arbitrary requests.
- A limit per visitor. Every shopper shares your key’s rate. Without a per-visitor limit of your own, one script typing in a loop slows suggestions for everyone. Key it on the forwarded client address or the session, not the load balancer’s socket address.
- Fail fast on HTTP 429. A person is waiting, so return an empty list or a quick error at once rather than sleeping out Retry-After. The form must work without suggestions; they are a help, not a dependency.
On submit: validate the parts
Send the street-and-number line as text, which lets validation find the house number at either end, and the town, postcode and country code as their own fields, using POST /v1/validate so the address travels in the request body rather than in a URL. If the house number field is empty, ask for it before validating at all: a verdict only grades the parts it receives, and a street with a postcode but no number can be confirmed against somebody else’s door.
Return a position to the page only for confirmed and corrected verdicts. On a partial or unconfirmed answer, the coordinates belong to whatever record was matched, not to the shopper’s address, and storing them would put a wrong pin on the order.
What to do with each verdict
| Verdict | What the form does | What to store |
|---|---|---|
| Confirmed | Accepts the address and moves on. | The graded parts and the position. |
| Corrected | Shows “Did you mean …?” with the corrected line, marking the changed parts and offering inferred ones as fill-ins. | The corrected version, only if the shopper accepts it; otherwise what they typed, flagged. |
| Partial | Highlights the parts that contradict the record — usually the number or the postcode — and asks the shopper to check them. | What the shopper confirms, flagged if it still disagrees. |
| Unconfirmed | Asks the shopper to check the street and number. | What they confirm, flagged for a look before dispatch. |
When to ask the customer
Ask about one part, once. The component grades name exactly which field disagrees, so the question can be specific — “we could not find number 48 on this street; is it right?” — rather than a generic warning over the whole block. A correction is always a question, never a silent rewrite: two edits can turn one real street name into another, and only the shopper knows which they meant.
Never make an unconfirmed or partial verdict a hard stop. New buildings, recently renamed streets and thinly covered areas all look like errors to a validator, and the cost of refusing a real customer is higher than the cost of a flagged order. Let the shopper keep their address after one prompt, and put the flag where your fulfilment team will see it. The conceptual difference between checking an address and locating one is covered in address validation vs geocoding.
Do not trust the browser’s copy
Anything the page holds, a shopper can edit, including a verdict your server sent back. When the order is placed, either validate again on the server or keep the server’s own answer keyed to the session, and store that. The same rule applies to the position: take it from your server’s record of the validation, not from a hidden form field.
Which plan
The Search plan covers both calls: $299 a month for 20 requests a second sustained, burst 100 of search and 20 requests a second sustained, burst 100 of address requests. Size it by how many shoppers are typing at the same moment, not by how many orders you take: a debounced shopper sends a few suggestion requests a second at most, and each submitted order costs one validation. There is no charge per keystroke and no monthly quota, so a busy day costs the same as a quiet one; the pricing page lists the rates on larger plans. Addresses from older orders that never went through this check can be tidied in bulk with the customer data clean-up workflow.
Bottom line
Suggest while the shopper types, validate when they submit, and let the verdict choose between accepting, suggesting and asking about one part. Keep the key on your server behind a narrow proxy, and never let a validator’s doubt cost you a real customer’s order.
Where this workflow falls short
- Validation grades only the parts it is sent. Without a house number, a street and postcode can come back confirmed against a neighbour’s record, so require the number before the form validates.
- An unconfirmed verdict can belong to a real address that is newer than the loaded data. Let the shopper keep what they typed and flag the order for a look, rather than refusing the sale.
- Autocomplete treats text after a comma as a raw term with no resolution of towns or regions, so suggest from the street line alone and let validation weigh the town and postcode.
- Suggestions come from the addresses and places loaded for the area. Where that data is thin, few suggestions appear, and the form has to work just as well when there are none.
Questions
Can a checkout page call the address API directly from the browser?
No, and it should not want to. The API answers no cross-origin browser requests, and a key opens every product on its plan to whoever holds it. The page talks to two routes on your own server — one for suggestions, one for the check at submit — and only the server holds the key.
What should a checkout do when an address comes back unconfirmed?
Ask the shopper to look at the street and number once, then accept what they confirm, flagged for someone to check before dispatch. Unconfirmed means the address did not match the data, which is also what a brand-new building looks like. Blocking the order on it turns a data gap into a lost sale.
Should a checkout form geocode the address or validate it?
Validate it. The shopper is still there, and validation says which part disagrees with the data, so the form can ask a precise question. A confirmed or corrected answer comes with a position too, so a separate geocode is not needed for most orders.
How many API requests does one checkout address use?
A handful of suggestion requests while the shopper types, one per pause, and one validation when they submit — plus one more if they fix a part and submit again. Suggestions come out of the Search rate and validation out of the Address rate, and neither is billed per request.