---
title: Install AI Chat
---
AI Chat is delivered by the **ServiceStack.AI.Chat** NuGet package and requires a **.NET 8+** ServiceStack App.
## Add the plugin
The fastest way to add AI Chat is with the `add-in` npx script, which adds the package, registers both plugins and writes a starting configuration:
:::sh
npx add-in chat
:::
This creates a `Configure.AI.Chat.cs` [Modular Startup](/modular-startup) registering `ChatFeature` and `PdfFeature`:
```csharp
[assembly: HostingStartup(typeof(MyApp.ConfigureAiChat))]
namespace MyApp;
public class ConfigureAiChat : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
services.AddPlugin(new ChatFeature {
RequireAuth = true,
// RequiredRole = "Admin",
Tools = {
// EnableCodeExecution = true,
// EnableFilesystemTools = true,
},
// ApiTools = {
// IncludeTags = ["todos"]
// },
// Mcp = {
// ToolGroups = ["api_tools"],
// },
});
services.AddPlugin(new PdfFeature());
});
}
```
### Manual install
```xml
```
```csharp
services.AddPlugin(new ChatFeature());
```
## Requirements
See [Providers & Models](/chat/providers) for enabling a provider and [Integrated Auth](/chat/auth) for
choosing an `AuthType`.
:::info
AI Chat resolves its OrmLite connection from the host's `IDbConnectionFactory` and creates its tables when `AutoInitSchema` is true (the default). Without a registered `IDbConnectionFactory`, threads aren't persisted and the `gemini` extension disables itself.
:::
## Configure a provider
Set an API key for at least one provider as an environment variable before running your App:
Or supply them in code, which takes precedence over environment variables:
```csharp
services.AddPlugin(new ChatFeature {
Variables = {
["OPENAI_API_KEY"] = context.Configuration["OpenAi:ApiKey"]!,
},
});
```
A local [Ollama](https://ollama.com) or [LM Studio](https://lmstudio.ai) endpoint needs no key at all - see [Providers & Models](/chat/providers).
## Run it
Start your App and open:
Your existing users can sign in immediately with the account they already have.
## Add a link from your App
Surface AI Chat from ServiceStack's metadata page:
```csharp
services.ConfigurePlugin(feature => {
feature.AddPluginLink("/chat", "AI Chat");
});
```
## Install typst for PDF support
PDF Studio and `PdfFeature` shell out to the [Typst](https://typst.app) CLI. Both self-disable when it isn't found, so this is only needed if you want PDF support:
:::sh
brew install typst
:::
:::sh
cargo install --locked typst-cli
:::
AI Chat resolves `typst` from `$TYPST_PATH` first, then `PATH`. See [PDF Studio](/chat/pdf-studio) and [Rendering PDFs](/chat/rendering-pdfs).
## First-run files
On startup AI Chat writes its configuration into `App_Data/chat`:
`llms.json` is seeded only when missing and preserves user settings across restarts. Provider
catalogs (`providers.json` and `providers-extra.json`) refresh from bundled defaults on startup unless
their filenames are listed in `PreserveConfigs`. Preserved catalog files are seeded when missing.
```csharp
services.AddPlugin(new ChatFeature {
PreserveConfigs = ["providers-extra.json"],
});
```
See [Data & Storage](/chat/data).
## What's next
- [Configuration](/chat/configuration) - every `ChatFeature` option
- [Providers & Models](/chat/providers) - enabling providers and refreshing the model catalog
- [Integrated Auth](/chat/auth) - choosing an `AuthType` and restricting access
- [API Tools](/chat/api-tools) - exposing your own APIs to AI Models