Skip to main content
Ragen exposes an OpenAI-compatible REST API at /v1 and an official TypeScript SDK — @webamigos/ragen-sdk-ts — that adds typed responses, streaming helpers, automatic retries, and waitUntilProcessed() for file uploads. If your language or runtime cannot use the SDK, every feature is also available over raw HTTP.

Prerequisites

Before making your first API call, make sure you have:

Running Ragen instance

A self-hosted Ragen deployment reachable at a known URL — for example, http://localhost:3001.

Project with documents

At least one project with documents uploaded to its knowledge base so the API has content to retrieve.

API key

An API key scoped to your organization and project. You’ll create one in Step 1.

Node.js 18+

Node.js version 18 or later for the TypeScript SDK. Earlier versions are not supported.

Steps

1

Create an API key

Open your Ragen instance in a browser, log in, and navigate to Settings → API Keys. Click Create API Key, give it a name, and select the project this key should access. You can also enable Debug mode at this point to save API conversations as threads for later inspection.Click Create, then copy the key immediately — it is displayed only once. A masked version is stored for display, but the full secret cannot be recovered after you leave this page.
2

Install the SDK

Add the SDK to your project using your preferred package manager:
3

Set environment variables

The SDK reads your credentials from the environment by default. Set both variables before running your application:
All examples below read from these environment variables. Never hard-code your API key in source code.
4

Send your first completion

Create a Ragen client and call chat.completions.create. The response is grounded in the project’s knowledge base — retrieval, reranking, and answer generation all happen server-side.
completion.ts
If most of your calls target the same project, set assistantId on the client once and omit it on every individual call:
5

Stream tokens

Use chat.completions.stream to receive tokens as they are generated. Iterate over the async stream or use streamToString when you just want the finished text:
stream.ts

Error handling

All SDK errors extend RagenError. Pattern-match on the subclass to handle specific HTTP statuses gracefully:
error-handling.ts
429 and 5xx responses are automatically retried with exponential backoff and jitter, up to maxRetries times (default 2).

SDK configuration options

Raw HTTP example

When the SDK is not available — for example in Python, Go, or shell scripts — call the same endpoint directly over HTTP:
Ragen serves an interactive Swagger UI at /v1/docs (OpenAPI JSON at /v1/docs/openapi.json). It is enabled by default and can be disabled by setting the SWAGGER_ENABLED=false environment variable on your instance.