Frontend Integration

Inferable provides a flexible, hooks-based React SDK for building custom AI copilot interfaces in your React applications.

While we currently offer official support for React, Inferable is API-driven at its core, allowing you to build integrations for any platform or framework by directly utilizing our HTTP APIs.

React SDK Integration

The React SDK provides a hooks-based foundation for integrating AI agents into your frontend application. This approach gives you complete control over the user interface and interaction design, perfect for creating custom copilot experiences or conversational interfaces that match your application’s look and feel.

import { useInferable, useRun, useMessages } from "@inferable/react";

function Chat() {
  // Initialize the Inferable client
  const inferable = useInferable({
    clusterId: "your-cluster-id",
    ...authSettings,
  });

  // Start or connect to a run
  const run = useRun(inferable);

  // Get utility functions for working with messages
  const messages = useMessages(run.messages);

  return (
    <div>
      {/* Display messages */}
      {messages.all("asc")?.map((msg) => (
        <div key={msg.id}>
          {msg.type === "human" ? "You: " : "Assistant: "}
          {msg.data.message}
        </div>
      ))}

      {/* Message input */}
      <input
        onKeyPress={(e) => {
          if (e.key === "Enter") {
            run.createMessage(e.target.value);
            e.target.value = "";
          }
        }}
        placeholder={"Type your message..."}
      />
    </div>
  );
}

For the examples and more details see Inferable React SDK Github

Demo

This is a demo of the React SDK in action.

Authentication

React SDK allows you to authenticate with your Inferable API secret key. However, this is not recommended for production environments as it exposes your API key to the client.

Instead, we have implemented a Custom Auth method that allows you to authenticate a user with your own authentication system. Typically, the custom auth token in this case would be your user’s session token.

Features

The React SDK provides essential capabilities for building robust AI chat interfaces:

Chat State Management - Intelligent conversation history handling - Automatic message truncation - Persistent chat sessions

Frontend-safe Authentication - Secure API access without credential exposure - Flexible authentication strategies - For more details see Custom Auth

Distributed Tool Calling - Seamless backend service integration - Secure function execution - Built-in authentication and routing - For more details see Functions