A way to set OLLAMA_API_KEY for web_search #302

Closed
opened 2026-02-15 16:29:46 -05:00 by yindo · 1 comment
Owner

Originally created by @BELKHIR on GitHub (Oct 9, 2025).

Hi,
To call web_search or web_fetch, on have to set the environment variable OLLAMA_API_KEY before launching a python code.

I you want to set the environment variable OLLAMA_API_KEY inside the code, you have to set it (via os.environ["OLLAMA_API_KEY"] = key) before importing ollama !

This is set in _client.py which is loaded during module initialization.

Any way to let functions requiring an Ollama api key to be called with the key instead of relying on environment variable ?

Many thanks,

Originally created by @BELKHIR on GitHub (Oct 9, 2025). Hi, To call web_search or web_fetch, on have to set the environment variable OLLAMA_API_KEY before launching a python code. I you want to set the environment variable OLLAMA_API_KEY inside the code, you have to set it (via os.environ["OLLAMA_API_KEY"] = key) before importing ollama ! This is set in _client.py which is loaded during module initialization. Any way to let functions requiring an Ollama api key to be called with the key instead of relying on environment variable ? Many thanks,
yindo closed this issue 2026-02-15 16:29:46 -05:00
Author
Owner

@ParthSareen commented on GitHub (Oct 15, 2025):

Yes! You can instantiate a client yourself like:

from ollama import Client

client = Client(headers={'Authorization': f"Bearer {os.getenv('OLLAMA_API_KEY')}"})
@ParthSareen commented on GitHub (Oct 15, 2025): Yes! You can instantiate a client yourself like: ```python from ollama import Client client = Client(headers={'Authorization': f"Bearer {os.getenv('OLLAMA_API_KEY')}"}) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#302