Developers · Cortex SDK

Add a cited knowledge agent to your app with the Cortex SDK

Uthereal Cortex turns your documents into an AI agent that answers with claim-level citations — every claim opens the exact PDF page with the passage highlighted. Create an agent, download a generated TypeScript SDK, and let your AI coding tool wire it in — no vector database, no chunking pipeline, no citation UI to build.

Works with Lovable · Codex · Claude Code · Cursor · Windsurf · GitHub Copilot

Your app → Cortex, in 3 lines
const id = await cortex.createConversation();
for await (const u of cortex.ask(id, { message })) render(u);
<CitedAnswer answer={saved.answer} loadPdf={cortex.pdf} … />

“Seedlings grew toward the window. [7]

[7] Garden Guide · page 3 · passage highlighted

When to use Uthereal Cortex

The knowledge-agent API for apps that must show their sources

Choose Cortex when your application needs answers grounded in a specific body of knowledge — and users need to see where every answer came from.

  • Add a chat assistant that answers from your own PDFs, manuals, policies, books or research
  • Build RAG without wiring a vector database, chunking, embeddings, reranking and prompts by hand
  • Show sources users can verify: every claim opens the exact PDF page, highlighted
  • Fetch ranked passages as JSON to power your own LLM or workflow
  • Serve regulated, knowledge-heavy users who need traceable answers and data control
  • Ship from Lovable, Supabase, React, Vite, Next.js, Node or Deno

Not for open-web search or tasks that don't need grounding in your own knowledge base.

How it works

From documents to a cited agent in your app — four steps

  1. 1

    Create your Cortex agent

    Upload your documents. Cortex ingests, indexes and structures them into a knowledge agent.

  2. 2

    Create a scoped API key

    Choose ask (cited answers + PDFs) and/or rag (retrieval). Store it in your server secrets.

  3. 3

    Download the integration kit

    Generated for your agent: AGENTS.md, typed SDK, OpenAPI spec, React components, tests and fixtures.

  4. 4

    Paste it into your AI coding tool

    Lovable, Codex, Claude Code or Cursor reads AGENTS.md and wires Cortex into your app.

Step 4

The prompt for Lovable, Codex, Claude Code or Cursor

Attach your downloaded integration kit, paste this prompt, and let your coding agent do the wiring. The kit's AGENTS.md tells it exactly what to reuse.

prompt.txt
Integrate Uthereal Cortex into this application using the attached Cortex integration kit.

1. Read AGENTS.md first, then README.md, integration.json and examples/README.md.
2. Preserve this repository's existing instructions, auth, history, quotas and UI conventions.
   Merge the kit guidance into our root AGENTS.md instead of overwriting it.
3. Copy the sdk/ directory intact. Use createCortexHandler (sdk/server.ts) on the server,
   createCortexBrowserClient (sdk/browser.ts) in the frontend, and CitedAnswer (sdk/react.ts) to render answers.
4. Keep CORTEX_SHARED_API_KEY in server secrets only. Never in VITE_* variables or browser code.
5. Map our existing user/session storage through the CortexStore interface.
6. Run pnpm test, pnpm check:edge and pnpm build, replay the fixtures, and report which checks passed.

Code

What the integration looks like

One authenticated endpoint. Your key stays on the server.

Server
import { createCortexHandler, type CortexStore } from "./sdk/server.ts";

const handler = createCortexHandler({
  config: {
    baseUrl: process.env.CORTEX_API_BASE_URL!,
    assistantId: process.env.CORTEX_ASSISTANT_ID!,
    apiKey: process.env.CORTEX_SHARED_API_KEY!, // server secret only
  },
  allowedOrigin: "https://your-app.example",
  authenticate: async (request) => {
    const user = await verifyYourApplicationSession(request);
    return user ? { id: user.id, externalUserId: user.cortexIdentity } : null;
  },
  store: yourStoreAdapter satisfies CortexStore,
});
// Mount at /cortex — Supabase Edge Functions, Deno, Node or Workers.

What you get

Everything a production knowledge agent needs

Claim-level citations

Answers carry GIST and CIT markers that resolve to claims and references with durable IDs.

PDF page + highlight

References include page, coordinates and dimensions. PdfEvidence renders the passage highlighted.

Rich evidence

PDF highlights, images, video intervals, YouTube snippets, tables with chart hints and catalogue records.

Streaming with memory

Session-aware answers with adjustable detail (succinct → detailed) and technicality (simple → technical).

Typed end to end

