@fishaudio/agent-react provides React hooks and components for Fish Audio voice agents, built on @fishaudio/agent-client. Authentication, events, client tools, and error semantics come from the client SDK. Everything documented there applies here.
npm install @fishaudio/agent-reactRequires React 18+.
"use client";
import { useConversation } from "@fishaudio/agent-react";
export function VoiceWidget() {
const conversation = useConversation();
const start = async () => {
const sessionToken = await fetch("/api/voice-session", { method: "POST" }).then((r) => r.json());
await conversation.startSession({ sessionToken });
};
return (
<div>
<p>
status: {conversation.status}
{conversation.isSpeaking ? " · agent is speaking" : ""}
</p>
{conversation.status === "connected" ? (
<>
<button onClick={() => conversation.setMicMuted(!conversation.micMuted)}>
{conversation.micMuted ? "Unmute" : "Mute"}
</button>
<button onClick={() => conversation.endSession()}>End call</button>
</>
) : (
<button onClick={start}>Start call</button>
)}
</div>
);
}The hook ends the session automatically when the component unmounts. Start calls made from the required user interaction path are safe under React StrictMode's effect replay.
useConversationowns one session's lifecycle. It is the primary entry point.- Provider covers
<AgentSessionProvider>and the context hooks that share one conversation across a tree. useAgentMessagesis a streaming chat log for building a chat UI.- Audio visualization covers
useAudioLevelsfor meters and<AgentAudioVisualizer />for frequency bars.
The client package's key exports (AgentSession, FishAgentError, and their types) are re-exported, so app code can import everything from @fishaudio/agent-react.
The SDK only touches browser APIs when a session starts, so importing in Server Components is safe; components using the hooks need "use client". Create session tokens in a Route Handler (app/api/voice-session/route.ts) with your FISH_API_KEY.