r/OpenWebUI 2026 threads complain that the built-in web search tool fires on every prompt, burning credits and slowing responses. The fix is a conditional search layer: a lightweight classifier decides whether the query needs real-time data, and only then calls Scavio. This tutorial wires the classifier into OpenWebUI's function framework.
Prerequisites
- OpenWebUI 0.5+ self-hosted
- A Scavio API key
- Python 3.10+
- A local small LLM or regex classifier
Walkthrough
Step 1: Create an OpenWebUI function
Functions live in admin settings > functions > new.
# File: conditional_search.py
from pydantic import BaseModel
import os, requests, reStep 2: Write the need-search classifier
Start simple: regex keywords that signal freshness need.
NEEDS_SEARCH = re.compile(r'\b(today|latest|2026|news|price|current|right now|recent)\b', re.I)
def needs_search(prompt: str) -> bool:
return bool(NEEDS_SEARCH.search(prompt))Step 3: Call Scavio only when needed
Wrap the OpenWebUI tool interface.
class Tools:
def search_web(self, query: str) -> str:
if not needs_search(query):
return ''
r = requests.post('https://api.scavio.dev/api/v1/search',
headers={'x-api-key': os.environ['SCAVIO_API_KEY']},
json={'query': query})
return str(r.json().get('organic_results', [])[:5])Step 4: Register as the default web search tool
In OpenWebUI settings > tools, set conditional_search as the active provider.
# Admin > Tools > Web Search > Provider: conditional_searchStep 5: Monitor savings
Check the function call count before and after. Expect 60-80% credit reduction.
# OpenWebUI > Admin > Usage > conditional_search.search_webPython Example
import os, requests, re
API_KEY = os.environ['SCAVIO_API_KEY']
NEEDS = re.compile(r'\b(today|latest|2026|news|price|current|recent)\b', re.I)
def maybe_search(prompt):
if not NEEDS.search(prompt):
return None
r = requests.post('https://api.scavio.dev/api/v1/search',
headers={'x-api-key': API_KEY},
json={'query': prompt})
return r.json().get('organic_results', [])[:5]
print(maybe_search('Explain quicksort'))
print(maybe_search('latest Claude 4.7 release notes'))JavaScript Example
const API_KEY = process.env.SCAVIO_API_KEY;
const NEEDS = /\b(today|latest|2026|news|price|current|recent)\b/i;
export async function maybeSearch(prompt) {
if (!NEEDS.test(prompt)) return null;
const r = await fetch('https://api.scavio.dev/api/v1/search', {
method: 'POST',
headers: { 'x-api-key': API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({ query: prompt })
});
const data = await r.json();
return data.organic_results?.slice(0, 5);
}Expected Output
Static prompts (math, code) skip the search call. Freshness-sensitive prompts trigger Scavio. Typical savings: 60-80% fewer API calls vs. unconditional search.