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:
npx add-in chat
This creates a Configure.AI.Chat.cs Modular Startup registering ChatFeature and PdfFeature:
[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​
<PackageReference Include="ServiceStack.AI.Chat" Version="10.*" />
services.AddPlugin(new ChatFeature());
Requirements​
| Requirement | Needed for | Notes |
|---|---|---|
| .NET 8+ | Everything | net8.0 and net10.0 builds |
IDbConnectionFactory |
Threads, analytics, media, Gemini | Registered by every ServiceStack App template |
| At least one provider API key | Talking to a model | See Providers & Models |
AuthFeature or Identity Auth |
RequireAuth = true |
See Integrated Auth |
typst CLI |
PDF Studio + PDF rendering | Optional - self-disables when missing |
ffmpeg or Mistral |
Voice transcription | Optional - self-disables when missing |
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:
services.AddPlugin(new ChatFeature {
Variables = {
["OPENAI_API_KEY"] = context.Configuration["OpenAi:ApiKey"]!,
},
});
A local Ollama or LM Studio endpoint needs no key at all - see Providers & Models.
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:
services.ConfigurePlugin<MetadataFeature>(feature => {
feature.AddPluginLink("/chat", "AI Chat");
});
Install typst for PDF support​
PDF Studio and PdfFeature shell out to the Typst CLI. Both self-disable when it isn't found, so this is only needed if you want PDF support:
brew install typst
cargo install --locked typst-cli
AI Chat resolves typst from $TYPST_PATH first, then PATH. See PDF Studio and Rendering PDFs.
First-run files​
On first request AI Chat seeds its configuration into App_Data/chat:
These files are yours to edit and check in. See Data & Storage.
What's next​
- Configuration - every
ChatFeatureoption - Providers & Models - enabling providers and refreshing the model catalog
- Integrated Auth - choosing an
AuthTypeand restricting access - API Tools - exposing your own APIs to AI Models