Front End usage
Learn how to use Inferable within a React application
Overview
Inferable supports usage from front-end applications including via the React SDK. This makes it possible to trigger runs from your React application without needing to proxy the requests through your service’s API.
Installation
Authentication
When calling the Inferable API’s from the browser, it is strongly recomended not to use an Inferable Cluster API keys as these will be exposed to the client. Instead, Inferable provides a mechanisim for authenticating your own Customer Provided Secrets.
You can pass a session token or similar to the Inferable API and then validate this using a handleCustomerAuth function registered from your service’s backend.
This also has the benifit of being able to propogate user-specific auth context to vary the run’s function call based on the user’s session.
For more details on authentication, see Authentication.
Run Configuration
Runs can only be triggered from existing Run Configurations which have been marked as “public”.
This allows you to restrict the configuration of Runs triggered from the front-end. For example, defining an initialPrompt
and inputSchema on the configuration will limit the run’s input to a an object matching the inputSchema
.
For more details on run configurations, see Run Configurations.
useRun
The useRun
hook returns an object with the following properties:
Basic Usage
The following example uses the useRun
hook to trigger a run based on a button click and display the results once ready:
Interactive Usage (Chat)
The following example uses the useRun
hook to create a simple chat interface:
In this example, we are continuing an existing run by passing the runId
.
Was this page helpful?