Skip to content

Commit 3b3f5db

Browse files
fix: distinguish API key source (env var vs .env vs config file)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dba6106 commit 3b3f5db

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/lib/folders.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ export async function resolveApiKey(): Promise<string> {
88
if (cachedKey) return cachedKey;
99

1010
if (env.apiKey) {
11-
p.log.info("Using API key from environment");
11+
let source = "config (~/.scrapegraphai/config.json)";
12+
if (process.env.SGAI_API_KEY) {
13+
source = "SGAI_API_KEY env var";
14+
try {
15+
if (/^SGAI_API_KEY\s*=/m.test(readFileSync(".env", "utf-8"))) source = ".env file";
16+
} catch {}
17+
}
18+
p.log.info(`Using API key from ${source}`);
1219
cachedKey = env.apiKey;
1320
return env.apiKey;
1421
}

0 commit comments

Comments
 (0)