Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: bring-your-own-gateway (BYOG) — OpenAI-compatible AI provider for self-hosting (#2322)
Moulik Aggarwalfcc857b06af3
diff --git a/.env.docker.example b/.env.docker.exampleindex c7340aa44..18f9c5559 100644--- a/.env.docker.example+++ b/.env.docker.example@@ -144,6 +144,16 @@ OPENSTATUS_INGEST_URL=https://openstatus-private-location.fly.dev# /api/markdown endpoints. Defaults to the public openstatus.dev docs.# OPENSTATUS_WEB_BASE_URL=https://www.openstatus.dev+# AI chat provider (optional). Configure ONE option to enable the assistant.+# Option 1 — OpenAI-compatible endpoint (NVIDIA NIM, vLLM, Ollama, OpenRouter…).+# Recommended for self-hosting; takes priority when AI_BASE_URL is set. The model+# MUST support tool calling. AI_API_KEY is optional for keyless local gateways.+# AI_BASE_URL=https://integrate.api.nvidia.com/v1+# AI_API_KEY=nvapi-xxxxx+# AI_MODEL=meta/llama-3.1-70b-instruct+# Option 2 — Vercel AI Gateway (model chosen by workspace plan).+# AI_GATEWAY_API_KEY=+# DEVELOPMENT & TESTING# ============================================================================# Turbo build modediff --git a/apps/dashboard/.env.example b/apps/dashboard/.env.exampleindex 30af12a12..acb817ac4 100644--- a/apps/dashboard/.env.example+++ b/apps/dashboard/.env.example@@ -82,5 +82,20 @@ OPENPANEL_CLIENT_SECRET=something# https://github.com/ExodusOSS/bytes/issues/13#issuecomment-3965264022NODE_OPTIONS=--experimental-require-module-# chat model via AI Gateway-AI_GATEWAY_API_KEY=\ No newline at end of file+# AI chat provider. Configure ONE of the two options below.+#+# Option 1 — Vercel AI Gateway (hosted default). Free workspaces use a cheaper+# model, paid workspaces a stronger one.+AI_GATEWAY_API_KEY=+#+# Option 2 — Self-hosted / OpenAI-compatible endpoint (NVIDIA NIM, vLLM, Ollama,+# OpenRouter, …). Takes priority over the gateway when AI_BASE_URL is set.+# The model MUST support tool/function calling — the agent depends on it.+# AI_API_KEY is optional for keyless local gateways.+# Example (NVIDIA NIM):+# AI_BASE_URL=https://integrate.api.nvidia.com/v1+# AI_API_KEY=nvapi-xxxxx+# AI_MODEL=meta/llama-3.1-70b-instruct+AI_BASE_URL=+AI_API_KEY=+AI_MODEL=\ No newline at end of filediff --git a/apps/dashboard/package.json b/apps/dashboard/package.jsonindex 5e3bf0b31..89749cb0a 100644--- a/apps/dashboard/package.json+++ b/apps/dashboard/package.json@@ -23,6 +23,7 @@"@hookform/resolvers": "catalog:","@libsql/client": "catalog:","@openpanel/nextjs": "catalog:",+ "@openstatus/ai": "workspace:*","@openstatus/analytics": "workspace:*","@openstatus/api": "workspace:*","@openstatus/assertions": "workspace:*",diff --git a/apps/dashboard/src/app/api/chat/route.ts b/apps/dashboard/src/app/api/chat/route.tsindex 8b9730f2f..ecf80b68b 100644--- a/apps/dashboard/src/app/api/chat/route.ts+++ b/apps/dashboard/src/app/api/chat/route.ts@@ -1,3 +1,4 @@+import { resolveChatModel } from "@openstatus/ai";import {type ChatStoredMessage,storedMessageSchema,@@ -27,9 +28,6 @@ import { chatRateLimit } from "@/lib/rate-limit/chat";export const runtime = "edge";-const CHAT_MODEL_FREE = "anthropic/claude-haiku-4.5";-const CHAT_MODEL_PAID = "anthropic/claude-sonnet-4.5";-// Drop tool parts that have no result the SDK can turn into a tool_result// block. `ignoreIncompleteToolCalls` doesn't cover `approval-requested`, so// a mid-confirmation reload would otherwise replay an orphan `tool_use` to@@ -55,13 +53,6 @@ const requestSchema = z.object({});export async function POST(req: NextRequest) {- if (!process.env.AI_GATEWAY_API_KEY) {- return NextResponse.json(- { error: "Chat is not configured on this deployment." },- { status: 503 },- );- }-const workspaceSlug = (await cookies()).get("workspace-slug")?.value;const ctx = await getChatServiceContext({ workspaceSlug });if (!ctx || ctx.actor.type !== "user") {@@ -77,6 +68,17 @@ export async function POST(req: NextRequest) {const plan = ctx.workspace.plan ?? "free";+ // Provider is resolved from env: a self-hosted OpenAI-compatible endpoint+ // (`AI_BASE_URL`) or the Vercel AI Gateway (`AI_GATEWAY_API_KEY`). `null`+ // means neither is configured.+ const model = resolveChatModel({ plan });+ if (!model) {+ return NextResponse.json(+ { error: "Chat is not configured on this deployment." },+ { status: 503 },+ );+ }+// Skip the LLM-cost cap entirely in non-prod so testing doesn't// burn through the daily allowance. The Redis counter still// increments in prod where it matters.@@ -148,7 +150,7 @@ export async function POST(req: NextRequest) {);const result = streamText({- model: plan === "free" ? CHAT_MODEL_FREE : CHAT_MODEL_PAID,+ model,system: buildAgentSystemPrompt({workspaceName: ctx.workspace.name ?? "Unknown",surface: "dashboard",diff --git a/apps/web/public/assets/changelog/bring-your-own-ai-provider.png b/apps/web/public/assets/changelog/bring-your-own-ai-provider.pngnew file mode 100644index 000000000..9ca97a78aBinary files /dev/null and b/apps/web/public/assets/changelog/bring-your-own-ai-provider.png differdiff --git a/apps/web/src/content/pages/changelog/bring-your-own-ai-provider.mdx b/apps/web/src/content/pages/changelog/bring-your-own-ai-provider.mdxnew file mode 100644index 000000000..f91b84510--- /dev/null+++ b/apps/web/src/content/pages/changelog/bring-your-own-ai-provider.mdx@@ -0,0 +1,22 @@+---+title: "Self-host the AI assistant with your own model"+description: "Self-hosted openstatus can now run the AI assistant on any OpenAI-compatible model — NVIDIA NIM, vLLM, Ollama, and more."+image: "/assets/changelog/bring-your-own-ai-provider.png"+publishedAt: "2026-07-03"+author: "Moulik Aggarwal"+category: "integrations"+---++Running openstatus on your own infrastructure? The in-dashboard AI assistant no longer depends on a hosted gateway — you can now power it with **your own model provider**.++Point it at any **OpenAI-compatible** endpoint ([NVIDIA NIM](https://build.nvidia.com/), vLLM, Ollama, OpenRouter, or a private gateway) by setting three environment variables in your `.env.docker`:++```env+AI_BASE_URL=https://integrate.api.nvidia.com/v1+AI_API_KEY=nvapi-xxxxx+AI_MODEL=meta/llama-3.1-70b-instruct+```++The model and API key stay entirely on your own infrastructure, and `AI_API_KEY` is optional for keyless local gateways like Ollama. The only requirement is that the model supports tool calling, which the assistant uses to manage your monitors and status pages.++See the [self-hosting guide](/docs/guides/self-hosting-openstatus) for the full configuration.diff --git a/apps/web/src/content/pages/docs/guides/self-hosting-openstatus.mdx b/apps/web/src/content/pages/docs/guides/self-hosting-openstatus.mdxindex 2d11ec966..79ed3bb49 100644--- a/apps/web/src/content/pages/docs/guides/self-hosting-openstatus.mdx+++ b/apps/web/src/content/pages/docs/guides/self-hosting-openstatus.mdx@@ -177,6 +177,41 @@ Now that the services are running, you can access the dashboard and perform the/>+## Configuring the AI assistant (optional)++openstatus ships an in-dashboard AI assistant. It is **off by default** when self-hosting — the chat endpoint returns `503 "Chat is not configured"` until you point it at a model provider. Configure **one** of the two options below in your `.env.docker` (root) — or `apps/dashboard/.env` for a manual setup — then restart the dashboard.++### Option 1: OpenAI-compatible endpoint (bring your own model)++Use any OpenAI-compatible API — [NVIDIA NIM](https://build.nvidia.com/), vLLM, Ollama, OpenRouter, LM Studio, or a private gateway. This is the recommended path for self-hosting: the model and key stay on your own infrastructure.++```env+AI_BASE_URL=https://integrate.api.nvidia.com/v1+AI_API_KEY=nvapi-xxxxx+AI_MODEL=meta/llama-3.1-70b-instruct+```++- `AI_BASE_URL` — the provider's OpenAI-compatible base URL (usually ends in `/v1`). Setting it enables this option.+- `AI_API_KEY` — optional. Leave empty for keyless local gateways such as Ollama.+- `AI_MODEL` — the model id to use. It **must support tool / function calling** — the assistant manages your monitors and status pages through tools, so a model without tool support cannot act.++A fully local, keyless setup with Ollama:++```env+AI_BASE_URL=http://localhost:11434/v1+AI_MODEL=llama3.1+```++### Option 2: Vercel AI Gateway++If you use the [Vercel AI Gateway](https://vercel.com/docs/ai-gateway), set a single key. The model is chosen automatically (a smaller model for free workspaces, a stronger one for paid).++```env+AI_GATEWAY_API_KEY=your-gateway-key+```++When both are configured, `AI_BASE_URL` takes priority over the gateway.+## Service architectureopenstatus consists of multiple services running together:diff --git a/packages/ai/.gitignore b/packages/ai/.gitignorenew file mode 100644index 000000000..e365bcee2--- /dev/null+++ b/packages/ai/.gitignore@@ -0,0 +1,5 @@+# Type-check only package — never commit emitted output+*.js+*.d.ts+*.d.ts.map+*.tsbuildinfodiff --git a/packages/ai/package.json b/packages/ai/package.jsonnew file mode 100644index 000000000..ae9f8d21f--- /dev/null+++ b/packages/ai/package.json@@ -0,0 +1,32 @@+{+ "name": "@openstatus/ai",+ "version": "0.0.0",+ "license": "MIT",+ "type": "module",+ "main": "./src/index.ts",+ "types": "./src/index.ts",+ "exports": {+ ".": {+ "import": "./src/index.ts",+ "types": "./src/index.ts"+ }+ },+ "scripts": {+ "check": "deno check --sloppy-imports .",+ "test": "deno test --parallel -A --no-check --sloppy-imports",+ "lint": "oxlint",+ "tsc": "tsc --noEmit"+ },+ "dependencies": {+ "@ai-sdk/openai-compatible": "catalog:",+ "ai": "catalog:"+ },+ "devDependencies": {+ "@openstatus/db": "workspace:*",+ "@openstatus/tsconfig": "workspace:*",+ "@std/expect": "jsr:^1.0.19",+ "@std/testing": "jsr:^1.0.19",+ "@types/node": "catalog:",+ "typescript": "catalog:"+ }+}diff --git a/packages/ai/src/index.ts b/packages/ai/src/index.tsnew file mode 100644index 000000000..357c59607--- /dev/null+++ b/packages/ai/src/index.ts@@ -0,0 +1 @@+export { resolveChatModel } from "./resolve-model";diff --git a/packages/ai/src/resolve-model.test.ts b/packages/ai/src/resolve-model.test.tsnew file mode 100644index 000000000..a1bfb3889--- /dev/null+++ b/packages/ai/src/resolve-model.test.ts@@ -0,0 +1,76 @@+import { expect } from "@std/expect";+import { afterEach, beforeEach, describe, test } from "@std/testing/bdd";++import { resolveChatModel } from "./resolve-model";++const ENV_KEYS = [+ "AI_BASE_URL",+ "AI_MODEL",+ "AI_API_KEY",+ "AI_GATEWAY_API_KEY",+];++function clearEnv() {+ for (const key of ENV_KEYS) delete process.env[key];+}++describe("resolveChatModel", () => {+ beforeEach(clearEnv);+ afterEach(clearEnv);++ test("returns null when no provider is configured", () => {+ expect(resolveChatModel({ plan: "free" })).toBeNull();+ });++ test("gateway path: free plan resolves the cheaper model string", () => {+ process.env.AI_GATEWAY_API_KEY = "gw-key";+ expect(resolveChatModel({ plan: "free" })).toBe(+ "anthropic/claude-haiku-4.5",+ );+ });++ test("gateway path: paid plan resolves the stronger model string", () => {+ process.env.AI_GATEWAY_API_KEY = "gw-key";+ expect(resolveChatModel({ plan: "team" })).toBe(+ "anthropic/claude-sonnet-4.5",+ );+ });++ test("self-host path: AI_BASE_URL + AI_MODEL builds a model, plan ignored", () => {+ process.env.AI_BASE_URL = "https://integrate.api.nvidia.com/v1";+ process.env.AI_API_KEY = "nvapi-test";+ process.env.AI_MODEL = "meta/llama-3.1-70b-instruct";+ const model = resolveChatModel({ plan: "free" });+ expect(model).not.toBeNull();+ expect(typeof model).toBe("object");+ expect((model as { modelId: string }).modelId).toBe(+ "meta/llama-3.1-70b-instruct",+ );+ });++ test("self-host path works without an API key (keyless local gateway)", () => {+ process.env.AI_BASE_URL = "http://localhost:11434/v1";+ process.env.AI_MODEL = "llama3.1";+ const model = resolveChatModel({ plan: "free" });+ expect(typeof model).toBe("object");+ expect((model as { modelId: string }).modelId).toBe("llama3.1");+ });++ test("self-host path takes priority over the gateway", () => {+ process.env.AI_GATEWAY_API_KEY = "gw-key";+ process.env.AI_BASE_URL = "https://integrate.api.nvidia.com/v1";+ process.env.AI_MODEL = "meta/llama-3.1-70b-instruct";+ expect(typeof resolveChatModel({ plan: "free" })).toBe("object");+ });++ test("AI_BASE_URL set but AI_MODEL missing returns null", () => {+ process.env.AI_BASE_URL = "https://integrate.api.nvidia.com/v1";+ expect(resolveChatModel({ plan: "free" })).toBeNull();+ });++ test("whitespace-only env values are treated as unset", () => {+ process.env.AI_BASE_URL = " ";+ process.env.AI_GATEWAY_API_KEY = " ";+ expect(resolveChatModel({ plan: "free" })).toBeNull();+ });+});diff --git a/packages/ai/src/resolve-model.ts b/packages/ai/src/resolve-model.tsnew file mode 100644index 000000000..b53fa1d76--- /dev/null+++ b/packages/ai/src/resolve-model.ts@@ -0,0 +1,51 @@+import { createOpenAICompatible } from "@ai-sdk/openai-compatible";+import type { WorkspacePlan } from "@openstatus/db/src/schema";+import type { LanguageModel } from "ai";++// Hosted openstatus.dev defaults, resolved through the Vercel AI Gateway as+// bare model strings. Free workspaces get the cheaper model because we pay for+// their inference; this tiering applies ONLY to the gateway path.+const GATEWAY_MODEL_FREE = "anthropic/claude-haiku-4.5";+const GATEWAY_MODEL_PAID = "anthropic/claude-sonnet-4.5";++// `||` (not `??`) so empty / whitespace-only env values fall back instead of+// being passed through as a real value.+function readEnv(name: string): string | undefined {+ return process.env[name]?.trim() || undefined;+}++/**+ * Resolve the chat model from environment, provider-agnostic.+ *+ * 1. Self-host (`AI_BASE_URL`): any OpenAI-compatible endpoint (NVIDIA NIM,+ * vLLM, Ollama, OpenRouter, …). Single `AI_MODEL`; `plan` is ignored+ * because the operator runs and pays for inference. `AI_API_KEY` is+ * optional so keyless local gateways work. The model MUST support tool+ * calling — the agent relies on it.+ * 2. Vercel AI Gateway (`AI_GATEWAY_API_KEY`): hosted default; `plan` selects+ * the model. Unchanged behavior.+ * 3. Neither configured → `null` (caller returns 503).+ */+export function resolveChatModel({+ plan,+}: {+ plan: WorkspacePlan;+}): LanguageModel | null {+ const baseURL = readEnv("AI_BASE_URL");+ if (baseURL) {+ const model = readEnv("AI_MODEL");+ if (!model) return null;+ const provider = createOpenAICompatible({+ name: "self-hosted",+ baseURL,+ apiKey: readEnv("AI_API_KEY"),+ });+ return provider.chatModel(model);+ }++ if (readEnv("AI_GATEWAY_API_KEY")) {+ return plan === "free" ? GATEWAY_MODEL_FREE : GATEWAY_MODEL_PAID;+ }++ return null;+}diff --git a/packages/ai/tsconfig.json b/packages/ai/tsconfig.jsonnew file mode 100644index 000000000..230005c38--- /dev/null+++ b/packages/ai/tsconfig.json@@ -0,0 +1,7 @@+{+ "extends": "@openstatus/tsconfig/base.json",+ "include": ["src", "*.ts"],+ "compilerOptions": {+ "noEmit": true+ }+}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 1c8e88032..43da4219d 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -9,6 +9,9 @@ catalogs:'@ai-sdk/anthropic':specifier: 1.2.12version: 1.2.12+ '@ai-sdk/openai-compatible':+ specifier: 2.0.54+ version: 2.0.54'@ai-sdk/react':specifier: 3.0.190version: 3.0.190@@ -596,6 +599,9 @@ importers:'@openpanel/nextjs':specifier: 'catalog:'version: 1.5.1([email protected](@opentelemetry/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])+ '@openstatus/ai':+ specifier: workspace:*+ version: link:../../packages/ai'@openstatus/analytics':specifier: workspace:*version: link:../../packages/analytics@@ -1725,6 +1731,34 @@ importers:specifier: 'catalog:'version: 5.9.3+ packages/ai:+ dependencies:+ '@ai-sdk/openai-compatible':+ specifier: 'catalog:'+ version: 2.0.54([email protected])+ ai:+ specifier: 'catalog:'+ version: 6.0.188([email protected])+ devDependencies:+ '@openstatus/db':+ specifier: workspace:*+ version: link:../db+ '@openstatus/tsconfig':+ specifier: workspace:*+ version: link:../tsconfig+ '@std/expect':+ specifier: jsr:^1.0.19+ version: '@jsr/[email protected]'+ '@std/testing':+ specifier: jsr:^1.0.19+ version: '@jsr/[email protected]'+ '@types/node':+ specifier: 'catalog:'+ version: 24.12.4+ typescript:+ specifier: 'catalog:'+ version: 5.9.3+packages/analytics:dependencies:'@openpanel/sdk':@@ -3045,6 +3079,12 @@ packages:peerDependencies:zod: ^3.25.76 || ^4.1.8+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-OyXt0zK8y2/ZIyWlbxTv2r1M7AK227S+Gl4BYOEF42q0wz1n5m4fwR8L4Fy/MQ4Ho6xje47MPsFcRdIqIyP6Rw==}+ engines: {node: '>=18'}+ peerDependencies:+ zod: ^3.25.76 || ^4.1.8+'@ai-sdk/[email protected]':resolution: {integrity: sha512-fqhG+4sCVv8x7nFzYnFo19ryhAa3w096Kmc3hWxMQfW/TubPOmt3A6tYZhl4mUfQWWQMsuSkLrtjlWuXBVSGQA==}engines: {node: '>=18'}@@ -3057,6 +3097,12 @@ packages:peerDependencies:zod: ^3.25.76 || ^4.1.8+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-nJ0bAfegMAIJtrzMJtbzer1cS3nb7c7DsyU1S4nrPm7ZU0Mn6SBBZv5IGZZGTbpWTJwqKTSPeZJTXalbAxt1BA==}+ engines: {node: '>=18'}+ peerDependencies:+ zod: ^3.25.76 || ^4.1.8+'@ai-sdk/[email protected]':resolution: {integrity: sha512-qZMxYJ0qqX/RfnuIaab+zp8UAeJn/ygXXAffR5I4N0n1IrvA6qBsjc8hXLmBiMV2zoXlifkacF7sEFnYnjBcqg==}engines: {node: '>=18'}@@ -3065,6 +3111,10 @@ packages:resolution: {integrity: sha512-Q3BZ27qfpYqnCYGvE3vt+Qi6LGOF9R5Nmzn+9JoM1lCRsD9mYaIhfJLkSunN48nfGXJ6n+XNV0J/XVpqGQl7Dw==}engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-sj9DWTJ2Ze0WR9qsiOPqoqzNx3OxL6iMxHImbhvoe9qOspekbzxNDMiJ4TIGfYHYh9w4OmBjz3prvqhzTi96+Q==}+ engines: {node: '>=18'}+'@ai-sdk/[email protected]':resolution: {integrity: sha512-ee8bZ3ZCC/PZDfCIX0LNvoPezo1v+jHp85pW6ct6B3qddsSp4SoFvapGuhK1gHRMLR6rKq0D5Gjii/+rgLzb9g==}engines: {node: '>=18'}@@ -11437,6 +11487,19 @@ snapshots:'@vercel/oidc': 3.2.0zod: 4.1.13+ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 3.0.10+ '@ai-sdk/provider-utils': 4.0.27([email protected])+ '@vercel/oidc': 3.2.0+ zod: 4.4.3++ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 3.0.12+ '@ai-sdk/provider-utils': 4.0.33([email protected])+ zod: 4.4.3+'@ai-sdk/[email protected]([email protected])':dependencies:'@ai-sdk/provider': 1.1.3@@ -11451,6 +11514,20 @@ snapshots:eventsource-parser: 3.0.8zod: 4.1.13+ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 3.0.10+ '@standard-schema/spec': 1.1.0+ eventsource-parser: 3.0.8+ zod: 4.4.3++ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 3.0.12+ '@standard-schema/spec': 1.1.0+ eventsource-parser: 3.0.8+ zod: 4.4.3+'@ai-sdk/[email protected]':dependencies:json-schema: 0.4.0@@ -11459,6 +11536,10 @@ snapshots:dependencies:json-schema: 0.4.0+ '@ai-sdk/[email protected]':+ dependencies:+ json-schema: 0.4.0+dependencies:'@ai-sdk/provider-utils': 4.0.27([email protected])@@ -15660,6 +15741,14 @@ snapshots:'@opentelemetry/api': 1.9.1zod: 4.1.13+ dependencies:+ '@ai-sdk/gateway': 3.0.118([email protected])+ '@ai-sdk/provider': 3.0.10+ '@ai-sdk/provider-utils': 4.0.27([email protected])+ '@opentelemetry/api': 1.9.1+ zod: 4.4.3+optionalDependencies:ajv: 8.17.1diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex a61cf7762..3f5864cf0 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -18,6 +18,7 @@ allowBuilds:autoInstallPeers: truecatalog:"@ai-sdk/anthropic": 1.2.12+ "@ai-sdk/openai-compatible": 2.0.54"@ai-sdk/react": 3.0.190"@astrojs/check": 0.9.9"@astrojs/react": 4.4.2