React SDK
Loading...

React SDK Reference

API reference for @tambo-ai/react - Tambo's React SDK with streaming-first architecture and explicit thread management.

The @tambo-ai/react package is Tambo's React SDK, featuring a streaming-first architecture, explicit thread management, and React Query integration.

Installation

npm install @tambo-ai/react

Quick Start

import { TamboProvider, useTambo, useTamboThreadInput } from "@tambo-ai/react";
  • Hooks - React hooks for thread management, messaging, suggestions, and component state
  • Types - TypeScript interfaces and types
  • Providers - Provider components for configuring Tambo

Overview

The React SDK is organized around a simplified provider hierarchy with React Query for data fetching:

import { TamboProvider } from "@tambo-ai/react";

function App() {
  return (
    <TamboProvider
      apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY}
      userKey={userId}
      components={
        [
          /* your components */
        ]
      }
      tools={
        [
          /* your tools */
        ]
      }
    >
      <YourApp />
    </TamboProvider>
  );
}

Inside the provider, use hooks to access Tambo functionality:

import { useTambo, useTamboThreadInput } from "@tambo-ai/react";

function Chat() {
  const { messages, isStreaming, startNewThread } = useTambo();
  const { value, setValue, submit } = useTamboThreadInput();

  return (
    <div>
      {messages.map((msg) => (
        <Message key={msg.id} message={msg} />
      ))}
      <input
        value={value}
        onChange={(e) => setValue(e.target.value)}
        onKeyDown={(e) => e.key === "Enter" && submit()}
      />
    </div>
  );
}

Key Features

FeatureImplementation
Import path@tambo-ai/react
Main hookuseTambo()
User scopinguserKey prop
Thread inputuseTamboThreadInput()
Message formatContent blocks (text, component, tool_use, etc.)
Component stateuseTamboComponentState() (bidirectional sync)
Streaming statusstreamingState.status (typed as RunStatus)
Data fetchingReact Query hooks