Skip to main content
Ensure fetchWithPayment wraps your HTTP client so 402 Payment Required flows are replayed automatically.

1. Issue a search query

const baseUrl = process.env.HORIZON_BASE_URL ?? 'https://api.horizon.new/v1';

const searchResponse = await fetchWithPayment(
  `${baseUrl}/search?q=workflow%20patterns&types=document,contribution&limit=5`,
);

const { results, nextCursor } = await searchResponse.json();
console.log('Top hit', results?.[0]);
Include types to restrict the sources you read from, and append filter parameters if you tagged records during extraction or contribution.

2. Use results synchronously

if (results.length === 0) {
  console.log('No matches found');
} else {
  for (const hit of results) {
    console.log(hit.type, hit.title, hit.snippet);
  }
}

3. Follow pagination

let cursor = nextCursor;

while (cursor) {
  const pageResponse = await fetchWithPayment(
    `${baseUrl}/search?q=workflow%20patterns&cursor=${encodeURIComponent(cursor)}`,
  );
  const page = await pageResponse.json();

  console.log('Page size', page.results.length);
  cursor = page.nextCursor;
}

4. Combine with downstream systems

  • Use the fields on result.source to route hits into personalization, analytics, or compliance reviews.
  • Pipe relevant excerpts into your retrieval augmented generation chain or product UI.
  • Store cursors if you need resumable scans for large exports.