React SDK for Thred - AI-powered responses and streaming capabilities.
npm install @thred-apps/thred-react @thred-apps/thred-js
# or
yarn add @thred-apps/thred-react @thred-apps/thred-js
# or
pnpm add @thred-apps/thred-react @thred-apps/thred-jsimport { ThredProvider } from "@thred-apps/thred-react";
function App() {
return (
<ThredProvider apiKey={process.env.NEXT_PUBLIC_THRED_KEY}>
{/* Your app content */}
</ThredProvider>
);
}import { useAnswerAPI } from "@thred-apps/thred-react";
function MyComponent() {
const { answer } = useAnswerAPI();
const handleQuestion = async () => {
const result = await answer("What is the weather today?", {
instructions: "Be concise",
previousMessages: [],
});
console.log(result.response);
};
return <button onClick={handleQuestion}>Ask Question</button>;
}import { useStreamingAPI } from "@thred-apps/thred-react";
import { useState } from "react";
function StreamingComponent() {
const { stream } = useStreamingAPI();
const [response, setResponse] = useState("");
const handleStream = async () => {
await stream(
"Tell me a story",
{
instructions: "Be creative",
},
(chunk) => {
setResponse((prev) => prev + chunk);
}
);
};
return (
<div>
<button onClick={handleStream}>Start Streaming</button>
<p>{response}</p>
</div>
);
}import { ThredBox } from "@thred-apps/thred-react";
function ResponseDisplay() {
return (
<ThredBox
code="greeting"
boxColor="#1C1C1C"
text={{
value: "Welcome to Thred!",
color: "#FFFFFF",
}}
link={{
value: "thred.app",
display: "Visit our website",
color: "green",
}}
/>
);
}The context provider that initializes the Thred client.
Props:
apiKey(string, required): Your Thred API keychildren(ReactNode, required): Your app components
Hook for making non-streaming answer requests.
Returns:
answer(message, options, targets): Async function to get an answermessage(string): The question or messageoptions(object): Optional configurationinstructions(string): Custom instructionspreviousMessages(array): Message history
targets(Targets): Optional targeting configuration
Hook for making streaming answer requests.
Returns:
stream(message, options, onAnswer, targets): Async function to stream an answermessage(string): The question or messageoptions(object): Optional configurationonAnswer(function): Callback for each chunktargets(Targets): Optional targeting configuration
Component for displaying responses with links.
Props:
code(string, required): Unique identifier for the responseboxColor(string): Background color (default: "#1C1C1C")text(object, required):value(string): The text contentcolor(string): Text color (default: "#000000")
link(object): Optional linkvalue(string): The URLdisplay(string): Display textcolor(string): Link color (default: "green")
This package includes TypeScript definitions out of the box.
MIT