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:

Terminal
npm install 10xgraph-client

For WebSocket support on Node 18-20, also install the ws package and pass it to the client config:

Terminal
npm install ws
TypeScript
import { 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

Features

Frameworks

  • Next.js and React: Route handler proxy (keep tokens server-side), streaming React components, abort patterns

All pages in TypeScript client

Basics

  1. Create and configure the clientInstall the TypeScript client and configure authentication to communicate with a 10xGraph API server securely.7 min
  2. 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
  3. Stream responsesProcess agent responses token-by-token with client.stream() and client.wsStream().8 min
  4. Manage threadsList, inspect, update, and delete conversation threads and messages from the TypeScript client.6 min

Features

  1. Remote toolsExecute client-side tools from the agent graph, handling geolocation, clipboard, and other browser capabilities.7 min
  2. Work with files and multimodal messagesUpload images, documents, and audio; reference them in messages with file_id for secure, efficient multimodal input.8 min
  3. Use the memory APIStore, search, and manage long-term memories across agent conversations with the 10xGraph TypeScript client.6 min
  4. 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
  5. 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
  6. Error handlingCatch, classify, and recover from errors in the TypeScript client. Error classes, retrying transient failures, and streaming error events.5 min

Frameworks

  1. Call 10xGraph from Next.js and ReactIntegrate a 10xGraph Python agent backend with Next.js using route handlers for secure streaming and Server Actions for non-streaming calls.8 min