Generated OpenAPI 3.1, TypeScript types and Zod runtime validators. No guessing at payloads.

Tested, agent-ready kit

Stream parser, citation reducer, token refresh and ownership checks — with replay fixtures that need no key.

Secure by design

Scoped, revocable server keys. The browser only talks to your backend. Per-user checks before any PDF.

Sovereign by default

Built in Zurich by Uthereal AG on Swiss sovereign infrastructure with zero data retention.

Compare

Cortex vs. building RAG yourself

Uthereal Cortex compared with DIY RAG and basic vector-search APIs
CapabilityUthereal CortexDIY RAG on a cloud AI stackBasic vector-search API
Time to first cited answer in your appDownload kit, paste into AI toolDesign ingestion, index, prompts, API, UIBuild prompting, answers and UI
Ingestion, chunking, indexingManagedYou build and tunePartly — you chunk and embed
Generated answers with session memoryIncludedYou buildNot included
Claim-level citations with durable IDsIncludedYou design the formatNot included
Open cited PDF page with highlightIncluded (React)Custom buildNot included
Retrieval-only JSON endpointIncludedYou buildCore feature
Typed SDK, OpenAPI, runtime validatorsGenerated per agentYou writeVaries
Instructions for AI coding agentsAGENTS.md in every kitNoneRare
Test fixtures without API keysIncludedYou writeRare

Reference

API at a glance

Base URL: https://agent.uthereal.ai/api/functions/v1/api-server-proxy · Headers: Authorization: Bearer <assistant key>, X-App-Code: selfserve

Uthereal Cortex external API operations
OperationMethod and pathBody and scope
AskPOST /external/v1/assistants/{assistant}/sessions/{external_session}/ask{ id_user, message, detail_level?, technicality_level? } → NDJSON stream. Scope: ask
RAGPOST /external/v1/assistants/{assistant}/rag{ query, id_user?, max_results? (1–20), datasource_ids? (≤50) } → JSON. Scope: rag
PDFGET /chat/reference/pdf/{token}?page={page}Cited page slice with X-External-User-Id. Scope: ask
RefreshPOST /chat/reference/pdf/refreshRenews an expired PDF reference once from saved IDs. Scope: ask

SDK entry points

sdk/core.ts

Generated OpenAPI types, Zod validators, readAnswers, mergeAnswer, resolveMarker, pdfLocation.

sdk/server.ts

createCortexHandler, CortexStore, CortexClient — server only, holds the API key.

sdk/browser.ts

createCortexBrowserClient — create, ask, rag, pdf against your own endpoint.

sdk/react.ts

CitedAnswer and PdfEvidence components for React 18 and 19.

sdk/adapters/supabase-server.ts

Supabase auth + storage adapter for Edge Functions.

sdk/adapters/supabase-browser.ts

Supabase browser adapter for authenticated fetch.

Requirements: TypeScript; React 18 or 19 for the components; Zod, TanStack Query 5, React-PDF 9. The runnable example uses Node 22, pnpm 10, Deno 2 and the Supabase CLI.

Errors: 400/422 input · 401 invalid or revoked key · 403 missing scope · 404 not found · 502/503/504 transient. Keep X-Request-ID for support. Full guide for AI tools: cortex.md · llms.txt

FAQ

Questions developers ask

What is Uthereal Cortex?

A platform that turns an organisation's knowledge base into an AI agent that answers with verifiable citations, callable from any application through an API and a TypeScript SDK.

Can I use Cortex with Lovable?

Yes. Download the integration kit for your agent and give it to Lovable. It includes a Supabase Edge Function handler, a Supabase auth adapter and React components that match the Lovable stack.

Does it work with Codex, Claude Code and Cursor?

Yes. Every kit ships an AGENTS.md that tells coding agents what to reuse and what not to rewrite, plus tests they can run to verify the integration.

Is Cortex a RAG API?

Both an answer API and a RAG API. Use ask for streamed, cited answers, or rag for ranked retrieval results to feed your own model.

Where does my API key go?

Only in your server secrets, for example Supabase Edge Function secrets. The browser calls your backend, which calls Cortex.

Can I test without credentials?

Yes. Run pnpm dev and open localhost:5173/?replay to render synthetic answers, citations and a highlighted PDF.

Do I need Supabase?

No. Supabase is an optional adapter. Implement authenticate and CortexStore for any backend that runs a Fetch API handler.

Ship a knowledge agent your users can trust

Create your agent, download the kit, paste it into your AI coding tool.

Machine-readable versions: /developers/cortex.md · /llms.txt