# Replit

Replit Agent builds web apps from a chat prompt. You'll add the Ideal Postcodes Address Finder with our [React component](/docs/address-finder/react.md), and store your API key in Replit's **Secrets** when Agent asks for it.

## What you'll add

The [Ideal Postcodes Address Finder](/docs/address-finder.md) on any address form, via its [React component](/docs/address-finder/react.md).

## 1. Get an API key

* Quick test: paste `ak_test` as your key. Capped at 5 lookups/day. Will break in production.
* Real key: [sign up](https://account.ideal-postcodes.co.uk/users/sign_up) for a free trial balance.

## 2. Starter prompt

Paste this into the Replit Agent chat:

```text
Find every address form in this app and list them, then ask me to
confirm which ones should get the Ideal Postcodes Address Finder
before wiring anything up.

For each form I confirm, add autocomplete using the
@ideal-postcodes/react component:

- Install the @ideal-postcodes/react package.
- Render its <AddressFinder> component on that form. Read the selected
  address from the onAddressRetrieved callback and update the form's
  state.
- Read the API key from a Repl Secret named IDEAL_POSTCODES_API_KEY and
  pass it as the apiKey prop. If the app uses Vite, expose it as
  VITE_IDEAL_POSTCODES_API_KEY and read via import.meta.env. Prompt me
  for the value if it isn't set.
- Reference docs: https://docs.ideal-postcodes.co.uk/docs/address-finder/react.md
```

For multi-turn projects, add a one-liner to `replit.md` (the file Agent reads on every turn) so it stays on the SDK:

```text
Ideal Postcodes Address Finder: @ideal-postcodes/react, docs at
https://docs.ideal-postcodes.co.uk/docs/address-finder/react.md
```

## 3. Lock down the key

1. When you're ready to go live, apply the appropriate [Allow URLs](/docs/guides/api-key-secure.md#allow-urls) setting to your key.
2. Add the origins your app runs on, e.g. `*.replit.dev` (workspace preview), `*.replit.app` (deployments), and `*.yourdomain.com` (production).

## Troubleshooting

* **403 `allowed_url_mismatch` in the workspace preview**: add `*.replit.dev` to Allowed URLs.
* **Suggestions never appear and the network tab shows no calls**: the key isn't reaching the browser. In a Vite app, rename the Secret to `VITE_IDEAL_POSTCODES_API_KEY` and reference it via `import.meta.env.VITE_IDEAL_POSTCODES_API_KEY`.
* **Server errors land in the Console pane, browser errors in the Preview's DevTools**: if Agent is "fixing" the wrong layer, check the other pane and paste the real error back into chat.

## Need help?

* File an issue: [github.com/ideal-postcodes/feedback](https://github.com/ideal-postcodes/feedback/issues)
* Email: <support@ideal-postcodes.co.uk>
