/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
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 extendRagenError. 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).