Skip to Content
AeroSearch Docs
Quickstarts

TypeScript / Next.js quickstart

Reach a 200 search response from a Next.js App Router handler in under five minutes.

Save this server-only helper as lib/search.ts, then call searchDocs from your App Router handler or server action. It is not a route.ts module. The helper posts to Collection search and returns a response with a queryId.

Prerequisites

  1. A Project search-scoped API key (ask_…).
  2. A Collection id (col_…) with at least one Document.
  3. Node 22+ and a Next.js app (App Router).

Set AEROSEARCH_BASE_URL to your Cell search host (without a route), AEROSEARCH_API_KEY to a Project search key, and AEROSEARCH_COLLECTION to its Collection id. Set AEROSEARCH_END_USER_TOKEN only when your server supplies a real end-user token.

Sample

// generated-from-contract: contracts/openapi/v1.yaml
// Server-only helper for lib/search.ts — searchCollectionPost
// POST /v1/collections/col_help/search  (SearchRequest from contracts/openapi/v1.yaml)

export async function searchDocs(query: string) {
  const base = (process.env.AEROSEARCH_BASE_URL ?? "https://api.aerosearch.team").replace(/\/$/, "").replace(/\/v1$/, "");
  const collection = process.env.AEROSEARCH_COLLECTION ?? "col_help";
  const token = process.env.AEROSEARCH_END_USER_TOKEN;
  const response = await fetch(base + "/v1/collections/" + encodeURIComponent(collection) + "/search", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + process.env.AEROSEARCH_API_KEY,
      "Content-Type": "application/json",
      ...(token ? { "X-AeroSearch-End-User-Token": token } : {}),
    },
    body: JSON.stringify({ query, limit: 10 }),
  });
  if (!response.ok) throw new Error("Search failed: " + response.status);
  return response.json();
}

The data-inject-project-key attribute is a placeholder hook. Configure the environment variables above; this docs site does not provide a live auth integration.

Verify

From this repository, the local double verification executes the generated sample:

AEROSEARCH_BASE_URL=http://127.0.0.1:4418 AEROSEARCH_API_KEY=ask_search AEROSEARCH_COLLECTION=col_quickstart \
node tests/harness/quickstarts-daily/run.mjs typescript-nextjs

On this page