Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/web/client/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ SUPABASE_SERVICE_ROLE_KEY="<Your Supabase service role key>"

# OpenRouter - Enables AI chat. Other providers are optional below
OPENROUTER_API_KEY="<Your api key from https://openrouter.ai/settings/keys>"
# Optional: override the OpenRouter API base URL (e.g. for self-hosted proxies or custom endpoints)
# Defaults to https://openrouter.ai/api/v1 when unset
# OPENROUTER_BASE_URL="https://your-proxy.example.com/api/v1"
Comment on lines +11 to +13
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Locate env schema file(s) and check how OPENROUTER_API_KEY is declared
fd -t f 'env.ts$' apps packages | head -50
echo '---'
rg -n 'OPENROUTER_API_KEY' --type=ts -C2
echo '---'
rg -n 'OPENROUTER_BASE_URL' --type=ts -C2

Repository: onlook-dev/onlook

Length of output: 4122


🏁 Script executed:

#!/bin/bash
# Check the full env.ts file to see if OPENROUTER_BASE_URL is declared
echo "=== apps/web/client/src/env.ts ===" 
cat apps/web/client/src/env.ts | head -150

Repository: onlook-dev/onlook

Length of output: 5928


Add OPENROUTER_BASE_URL to the env schema for consistency.

OPENROUTER_API_KEY is declared in the server schema at apps/web/client/src/env.ts:36, but the new OPENROUTER_BASE_URL variable (consumed at packages/ai/src/chat/providers.ts:59) is missing from the schema. Add it as optional to match the usage pattern:

OPENROUTER_BASE_URL: z.string().url().optional(),

Also add it to the runtimeEnv section for proper validation at build time.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/client/.env.example` around lines 11 - 13, The env schema is missing
the OPENROUTER_BASE_URL variable used by packages/ai/src/chat/providers.ts;
update the server/client env schema in env.ts to include OPENROUTER_BASE_URL as
an optional URL (use z.string().url().optional()) alongside OPENROUTER_API_KEY,
and add OPENROUTER_BASE_URL to the runtimeEnv block so it is validated at build
time.


# Codesandbox - Used to host user apps. Other providers may be supported in the future. May be optional in the future.
CSB_API_KEY="<Your api key from https://codesandbox.io/t/api>"
Expand Down
20 changes: 19 additions & 1 deletion packages/ai/src/chat/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,28 @@ export function initModel({
};
}

/**
* Returns the base URL for the OpenRouter provider.
*
* The lookup order is:
* 1. `OPENROUTER_BASE_URL` environment variable (explicit override)
* 2. The default OpenRouter API endpoint
*
* This allows self-hosted deployments and proxy setups to point Onlook at a
* custom endpoint without modifying source code.
*/
function getOpenRouterBaseUrl(): string | undefined {
return process.env.OPENROUTER_BASE_URL || undefined;
}

function getOpenRouterProvider(model: OPENROUTER_MODELS): LanguageModel {
if (!process.env.OPENROUTER_API_KEY) {
throw new Error('OPENROUTER_API_KEY must be set');
}
const openrouter = createOpenRouter({ apiKey: process.env.OPENROUTER_API_KEY });
const baseURL = getOpenRouterBaseUrl();
const openrouter = createOpenRouter({
apiKey: process.env.OPENROUTER_API_KEY,
...(baseURL && { baseURL }),
});
return openrouter(model);
}