WIPIVERSE All articles

Tungsten(III) chloride

Ollama Web Search is a REST API introduced by Ollama in September 2025 that enables large language models (LLMs) to query the internet in real time, augmenting their responses with up-to-date information to reduce hallucinations and improve accuracy.

Overview

Ollama is a platform for running large language models locally on macOS, Windows, and Linux. The Web Search API extends its capabilities by allowing models to access live web data, addressing the limitation of static training data. It is provided as a REST API with deeper tool integrations in Ollama's Python and JavaScript libraries.

API Endpoints

Web Search (/api/web_search)

  • Method: POST to https://ollama.com/api/web_search
  • Parameters:
    • query (string, required): The search query string.
    • max_results (integer, optional): Maximum results to return (default: 5, max: 10).
  • Response: Returns an object containing a results array, where each result includes title, url, and content (a relevant snippet).

Web Fetch (/api/web_fetch)

  • Method: POST to https://ollama.com/api/web_fetch
  • Parameters:
    • url (string, required): The URL of the page to fetch.
  • Response: Returns an object containing title, content (main page content), and links (array of links found on the page).

Authentication

Access requires an API key generated from an Ollama account. The key is passed via the Authorization header or set as the OLLAMA_API_KEY environment variable.

Usage Examples

cURL:

curl https://ollama.com/api/web_search \
  --header "Authorization: Bearer $OLLAMA_API_KEY" \
  -d '{ "query": "what is ollama?" }'

Python:

import ollama
response = ollama.web_search("What is Ollama?")

JavaScript:

import { Ollama } from "ollama";
const client = new Ollama();
const results = await client.webSearch({ query: "what is ollama?" });

Building Search Agents

Ollama provides examples of building mini search agents that use both web_search and web_fetch as tools. The recommended approach involves a chat loop where the model decides when to call these tools, processes the results, and continues the conversation. Models with strong tool-use capabilities (such as Qwen 3 and gpt-oss) are recommended for this purpose. A minimum context length of approximately 32,000 tokens is advised for reasonable performance.

MCP Server Integration

Ollama also offers an MCP (Model Context Protocol) Server that standardizes interactions between models and external tools. This server enables integration with clients such as Cline, Codex, and Goose, allowing models to perform web searches, file operations, and other tasks through a standardized protocol.

Pricing

Ollama provides a generous free tier of web searches for individual use. Higher rate limits are available through Ollama's cloud subscription service.

Key Benefits

  • Reduced Hallucinations: By retrieving current information from the web, models produce more accurate responses.
  • Real-Time Data: Enables models to answer questions about recent events, dynamic data, and topics beyond their training cutoff.
  • Open-Source: The platform is open-source, allowing customization without vendor lock-in.
  • Cross-Platform: Available on macOS, Windows, and Linux.
Browse

More topics to explore

    Browse all articles