Files
property-management-network/lib/ai/anthropic.ts
T

16 lines
559 B
TypeScript
Raw Normal View History

import Anthropic from "@anthropic-ai/sdk"
// Lazily construct the Anthropic client so `next build` does NOT require
// ANTHROPIC_API_KEY — it's only needed at runtime when the admin selects the
// Anthropic (Claude) provider for AI features. Mirrors lib/ai/client.ts.
let _anthropic: Anthropic | null = null
export function getAnthropic(): Anthropic {
if (!_anthropic) {
const key = process.env.ANTHROPIC_API_KEY
if (!key) throw new Error("ANTHROPIC_API_KEY is not set")
_anthropic = new Anthropic({ apiKey: key })
}
return _anthropic
}