Skip to main content
This is a beta feature according to Algolia’s Terms of Service (“Beta Services”).
You can interact with your published agents using HTTP API or use the AI SDK UI for a seamless integration.

Steps for integrating Agent Studio

1

Prepare your agent

Ensure that your agent is configured and published in the Algolia dashboard. To learn more, see Get started with the Agent Studio dashboard.
2

Get your agent ID

On the Agents page in the Agent Studio’s dashboard, find your published agent’s ID.
3

Choose how you want to integrate Agent Studio

  • HTTP API: Directly interact with your agent using HTTP requests.
  • AI SDK UI: Use the React-based SDK for a ready-to-use conversational UI.

API integration

Interact with your GenAI agent directly using the Agent Studio API. Example curl request:
curl 'https://{{H7DRX6ASDM}}.algolia.net/agent-studio/1/agents/{{agentId}}/completions?stream=false&compatibilityMode=ai-sdk-5' \
  -X POST \
  -H 'Content-Type: application/json' \
  -H 'x-algolia-application-id: H7DRX6ASDM' \
  -H 'X-Algolia-API-Key: YourSearchOnlyApiKey' \
  --data-raw '{
  "messages": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "What is 1+1 ?"
                }
            ]
        }
    ]
}'
And the response would look like the following:
JSON
{
    "role": "assistant",
    "parts": [
        {
            "type": "step-start"
        },
        {
            "type": "text",
            "text": "1 + 1 = 2"
        }
    ]
}
To continue the conversation, include the previous messages in the request:
JSON
{
    "messages": [
        {
            "role": "user",
            "content": "What is 1+1 ?"
        },
        {
            "role": "assistant",
            "content": "The sum of 1 + 1 is 2."
        },
+        {
+            "role": "user",
+            "content": "What is the sum of the previous value + 3"
+        }
    ]
}
  • Replace {{ALGOLIA_APPLICATION_ID}} with your Algolia application ID.
  • Replace {{agentId}} with your published agent ID.
  • Use your application’s search-only API key for authentication.
  • The endpoint supports streaming responses and is compatible with ai-sdk v4 and v5.
  • For streaming responses, set stream=true in the query parameters.
  • For production, secure your API keys and restrict usage as needed.

AI SDK UI integration

The Agent Studio is compatible with AI SDK UI, a React-based UI integration for building conversational interfaces. Agent Studio supports both ai-sdk v5 and v4. AI SDK UI isn’t required to use Agent Studio, but it makes the integration process much easier by handling common tasks like UI rendering and state management. The benefits of using the AI SDK UI are:
  • Abstractions over low-level HTTP requests
  • Built-in error handling, retries, and extensibility using middleware and plugins
  • Fast setup for conversational user interfaces
It also allows for advanced use cases, such as:
  • Custom tool handling
  • UI state control
For more information, see the AI SDK documentation.

Installation

npm install ai @ai-sdk/react

Example React integration

React
import { useState } from 'react';
import { useChat } from '@ai-sdk/react'
import { DefaultChatTransport } from 'ai';

const App = () => {
  const [input, setInput] = useState('');
  
  const { messages, sendMessage } = useChat({
      transport: new DefaultChatTransport({
      api: `https://${XGWKVNJNLW}.algolia.net/agent-studio/1/agents/${agentId}/completions?streaming=true&compatibilityMode=ai-sdk-5`,
      headers: {
        'x-algolia-application-id': 'XGWKVNJNLW',
        'x-algolia-api-key': 'YourSearchOnlyApiKey',
      },
    }),
  })

  const handleSubmit = e => {
    e.preventDefault();
    sendMessage({ text: input });
    setInput('');
  };

  return (
    <>
      {messages.map(message => (
        <div key={message.id}>
          {message.role}:{message.content}
        </div>
      ))}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={e => setInput(e.target.value)} />
        <button type="submit">Submit</button>
      </form>
    </>
  )
}
I