ScavioScavio
ProductPricingDocs
Sign InGet Started
  1. Home
  2. Tutorials
  3. How to Do Conditional Web Search in OpenWebUI
Tutorial

How to Do Conditional Web Search in OpenWebUI

OpenWebUI runs web search on every query by default, burning credits. Gate search behind a classifier so it only fires when the model actually needs it.

Get Free API KeyAPI Docs

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.

Python
# File: conditional_search.py
from pydantic import BaseModel
import os, requests, re

Step 2: Write the need-search classifier

Start simple: regex keywords that signal freshness need.

Python
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.

Python
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.

Text
# Admin > Tools > Web Search > Provider: conditional_search

Step 5: Monitor savings

Check the function call count before and after. Expect 60-80% credit reduction.

Text
# OpenWebUI > Admin > Usage > conditional_search.search_web

Python Example

Python
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

JavaScript
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

JSON
Static prompts (math, code) skip the search call. Freshness-sensitive prompts trigger Scavio. Typical savings: 60-80% fewer API calls vs. unconditional search.

Related Tutorials

  • How to Replace Claude's Built-in MCP Web Search with Scavio
  • How to Replace Tavily with Scavio (Migration Guide)
  • How to Add Real-Time Search to Claude via MCP

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

OpenWebUI 0.5+ self-hosted. A Scavio API key. Python 3.10+. A local small LLM or regex classifier. A Scavio API key gives you 50 free credits on signup.

Yes. The free tier includes 50 credits on signup, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Related Resources

Best Of

Best Search API for Open WebUI in 2026

Read more
Best Of

Best Search APIs for OpenWebUI in May 2026

Read more
Solution

Boost RAG Accuracy with Hybrid Web Search

Read more
Use Case

OpenWebUI Reliable Search Backend

Read more
Use Case

Local LLM Search Grounding via API

Read more
Solution

Local RAG with Search API Fallback

Read more

Start Building

OpenWebUI runs web search on every query by default, burning credits. Gate search behind a classifier so it only fires when the model actually needs it.

Get Free API KeyRead the Docs
ScavioScavio

Real-time search API for AI agents. Search every platform, not just Google.

Product

  • Features
  • Pricing
  • Dashboard
  • Affiliates

Developers

  • Documentation
  • API Reference
  • Quickstart
  • MCP Integration
  • Python SDK

Alternatives

  • Tavily Alternative
  • SerpAPI Alternative
  • Firecrawl Alternative
  • Exa Alternative

Tools

  • JSON Formatter
  • cURL to Code
  • Token Counter
  • All Tools

© 2026 Scavio. All rights reserved.

Featured on TAAFT
Terms of ServicePrivacy Policy