> For the complete documentation index, see [llms.txt](https://docs.uibakery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uibakery.io/on-premise/additional-configurations/self-hosted-ai-chat-setup.md).

# Self-hosted AI chat

Run Chat and sandboxes in your infrastructure using your own model API keys (BYOK). If you use UI Bakery managed Chat, you can skip this setup.

You need UI Bakery **3.207 or later**, a **license** that supports self-hosted Chat, and an Anthropic API key for the default models.

## Installation

* [Docker Compose setup](https://docs.uibakery.io/on-premise/additional-configurations/self-hosted-ai-chat-setup/docker-compose.md)
* [Kubernetes setup](https://docs.uibakery.io/on-premise/additional-configurations/self-hosted-ai-chat-setup/kubernetes.md)

## Models

Leave `UI_BAKERY_AGENT_MODELS_CONFIG` unset to use the default model options. To customize them, set it to a JSON object:

```json
{
  "defaultModelPreference": "fast-changes",
  "models": {
    "fast-changes": { "model": "<fast-model-id>", "label": "Fast" },
    "high-power": { "model": "<smart-model-id>", "label": "Smart" },
    "thinking": { "model": "<thinking-model-id>", "label": "Thinking" }
  }
}
```

Replace the placeholders with model IDs available to your provider account.

* `models` lists the available options in display order.
* `model` selects the provider model; `label` sets its name in the picker.
* `defaultModelPreference` selects an option by its key when no model is selected.

For a built-in option, use `{}` to keep its current model and label.

## Attachments and storage

Follow [Project assets and Chat attachments](https://docs.uibakery.io/extras/ui-bakery-storage/on-premise-setup.md#project-assets-and-chat-attachments) to configure Bakery Storage and sandbox access for attachments.

## UI inspirations

To let the agent fetch component examples from 21st.dev, set this in Chat:

```dotenv
UI_BAKERY_FETCH_UI_API_KEY=<21st-dev-fetch-ui-api-key>
```

Allow Chat to reach `https://magic.21st.dev/api/fetch-ui`.

## Low-code AI assistant

The low-code assistant uses OpenAI separately from the app builder agent. To enable it:

```dotenv
UI_BAKERY_SHOW_CHAT_BUTTON=true
UI_BAKERY_CHAT_OPENAI_KEY=<openai-api-key>
```

Apply `UI_BAKERY_SHOW_CHAT_BUTTON` to the Bakery frontend and the OpenAI key to Chat.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.uibakery.io/on-premise/additional-configurations/self-hosted-ai-chat-setup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
