---
title: "Algolia"
description: "Use Algolia for MainSDK search - application and API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping."
section: "integrations"
canonical: "https://mainsdk.dev/docs/integrations/algolia"
updated: "2026-10-28"
---

# Algolia

> Use Algolia for MainSDK search - application and API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping.

Canonical: https://mainsdk.dev/docs/integrations/algolia · Updated: 2026-10-28

Algolia is a hosted search service, and a driver behind [`search`](https://mainsdk.dev/docs/interfaces/search). Your app indexes records with `search.index()` and queries them with `search.query({ for: user })`, and MainSDK limits results to what the person searching may see. Pick Algolia when you want hosted, fast-as-you-type search for a catalogue or help centre without running a search server.

> **Note:** `search` has no spec yet. The calls and options on this page are provisional, taken from the catalog and the product requirements, and may change when the spec lands.

## Interfaces it serves

### Search (`search`)

- Status: Building for 0.4 · ships as a beta API
- Driver: `algolia` (Algolia, planned driver). later; not in the search spec for 0.4
- Docs: https://mainsdk.dev/docs/interfaces/search.md

```yaml
search:
  driver: algolia
```

Swap to another provider: `db`, `typesense`, `meilisearch`, `local`, `pgvector`.

## Before you start

You need an Algolia account.

1. **Create an application** and pick the region where its data is hosted, close to your users and in line with your data rules.
2. **Copy the application ID and an API key.** Algolia gives you an admin key, a search-only key, and lets you create keys with narrower rights. Use a key restricted to the indexes and operations the app needs, rather than the admin key, and keep it server side.
3. **Create the indexes** your app searches. Whether the driver creates them for you is [TBD].

Store the key in your secrets manager, never in code or a committed env file.

## Configure

```yaml title="main.yaml"
search:
  driver: algolia
  # key: secret:ALGOLIA_API_KEY   # suggested name; application ID, key and index names are [TBD]
```

Not decided yet: index names and fields, the document shape `search.index()` takes, and the connection settings per driver.

## Use it

```ts title="app/api/search/route.ts"
import { auth, search } from "mainsdk";

export async function GET(req: Request) {
  const session = await auth.require(req);
  const q = new URL(req.url).searchParams.get("q") ?? "";
  const hits = await search.query({ q, for: session.user, limit: 10 });
  return Response.json(hits);
}
```

Index a record when it changes with `search.index(product)`.

## Local development and testing

- **No account:** a `search` fake for `createTestApp()` from `@mainsdk/testing` arrives with the spec. Until then, use a separate Algolia application or index for development.
- **The test that matters:** prove a user never gets another user's records. When the fake lands, `chaos.on("search", { outage: true })` drills an Algolia outage.

## What MainSDK adds on top

- Results scoped to the person searching (`for: user`).
- The same `search.index()` and `search.query()` calls on every engine, so moving off Algolia is one line plus a re-index.
- Hits that can ground an AI answer through [`ai`](https://mainsdk.dev/docs/interfaces/ai) without leaking another customer's records.

See [Search and vector search](https://mainsdk.dev/docs/interfaces/search) for the full contract.

## Limits and notes

- `algolia` is a planned `search` driver for phase 2, and `search` has no spec yet.
- An index is a copy of your data, held in the Algolia region you chose. Keep `personal` and `sensitive` fields out of it unless the feature needs them; see [Data and regions](https://mainsdk.dev/docs/concepts/data-and-regions). MainSDK regions are US, EU and India.
- Never ship the admin key to the browser. How MainSDK scopes results when the browser queries Algolia directly is [TBD]; query through your server.

## Swap to or from it

```yaml title="main.yaml"
search:
  driver: algolia   # was typesense
```

> **Warning:** An index lives in the engine. Moving engines means re-indexing your records in the new one before you switch queries over.

## FAQ

**Can I use Algolia for vector search?** `search` covers vector search, but how a driver takes a vector is [TBD]. [pgvector](https://mainsdk.dev/docs/integrations/postgres) runs it inside your Postgres.

**Which key goes in `main.yaml`?** None directly. Store a restricted server key in your secrets manager and refer to it with `secret:NAME`.

## Next

- [Search and vector search](https://mainsdk.dev/docs/interfaces/search)
- [Typesense](https://mainsdk.dev/docs/integrations/typesense), [Meilisearch](https://mainsdk.dev/docs/integrations/meilisearch) and [Postgres](https://mainsdk.dev/docs/integrations/postgres)
- [Swap a driver](https://mainsdk.dev/docs/guides/swap-a-driver)
