Skip to main content
This guide explains how to call the Captide API from your backend, using Node.js and Express. Your backend holds the API key and exposes the few routes your frontend needs, so the key never reaches the browser.

Node.js Integration

Express.js Example

The proxy below exposes three routes:
  1. POST /api/chunks returns the chunks relevant to a query.
  2. GET /api/documents/:id returns a document in the shape the Document Auditing SDK expects.
  3. POST /api/agent-stream streams the agent’s answer to the browser.
It uses the fetch built into Node.js 18 and later.

Environment Variables and Security

Always store your API key in environment variables or a secure configuration system, never hardcode it in your application code. Create a .env file in your project root:
Make sure to add .env to your .gitignore file to avoid committing sensitive credentials.

Error Handling

Errors from the Captide API are JSON objects with a detail field, returned with a standard HTTP status. detail is a message, except on 422, where it lists the invalid fields: fetch doesn’t throw on HTTP errors, so check response.ok and pass the status and detail on to your client, as the routes above do. Network failures (no response at all) do throw:

Rate Limiting

Your API key’s limits apply across everyone using your application. Rate-limit your own routes so that one user can’t use them up: