# Self-hosted AI

{% hint style="success" %}
This is the official documentation of the `@forestadmin/agent` Node.js agent.
{% endhint %}

## Self-hosted AI

By default, AI features in Forest Admin are processed by Forest Admin servers. To keep your data private, you can route AI requests through your own agent using the `addAi` method—your data never leaves your infrastructure.

### Installation

```bash
npm install @forestadmin/ai-proxy
```

### Configuration

{% tabs %}
{% tab title="OpenAI" %}

```javascript
import { createAiProvider } from '@forestadmin/ai-proxy';

const agent = createAgent(options)
  .addDataSource(/* ... */)
  .addAi(
    createAiProvider({
      name: 'my-assistant',
      provider: 'openai',
      apiKey: process.env.OPENAI_API_KEY,
      model: 'gpt-4o',
    }),
  );
```

{% endtab %}

{% tab title="Anthropic" %}

```javascript
import { createAiProvider } from '@forestadmin/ai-proxy';

const agent = createAgent(options)
  .addDataSource(/* ... */)
  .addAi(
    createAiProvider({
      name: 'my-assistant',
      provider: 'anthropic',
      apiKey: process.env.ANTHROPIC_API_KEY,
      model: 'claude-sonnet-4-5',
    }),
  );
```

{% endtab %}
{% endtabs %}

### Options

| Option     | Type                        | Required | Description                                                           |
| ---------- | --------------------------- | -------- | --------------------------------------------------------------------- |
| `name`     | `string`                    | Yes      | Unique identifier for this AI configuration                           |
| `provider` | `'openai'` \| `'anthropic'` | Yes      | AI provider                                                           |
| `model`    | `string`                    | Yes      | Model to use (see supported models below)                             |
| `apiKey`   | `string`                    | No       | API key (defaults to `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` env var) |

All provider-specific options are also supported: [ChatOpenAI options](https://docs.langchain.com/oss/javascript/integrations/chat/openai) (`configuration`, `temperature`, `maxTokens`, etc.) and [ChatAnthropic options](https://docs.langchain.com/oss/javascript/integrations/chat/anthropic) (`anthropicApiUrl`, `temperature`, `maxTokens`, `topK`, etc.).

### Supported models

Any model with function/tool calling support works. See the [full list of unsupported models](https://github.com/ForestAdmin/agent-nodejs/blob/main/packages/ai-proxy/src/supported-models.ts) for details.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/ai/self-hosted-ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
