@fishaudio/agent-client
Framework-agnostic JavaScript/TypeScript SDK for embedding Fish Audio voice agents into any website or web app: realtime voice over WebRTC, live transcripts, text input, and client tools. The API is small and event-driven.
Using React? @fishaudio/agent-react wraps this SDK in hooks and components.
Installation
npm install @fishaudio/agent-client
Quickstart
import { AgentSession } from "@fishaudio/agent-client";
// Session token from your backend, or { agentId } for a public agent.
const sessionToken = await fetch("/api/voice-session", { method: "POST" }).then((r) => r.json());
const session = await AgentSession.start({
sessionToken,
callbacks: {
onModeChange: (mode) => setOrbState(mode), // "listening" | "thinking" | "speaking"
onMessage: ({ role, text }) => renderChatBubble(role, text),
onDisconnect: ({ reason }) => showCallEnded(reason),
},
});
// Later:
session.sendUserMessage("Can you summarize that?");
await session.end();
Starting a session requests microphone access. Call start() from a user gesture such as a button click for the best permission and autoplay behavior.
Documentation
- Quickstart gets you to a first call, with or without a backend.
- Authenticated sessions and public agents compare server-created session tokens with a public agent id.
- Web SDK reference covers
start()options, the session API, lifecycle, and reconnection. - Events is the event reference, including live transcripts.
- Client tools lets the agent call functions in the browser.
- Overrides and dynamic variables cover per-session customization.
- Errors lists
FishAgentErrorcodes.