Config API
Fetch tenant configuration including Rules and other settings.
The Config API allows the frontend to retrieve Rules (command shortcuts) and other configuration settings from Lens OS backend.
Overview
The Config API enables your frontend to fetch Rules configured in the Lens OS console, which can be displayed in the rules menu for quick access.
Setup
src/app/api/lens/agent/config/route.ts
import { NextResponse } from "next/server";
import { auth } from "@/auth";
import { LensClient } from "@lens-os/sdk";
const client = new LensClient({ apiKey: process.env.LENS_OS_API_KEY! });
export async function GET() {
const session = await auth();
if (!session?.user) {
return NextResponse.json(
{ success: false, error: "Unauthorized" },
{ status: 401 }
);
}
try {
const config = await client.getConfig();
return NextResponse.json({ success: true, config });
} catch (err) {
console.error("[Config API] Error:", err);
return NextResponse.json(
{ success: false, error: "Failed to fetch config" },
{ status: 500 }
);
}
}Response Format
Response
{
success: true,
config: {
rules: [
{
id: "rule-1",
name: "search",
displayName: "Search Products",
description: "Search product database",
prompt: "Please help me search for:",
},
// ...
],
systemPrompt: "You are a helpful assistant...",
// ...other config
}
}Frontend Usage
Using the useLensAgent hook, you can access rules, skills, and other settings configured in the Lens OS console — no need to manage state manually.
Access rules from config
'use client';
import { useLensAgent } from '@lens-os/sdk/react';
export function RulesMenu() {
const { config } = useLensAgent();
// Get rules configured in Lens OS console
const rules = config?.rules ?? [];
return (
<ul>
{rules.map((rule) => (
<li key={rule.id}>
<button onClick={() => sendMessage(rule.prompt)}>
{rule.displayName}
</button>
</li>
))}
</ul>
);
}Note
config is loaded automatically by the SDK when the session initializes — no need to manually call /api/lens/agent/config. Updates made in the Lens OS console may take a few minutes to propagate.