Skip to content

fix: accept BRAVE_SEARCH_API_KEY for Brave web search - #19186

Closed
Plutarch01 wants to merge 2 commits into
openclaw:mainfrom
Plutarch01:fix/brave-search-key-alias-clean
Closed

Plutarch01 wants to merge 2 commits into
openclaw:mainfrom
Plutarch01:fix/brave-search-key-alias-clean

Conversation

@Plutarch01

@Plutarch01 Plutarch01 commented Feb 17, 2026 •

Copy link
Copy Markdown

Summary

  • accept BRAVE_SEARCH_API_KEY as an env-var alias when resolving Brave web search API credentials
  • preserve existing precedence: explicit config apiKey, then BRAVE_API_KEY, then BRAVE_SEARCH_API_KEY
  • update missing-key guidance text to mention both supported Brave env vars

Testing

  • pre-commit formatting/lint hook passed during commit on this branch
  • verified branch diff is isolated to src/agents/tools/web-search.ts

Notes

Greptile Summary

This PR adds BRAVE_SEARCH_API_KEY as a fallback environment variable for Brave web search API credentials in resolveSearchApiKey(), preserving the existing precedence: explicit config apiKey > BRAVE_API_KEY > BRAVE_SEARCH_API_KEY. The error message is updated to mention both supported env vars. The change is minimal and well-scoped.

  • The core logic in resolveSearchApiKey() correctly chains the new env var as a third fallback
  • Import reordering groups type imports together (cosmetic, no functional impact)
  • Missing update: hasWebSearchKey() in src/security/audit-extra.sync.ts also needs to check for BRAVE_SEARCH_API_KEY, otherwise the audit will incorrectly report the key as missing when only the new alias is set
  • Several other files reference only BRAVE_API_KEY in user-facing guidance text (onboarding, configure wizard, config schema help, type comments) — not bugs, but worth a follow-up to mention both env vars for consistency

Confidence Score: 4/5

  • This PR is safe to merge — the core change is correct, but a related audit function in another file should be updated to stay consistent.
  • The change is small, well-scoped, and the fallback logic is correct. Deducting one point because hasWebSearchKey() in audit-extra.sync.ts was not updated, which could cause the security audit to misreport key availability when only BRAVE_SEARCH_API_KEY is set.
  • src/security/audit-extra.sync.ts — the hasWebSearchKey function needs to also check for BRAVE_SEARCH_API_KEY to match the new runtime behavior.

Last reviewed commit: dc5161c

(4/5) You can add custom instructions or style guidelines for the agent here!

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +188 to +189
const fromOpenWebUIEnv = normalizeSecretInput(process.env.BRAVE_SEARCH_API_KEY);
return fromConfig || fromEnv || fromOpenWebUIEnv || undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Audit check not updated for new alias

The hasWebSearchKey function in src/security/audit-extra.sync.ts:258-267 checks for env.BRAVE_API_KEY but does not check for env.BRAVE_SEARCH_API_KEY. This means that if a user sets only BRAVE_SEARCH_API_KEY, the web search tool will work at runtime (because of this change), but the security audit will incorrectly report the key as missing. Consider adding env.BRAVE_SEARCH_API_KEY to the hasWebSearchKey check as well:

function hasWebSearchKey(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): boolean {
  const search = cfg.tools?.web?.search;
  return Boolean(
    search?.apiKey ||
    search?.perplexity?.apiKey ||
    env.BRAVE_API_KEY ||
    env.BRAVE_SEARCH_API_KEY ||
    env.PERPLEXITY_API_KEY ||
    env.OPENROUTER_API_KEY,
  );
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/tools/web-search.ts
Line: 188:189

Comment:
**Audit check not updated for new alias**

The `hasWebSearchKey` function in `src/security/audit-extra.sync.ts:258-267` checks for `env.BRAVE_API_KEY` but does not check for `env.BRAVE_SEARCH_API_KEY`. This means that if a user sets only `BRAVE_SEARCH_API_KEY`, the web search tool will work at runtime (because of this change), but the security audit will incorrectly report the key as missing. Consider adding `env.BRAVE_SEARCH_API_KEY` to the `hasWebSearchKey` check as well:

```
function hasWebSearchKey(cfg: OpenClawConfig, env: NodeJS.ProcessEnv): boolean {
  const search = cfg.tools?.web?.search;
  return Boolean(
    search?.apiKey ||
    search?.perplexity?.apiKey ||
    env.BRAVE_API_KEY ||
    env.BRAVE_SEARCH_API_KEY ||
    env.PERPLEXITY_API_KEY ||
    env.OPENROUTER_API_KEY,
  );
}
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 4e7f6dc on this PR branch. hasWebSearchKey now includes BRAVE_SEARCH_API_KEY so the audit check matches runtime key resolution.

@Plutarch01

Copy link
Copy Markdown
Author

Good catch — fixed in 4e7f6dc. I updated in to include , so audit behavior now matches runtime key resolution.

@Plutarch01

Copy link
Copy Markdown
Author

Update: addressed in commit 4e7f6dc. hasWebSearchKey in src/security/audit-extra.sync.ts now checks BRAVE_SEARCH_API_KEY in addition to BRAVE_API_KEY, so audit and runtime behavior are aligned.

@Plutarch01 Plutarch01 closed this by deleting the head repository Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant