Skip to main content
This guide explains how to show Captide results in a React frontend, and open their sources in the Document Auditing SDK’s viewer.
Never expose your Captide API key in frontend code! The examples below call the backend proxy from the Backend Integration guide: POST /api/chunks, GET /api/documents/:id and POST /api/agent-stream.

React Integration

Basic Document Viewer Setup

Wrap your app in DocumentViewerProvider with a fetchDocumentFn that loads a document from your backend. Then call loadDocument(documentId, { page, snippet }) to open a document at a page and highlight a passage. Here, each chunk returned for a query gets a button that opens its source:

Streaming Response Example

The agent stream is a sequence of data: lines, each holding a JSON event (see Example 5 in the Quickstart for the event types). The example below:
  • shows thinking events as a status line;
  • builds the answer from message events, and replaces it with content_final when that arrives;
  • keeps the sources event, which maps each citation (#43c00004, #43c00004:2, …) to its chunk;
  • turns each citation into a link that opens the source page and highlights the cited excerpt.
A network read can end in the middle of a line, so the parser keeps the unfinished part until the next read.
The answer is Markdown. In a real application, render it with a Markdown renderer (such as react-markdown) and replace citations with links in its output.

Next.js Integration

With Next.js, the proxy routes can be route handlers. This one serves documents to the viewer, mapped to the SDK’s Document fields: