Skip to content
Using spredr

Your agent from your backend

Your backend talks to your agent with the SDK, signing with its own key. spredr delivers what you send and what the agent answers; what you send and how it reads it is your code's business.

terminal
npm install @spredr/sdk
once

Link your backend

With your spredr token, from a script or as you deploy. spredr writes the backend's key into its variables (SPREDR_CALLER_ID, SPREDR_CALLER_KEY, SPREDR_AGENT, SPREDR_AI_URL, SPREDR_AI_KEY) and deploys it: the private key never passes through you.

TypeScript
import { Spredr } from "@spredr/sdk"; const spredr = new Spredr({ token: process.env.SPREDR_TOKEN }); await spredr.agent("shop").addCaller("shop-api", { service: "shop-api" });

You can also do it in the panel, in your agent's Connections tab. To change the key, remove the link and make it again: the old one stops working at once.

every message

Ask it for a task

Caller reads the variables spredr left. for() is the customer it works for (a shop, an account), with its own memory and limits. With key, asking again is the same task; with thread, its tasks read as one conversation.

TypeScript
import { Caller } from "@spredr/sdk"; const agent = new Caller(); const shop = agent.for(shopId); const { reply } = await shop.result( "reply", { text }, { thread: `chat:${customerId}`, key: messageId }, );
what it needs

Give it context

You decide what you give it and in what form; spredr makes sure it arrives. How the agent reads it is its code's business.

in the taskWhat goes in input, up to 256 KB: the message, the customer, what changes every time.
an addressA URL of your API the agent opens with its own code when it needs it. spredr never opens it.
a session's fileA txt, json, csv or pdf of up to 10 MB you leave once per conversation: every task of that thread lists it.
Your backend
await shop.attach(`chat:${customerId}`, "prices.csv", csv, { type: "text/csv", });
Your agent
agent.on("reply", async (input, ctx) => { const prices = await ctx.file("prices.csv"); const text = new TextDecoder().decode(prices.data); return { reply: await answer(input.text, text) }; });
live

The answer as it is written

If your agent uses ctx.stream, live() gives you each piece in order and then the finished task. If the connection drops, it goes on where it left off.

TypeScript
for await (const event of shop.live("reply", { text })) { if (event.type === "delta") send(event.text); if (event.type === "end") done(event.task); }
the rest

What else you can do

questionsIf your agent asks before it acts, pauses() gives you its questions and answer() answers them.
noticesWith a callbackUrl when you link, spredr tells your backend when each task ends, signed: believe it only when caller.callback() returns it.
costsThe model runs on your key and you pay for it. Your plan counts the month's tasks, the agent's memory and its sessions' files.
errorsEvery error says why. When trying again is safe, the SDK does it for you.