feat: add OpenRouter audit generation pipeline
This commit is contained in:
35
lib/ai/openrouter-provider.ts
Normal file
35
lib/ai/openrouter-provider.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
||||
|
||||
type OpenRouterEnv = Readonly<Record<string, string | undefined>>;
|
||||
|
||||
function normalizeOptionalEnvValue(value: string | undefined): string | undefined {
|
||||
if (typeof value !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const trimmed = value.trim();
|
||||
return trimmed === "" ? undefined : trimmed;
|
||||
}
|
||||
|
||||
export function createOpenRouterProvider(
|
||||
env: OpenRouterEnv = process.env,
|
||||
): ReturnType<typeof createOpenRouter> {
|
||||
const apiKey = normalizeOptionalEnvValue(env.OPENROUTER_API_KEY);
|
||||
|
||||
if (!apiKey) {
|
||||
throw new Error("OPENROUTER_API_KEY is required for OpenRouter provider.");
|
||||
}
|
||||
|
||||
const appName = normalizeOptionalEnvValue(env.OPENROUTER_APP_NAME);
|
||||
const appUrl = normalizeOptionalEnvValue(env.OPENROUTER_APP_URL);
|
||||
|
||||
return createOpenRouter({
|
||||
apiKey,
|
||||
appName,
|
||||
appUrl,
|
||||
compatibility: "strict",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user