Search results give an application source material from the web rather than a model-generated answer. Ollama web search returns page titles, URLs, and content snippets that an application can use as retrieval context.

Web search runs on Ollama's hosted service, separate from local model inference. No local Ollama server or model download is required, and the response does not automatically summarize or verify its sources.

You need a Unix-like shell, curl 7.76 or later, Python 3, and an existing Ollama account API key with access to web search. Queries leave your computer, and anyone holding the key can use the account's API access and available credits.

Steps to use Ollama web search with the API:

  1. Create a private ollama-search directory in a location outside source control and cloud-synced folders.
    $ mkdir -m 700 ollama-search

    The directory is accessible only to your user. An existing directory causes this command to fail instead of changing its permissions.

  2. Create ollama-search/header.txt in your text editor with your API key in place of YOUR_OLLAMA_API_KEY.

    This file contains the key in plain text. Editor backups and swap files may also contain it. A leaked key must be revoked in Ollama API key settings; deleting a file or clearing a variable does not revoke it.

    Authorization: Bearer YOUR_OLLAMA_API_KEY
  3. Restrict the header file to owner-only access.
    $ chmod 600 ollama-search/header.txt
  4. Send one hosted search request for Ollama's official documentation.
    $ curl --fail-with-body --silent --show-error https://ollama.com/api/web_search \
      -H @ollama-search/header.txt \
      -H 'Content-Type: application/json' \
      -d '{"query":"Ollama official documentation","max_results":1}' \
      --output ollama-search/results.json \
      --write-out 'HTTP %{http_code}\n'
    HTTP 200

    The bearer header is read from the file, so the key stays out of curl's command arguments and shell history. Verbose or trace output can expose it. The required query is the search text; max_results limits the result count and accepts at most 10. The response replaces results.json on each request. HTTP errors make curl exit with code 22 while preserving the error body. HTTP 401 indicates missing or invalid authentication; HTTP 402 indicates that usage credits are required.

  5. Inspect the saved result for a relevant title, URL, and content snippet.
    $ python3 -m json.tool ollama-search/results.json
    {
        "results": [
            {
                "title": "Ollama documentation - Ollama",
                "url": "https://docs.ollama.com/",
    ##### snipped #####
            }
        ]
    }

    A nonempty results array contains the returned pages; the content field is omitted above. Rankings and snippets can change between requests. An error object or an empty array does not provide a usable search result. The saved response remains available to your application. Retrieved content is untrusted input and can contain misleading claims or instructions; it does not authorize running commands or changing application rules.

Share this guide