Zero-Dependency Client SDK

Radiant automatically generates a zero-dependency Client SDK (radiant-sdk.ts) alongside your backend every time you compile. This standalone, perfectly-synced TypeScript file provides end-to-end type safety, real-time subscriptions, and native fetch bindings without requiring any external NPM packages.

Because the entire SDK logic and types exist in a single file, LLMs and AI Agents can read it directly without guessing your API surface. You can pass the SDK to an agent and say "build me a dashboard for my data"—it will instantly write flawless, fully-typed integrations against your Radiant backend on the first try.

Usage

You can import the generated SDK into your client application and initialize it using createRadiantClient.

import { createRadiantClient } from './radiant-sdk';

export const api = createRadiantClient({
  baseUrl: "http://localhost:3000",
  // Auto-inject your auth token into every request
  getToken: () => localStorage.getItem("token") 
});

Basic CRUD

The SDK automatically mirrors your collections and exposes strongly-typed methods:

// Create a user
const { data: newUser, error } = await api.users.post({ 
  name: "Alice", 
  email: "alice@example.com" 
});

// List users with filtering
const { data: activeUsers } = await api.users.get({
  query: {
    where: { status: "active" },
    limit: 10
  }
});

// Update a user
await api.users.patch(newUser.id, { status: "inactive" });

// Delete a user
await api.users.delete(newUser.id);

Authentication

If a collection is configured with auth: true (e.g. users), the SDK automatically centralizes its authentication endpoints under the .auth namespace.

// Register a new user
const { data: regRes, error: regErr } = await api.auth.register({ 
  email: "alice@example.com", 
  password: "securePassword123!" 
});

// Login
const { data: session } = await api.auth.login({ 
  email: "alice@example.com", 
  password: "securePassword123!" 
});

// The SDK can automatically use the session.accessToken if you configured getToken()
console.log("Logged in with token:", session.accessToken);

File Uploads (Multipart Form Data)

The SDK natively understands File and Blob objects. If you pass a File in your payload, the SDK engine seamlessly converts the entire request into a multipart/form-data payload under the hood. You never have to manually construct FormData.

const fileInput = document.getElementById("avatar");
const file = fileInput.files[0];

await api.users.patch(userId, {
  name: "Alice",
  avatar: file // Handled automatically!
});

Realtime Subscriptions

If you have enabled Realtime, the SDK provides cleanly-typed methods for both WebSockets and Server-Sent Events (SSE).

// Listen for real-time changes using WebSockets
const unsubscribe = api.users.subscribeWS((event) => {
  console.log("User updated!", event.data);
});

// Or using Server-Sent Events (SSE)
const unsubscribeSSE = api.users.subscribeSSE((event) => {
  console.log("User updated via SSE!", event.data);
});

Custom Streams (HTTP Readable Streams)

If you have created a custom endpoint on your Radiant backend and marked it with { stream: true }, the SDK generator will automatically generate a streaming method. These methods return an AsyncGenerator that you can seamlessly consume using for await.

// Call a custom streaming endpoint
const stream = await api.myCustomRoute.get();

// Consume the stream as chunks arrive
for await (const chunk of stream) {
  console.log("Received chunk:", chunk);
}

Server-Side Usage (SSR / Loaders)

If you are using a framework like Remix, Next.js App Router, or Nuxt, you will often need to execute queries on the server on behalf of a specific user.

To prevent token leakage across requests, the SDK provides the .withToken(token) method. This creates an isolated, shallow clone of the client strictly bound to that user's token.

// In your Remix Loader or Next.js Server Component
export async function loader({ request }) {
  const token = getCookieToken(request);
  
  // Safe isolated clone for this specific HTTP request
  const serverApi = api.withToken(token);
  
  const { data: myData } = await serverApi.posts.get();
  return Response.json(myData);
}

AI Agent Integration (MCP)

If you are using the Radiant Builder API or the Radiant MCP Server, the system automatically returns the absolute URL to your generated SDK after a successful build or deploy.

Agents (like Claude) can read the usage instructions baked directly into the SDK header and start scripting against your API immediately.