AI SDK is an open-source TypeScript library that gives you the tools to build AI-powered products.

Operator supports the AI SDK UI protocol out of the box. When you create a conversation using the chat_async channel, the response will include a ai_sdk_api_url field inside the channel object. You can use this URL directly with the useChat hook to create a UI for your conversational agent.

// Proxy this through your server to avoid exposing your API key
const conversation = createConversation();
const apiUrl = conversation.channel.ai_sdk_api_url;

const { messages, input, handleInputChange, handleSubmit } = useChat({
  api: apiUrl,
  headers: { 'Operator-Version': '2025-06-19' },
  // Provide an initial message if needed, or leave blank
  initialInput: '',
  onError: (error) => {
    console.error(error);
  },
  // Operator handles conversation state server-side.
  // Only the latest message needs to be sent.
  // See: https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence#sending-only-the-last-message
  experimental_prepareRequestBody({ messages, id }) {
    return { message: messages[messages.length - 1], id };
  },
});

You can now use this setup to build fully interactive chat interfaces backed by Operator.