Create A Client
Connect to a PAI app over HTTP or another transport.
Use createPaiHttpClient() for browser, server, and React clients that talk to
an HTTP-served PAI app.
import { createPaiHttpClient } from "@pai/client-http";
import type { AssistantPai } from "../../server/pai";
export const paiClient = createPaiHttpClient<AssistantPai>({
url: "http://localhost:3001/api/pai",
});
export const assistant = paiClient.agent("main");Options
Bearer token example:
const paiClient = createPaiHttpClient<AssistantPai>({
url: "http://localhost:3001/api/pai",
fetch,
headers: async () => ({
authorization: `Bearer ${await getToken()}`,
}),
});Cookie-session example:
const paiClient = createPaiHttpClient<AssistantPai>({
url: "https://api.example.com/api/pai",
credentials: "include",
headers: {
"x-csrf-token": getCsrfToken(),
},
});See Serve An Agent for server-side identity and request handling guidance.
Manifest
The per-agent client can read the agent manifest.
const manifest = await assistant.getManifest();React bindings and client tool registration use the manifest to validate capabilities.
Thread Handles
Create a new local thread handle:
const thread = assistant.thread(assistant.newThreadId());Reference an existing thread:
const thread = assistant.thread(threadId);
const state = await thread.refresh();List threads:
const page = await assistant.threads.list({ limit: 20 });Sending Work
Create or reference a thread handle, then send messages through it. The first send realizes a new thread id server-side.
const thread = assistant.thread(assistant.newThreadId());
const run = await thread.send("Draft a release note");
const state = await run.waitUntilIdle();
console.log(state.messages);The client manages transport details such as session ids, local client-tool registrations, and run.waitUntilIdle() live. App code registers tools on the thread or through React hooks; it does not manually attach client-tool protocol fields to each send.