Agents in Your App Template

Drop the SDK into an existing product, add an agent endpoint, and stream to your UI

What it is

A pattern for adding an AI agent to a product you already have. You do not migrate anything. You install the SDK, add one server endpoint that streams an agent, and wire your existing UI to it. Your stack stays exactly as it is.

What it includes

PieceWhat it does
SDKThe zero-dependency @recursiv/sdk dropped into your backend
AgentA model-agnostic agent (any supported model) created once
EndpointOne streaming route in your existing server
UI wiringClient code that renders streamed deltas
IntegrationsOptional access to hundreds of data integrations as tools

How to start it

Install the SDK in your existing backend and create one agent.

$npm install @recursiv/sdk
$export RECURSIV_API_KEY=sk_live_...
1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv();
4
5// Create the agent once (script, migration, or dashboard)
6const { data: agent } = await r.agents.create({
7 project_id: process.env.RECURSIV_PROJECT_ID!,
8 name: 'In-App Assistant',
9 model: 'anthropic/claude-sonnet-4.6',
10 system_prompt: 'You help users inside our product. Be concise and accurate.',
11});

Add an agent endpoint

Add one route to your existing server. Keep the API key server side and stream { delta } chunks to the client.

1// Express, Next.js route handler, or any Node server
2import { Recursiv } from '@recursiv/sdk';
3
4const r = new Recursiv();
5
6export async function handleChat(req, res) {
7 const { agentId, message } = req.body;
8
9 res.setHeader('Content-Type', 'text/plain; charset=utf-8');
10 for await (const chunk of r.agents.chatStream(agentId, { message })) {
11 res.write(chunk.delta ?? '');
12 }
13 res.end();
14}

Stream to your UI

Your existing frontend reads the response body as it arrives. No framework lock-in.

1const res = await fetch('/api/chat', {
2 method: 'POST',
3 headers: { 'Content-Type': 'application/json' },
4 body: JSON.stringify({ agentId, message }),
5});
6
7const reader = res.body!.getReader();
8const decoder = new TextDecoder();
9while (true) {
10 const { value, done } = await reader.read();
11 if (done) break;
12 appendToUI(decoder.decode(value)); // your existing render function
13}

In React Native, do not use chatStream(). Call r.agents.chatStreamText() instead.

Key SDK calls

  • r.agents.create({ project_id, model, instructions }) - the agent, created once
  • r.agents.chatStream(agentId, { message }) - stream from your server (Node and browser)
  • r.agents.chatStreamText(agentId, { message }) - the React Native streaming path
  • r.agents.chat(agentId, { message }) - non-streaming, if you just want the full reply

Next steps