Skip to main content
Every request to the Ragen AI API must include a valid Bearer token. You generate that token by creating an API key in your instance’s Settings dashboard. The key is scoped to your organization and to what it may read — one assistant, or the knowledge base — and it cannot be retrieved after it is first shown to you.

Create an API key

Follow these steps inside your Ragen instance to generate a new key:
1

Open API Keys

Log in to your Ragen instance, then navigate to Organization → API keys.
2

Create a new key

Click Create API Key and give the key a descriptive name.
3

Choose what the key can reach

Pick a scope. The whole knowledge base — the default — lets the key answer from the documents that belong to no assistant. One assistant binds the key to a single assistant, and the key is then refused for any other. The choice is made here and cannot be changed afterwards; to move a key to a different assistant, create a new one.
4

Configure optional settings

Enable Debug mode if you want API conversations saved as threads visible in the API threads tab. This is useful during development but should be disabled for production keys handling sensitive queries.
5

Copy the key immediately

Click Create. The full key is displayed only once. Copy it now and store it in a secrets manager or environment variable — only a masked version is kept for display afterward.
Your API key is a credential equivalent to a password. Never commit it to source control, log it, or expose it in client-side code. If a key is compromised, deactivate it immediately from Organization → API keys and generate a replacement. Deactivated keys cannot be reactivated.

API key format

Every Ragen API key follows this structure:
The sk- prefix signals that the value is an API secret key. The <keyId> portion identifies the key; the <secret> portion is the credential that authenticates the request. Both parts are required.

Passing the Authorization header

Include the key as a Bearer token in the Authorization header of every request:

With the TypeScript SDK

The SDK reads your key from the RAGEN_API_KEY environment variable by default, so you rarely need to pass it explicitly:
You can also supply the key inline, but prefer the environment variable approach to avoid leaking credentials:

What a key can reach

An API key is bound to one organization — every operation acts on resources inside it, and a key can never be promoted to another organization. Within that organization, the scope you chose when creating the key decides what it reads. It is a boundary, not a default: a request that disagrees with it is refused rather than obliged. Omitting assistant_id is the normal case, and it is what makes Ragen callable from clients that speak the OpenAI format, which has no field for it. The scope narrows more than the answer. A key bound to one assistant lists only that assistant from GET /v1/assistants, sees only its files from GET /v1/files, and cannot create or delete an assistant at all — including the one it is bound to, since deleting it would revoke the key’s own context. A knowledge-base key sees every assistant its organization owns, and the files that belong to none of them.
A key whose assistant is later deleted is refused rather than widened: it does not fall back to the knowledge base. Create a new key.

Whose permissions a key carries

The scope picks where a key reads. What it reads there follows the person who created it. Every retrieval made with a key — chat, chat completions, search, and the MCP tools, which forward the key to these endpoints — applies that person’s document permissions, exactly as the web app does for them: their organization role and their teams decide which files can enter a result. So a key created by a member returns only what that member can open, and a file its owner shared with nobody stays out of answers for other members’ keys. Organization admins are the exception: they can see user-owned files (see Document permissions), so a key created by an admin can retrieve such a file too. Give an agent a key created by the person it acts for, or by an account whose permissions you intend it to have — not an admin’s key by default.
The creator’s role and team memberships are read on every request, not frozen when the key is created: remove them from a team and their keys lose that team’s documents on the next call.

Debug mode

Each API key has an optional Debug mode toggle you can enable when creating the key. When debug mode is on:
  • Every API conversation is persisted as a thread on the server.
  • The saved threads appear in the API threads tab inside your Ragen instance.
  • This lets you inspect the full context, retrieved documents, and generated responses for each call.
Disable debug mode for production keys to avoid storing user conversations unnecessarily. You can create a separate debug key for development and keep your production key clean.

Error responses

The API returns standard HTTP status codes for authentication failures. Handle these in your application to surface clear error messages to users:

TypeScript SDK error classes

The SDK surfaces authentication failures as typed errors you can catch and handle: