← All projects

shipped

litellm-claude-code-websearch

A LiteLLM plugin that makes Claude Code's WebSearch tool work against local models, running the search through Brave and answering in the native Anthropic block format.

PythonLiteLLMBrave Search APIClaude Code

Highlights

  • Standalone WebSearch requests never reach the backend LLM: the plugin extracts the query, calls Brave, and returns a synthetic response in the canonical server_tool_use block sequence.
  • Claude Code renders results exactly as it does against real Anthropic: the "Did 1 search" line, result links, domain filters.
  • Main-agent requests pass through byte-identical; only the search short-circuit is intercepted.
  • Configured entirely by environment variables, with a daily search cap that degrades to a graceful "search unavailable" text instead of an error.
  • Pure callback, no monkeypatches: pip-installable against stock LiteLLM.

Claude Code runs a web search by sending a standalone request whose only tool is the Anthropic server tool web_search_20250305. Real Anthropic executes the search server-side. A local vLLM backend can’t, so without help the request errors and WebSearch is dead for every proxied local model.

This plugin subclasses LiteLLM’s own web-search interception machinery: when every tool in a request is a web-search tool, it extracts the query from Claude Code’s prompt boilerplate, runs it through any LiteLLM search provider (Brave by default), and returns the native server_tool_use, web_search_tool_result, and text blocks so the client renders real results. Requests that carry other tools pass through untouched.

It ships as a pip package with a one-line callback registration and env-var config for provider, result count, API key file, daily budget, and an optional JSONL tap for observability. Streaming the native blocks to clients depends on a LiteLLM fix under review (#37318); non-streaming works on stock LiteLLM. It’s the search layer inside BlackwellQwen38.