TypeScript client
In this sectionConnect browser and Node.js apps to 10xGraph over REST, streaming, and WebSockets with the typed SDK.
- 11 pages
- About 84 min to read all
The 10xgraph-client TypeScript SDK is a typed wrapper that connects browser and Node.js apps to a running 10xGraph API. It handles session threading, multiple transport modes, auth headers, file uploads, memory access, and client-side tool execution.
What you need
Install Node 18 or later and the client package:
npm install 10xgraph-clientFor WebSocket support on Node 18-20, also install the ws package and pass it to the client config:
npm install wsimport { TenxGraphClient } from '10xgraph-client';
import WebSocket from 'ws';
const client = new TenxGraphClient({
baseUrl: 'http://localhost:8000',
webSocketImpl: WebSocket, // required on Node < 21
authToken: 'your-token',
});How it works
Your app calls the client with messages and config. The client connects to the 10xGraph API over your chosen transport, runs the graph, and returns the result. The server restores the thread’s history from the checkpointer.
flowchart LR
subgraph "Browser / Node.js"
APP[Your App]
SDK[TenxGraphClient]
end
subgraph "10xGraph API"
REST["REST Endpoints"]
GRAPH["Python Graph"]
end
APP -->|invoke/stream/wsStream| SDK
SDK -->|HTTP POST / WebSocket| REST
REST --> GRAPH
GRAPH -->|StreamChunk via NDJSON / WS| REST
REST -->|typed events| SDK
SDK -->|InvokeResult / StreamChunk| APP
Transport modes
Choose the transport that fits your application’s latency, concurrency, and environment:
| Method | Protocol | Granularity | Latency | Bidirectional | Best for |
|---|---|---|---|---|---|
invoke() |
HTTP POST | Full response | Highest | No | One-off requests, simple chat |
stream() |
HTTP NDJSON body | Token-by-token | Medium | No | Progressive display, token streaming UI |
wsStream() |
WebSocket | Token-by-token | Low | Yes | Chat apps, real-time collaboration |
realtime() |
WebSocket (binary) | Audio frames | Lowest | Yes | Voice-to-voice conversations |
All modes restore your conversation history from the thread automatically, so you never repeat context.
Core concepts
Threads: Pass a thread_id to maintain a conversation across multiple API calls. The checkpointer on the server persists the full agent state, so each new request picks up where the last one stopped.
Remote tools: Tool schemas live on the server (in 10xgraph.json), but implementation runs in your client. This lets you call browser APIs (clipboard, geolocation), keep secrets local, or run integrations the server cannot access.
Response granularity: response_granularity controls how much comes back. 'low' returns only the latest messages, 'partial' adds context and summary, and 'full' adds the graph state.
Pages in this section
Basics
- Create and configure a client: Set auth tokens, timeout, proxy headers, and environment-specific URLs
- Invoke and get results: Call the agent and await the final response
- Stream responses: Consume token-by-token or message-by-message as they arrive
- Manage threads: List threads, fetch history, update state, delete old conversations
Features
- Run client-side tools: Register handlers for tools, auto-execute them during stream
- Send files and media: Upload images, audio, documents; send them in messages
- Use the memory API: Store and search long-term memory (semantic, metadata, facts)
- Graph utilities: Inspect schemas, stop runs, fix state, observe execution metadata
- Realtime audio: Voice-to-voice audio over the
/v1/graph/liveWebSocket bridge - Handle errors: Catch and retry transient failures, parse error details
Frameworks
- Next.js and React: Route handler proxy (keep tokens server-side), streaming React components, abort patterns
All pages in TypeScript client
Basics
- Create and configure the clientInstall the TypeScript client and configure authentication to communicate with a 10xGraph API server securely.7 min
- Invoke the agentCall client.invoke() to send messages to your agent and get back responses with full control over threading, error handling, and response structure.5 min
- Stream responsesProcess agent responses token-by-token with client.stream() and client.wsStream().8 min
- Manage threadsList, inspect, update, and delete conversation threads and messages from the TypeScript client.6 min
Features
- Remote toolsExecute client-side tools from the agent graph, handling geolocation, clipboard, and other browser capabilities.7 min
- Work with files and multimodal messagesUpload images, documents, and audio; reference them in messages with file_id for secure, efficient multimodal input.8 min
- Use the memory APIStore, search, and manage long-term memories across agent conversations with the 10xGraph TypeScript client.6 min
- Graph utilities and human-in-the-loopInspect graph topology and state, stop execution, repair broken threads, view execution traces, and handle interrupts for human approval workflows.13 min
- Build a realtime audio conversationCapture microphone input, stream it to a live agent with client.realtime(), receive PCM16 audio output, and play it back in the browser.11 min
- Error handlingCatch, classify, and recover from errors in the TypeScript client. Error classes, retrying transient failures, and streaming error events.5 min