Overview
TheTamboClient class is the main entry point for the @tambo-ai/client package. It manages threads, tool registration, streaming, and state without any React dependencies.
Compatible with useSyncExternalStore for React integration via client.getState() and client.subscribe().
Installation
Constructor
Configuration object for the client
API key for authentication with Tambo
Custom Tambo API URL. Conflicts with
environmentEnvironment preset. Conflicts with
tamboUrlUser key for identifying the user
User token for token-based auth
Tools to register on creation
MCP servers to connect on initialization
Callback invoked before each run starts
Core Methods
run()
Start a new run with a message. Returns aTamboStream immediately.
The message to send (string or InputMessage object)
Configuration for the run
Thread ID to run on. If omitted, creates a new thread
Whether to auto-execute tools when the model requests them
Max tool execution rounds
How the model should select tools
Enable debug logging
Additional context merged into the message
AbortSignal for cancellation
User message text for optimistic display
A TamboStream for observing the response. See TamboStream for details
Usage Patterns
Async Iteration (Stream Mode)getState()
Get the current client state snapshot. Compatible withuseSyncExternalStore.
subscribe()
Subscribe to state changes. Compatible withuseSyncExternalStore.
Callback invoked on state change
Function to unsubscribe from state changes
React Integration Example
Thread Management
switchThread()
Switch to an existing thread. Fetches thread data from the API.The thread ID to switch to
startNewThread()
Start a new thread. Returns the new thread ID.The new placeholder thread ID
getThread()
Get a thread from local state.The thread ID
The thread, or undefined if not found
listThreads()
List all threads from the API.Array of TamboThread objects
fetchThread()
Fetch a thread from the API and hydrate it into local state.The thread ID to fetch
The fetched thread
Tool Registration
registerTool()
Register a single tool.The tool to register
registerTools()
Register multiple tools at once.The tools to register
registerComponent()
Register a component.Component name
The registered component
Run Control
cancelRun()
Cancel the active run on a thread.The thread whose run to cancel. Defaults to current thread
Thread Naming
updateThreadName()
Update a thread’s name via the API.The thread ID
The new name
generateThreadName()
Generate a thread name via the API.The thread ID
The generated name
MCP Integration
connectMcpServer()
Connect to an MCP server.The MCP server configuration
The connected MCPClient
disconnectMcpServer()
Disconnect from an MCP server.The server key (from getMcpServerUniqueKey)
getMcpClients()
Get all connected MCP clients.Record of server key to MCPClient
getMcpToken()
Get an MCP token for a context key.The context key
Optional thread ID for session-bound tokens
The MCP access token response
Suggestions
listSuggestions()
List suggestions for a message.The message ID
The thread ID
Array of suggestions
generateSuggestions()
Generate suggestions for a message.The message ID
The thread ID
Generation options
Array of generated suggestions
Context Helpers
addContextHelper()
Add a context helper that provides additional context on each run.Unique name for the helper
Function returning context data
removeContextHelper()
Remove a context helper.The helper name to remove
Advanced
getAuthState()
Compute and return the current auth state.The current auth state
getSdkClient()
Get the underlying SDK client (for advanced use cases).The TamboAI SDK client