Fix openrouter proxy baseURL to honor FORWARD_TO_PRODUCTION

Previously the AI proxy baseURL was chosen based on NODE_ENV alone,
which caused dev requests to loop back to the local proxy and forward
"Bearer FORWARD_TO_PRODUCTION" upstream. Switch on the env var instead
and use NEXT_PUBLIC_STACK_API_URL as the default base.
This commit is contained in:
Bilal Godil 2026-04-13 14:50:38 -07:00
parent f7c6e69704
commit 7d466f6b00

View File

@ -1,5 +1,5 @@
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { getNodeEnvironment } from "@stackframe/stack-shared/dist/utils/env";
import { getEnvVariable } from "@stackframe/stack-shared/dist/utils/env";
export type ModelQuality = "dumb" | "smart" | "smartest";
export type ModelSpeed = "slow" | "fast";
@ -59,9 +59,9 @@ export const ALLOWED_MODEL_IDS: ReadonlySet<string> = new Set([
]);
export function createOpenRouterProvider() {
const baseURL = getNodeEnvironment() === "development"
? "http://localhost:8102/api/latest/integrations/ai-proxy/v1"
: "https://api.stack-auth.com/api/latest/integrations/ai-proxy/v1";
const baseURL = getEnvVariable("STACK_OPENROUTER_API_KEY", "") === "FORWARD_TO_PRODUCTION"
? "https://api.stack-auth.com/api/latest/integrations/ai-proxy/v1"
: `${getEnvVariable("NEXT_PUBLIC_STACK_API_URL")}/api/latest/integrations/ai-proxy/v1`;
return createOpenRouter({
apiKey: "forwarded",
baseURL,