mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 00:55:21 -04:00
How to implment access token or other form of authorization #99
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @PhilipAmadasun on GitHub (Jun 11, 2024).
Is it possible to implement access tokens with this library? I'm basically looking for a way to implement authorization.
@ajrodrigues commented on GitHub (Sep 26, 2024):
I was trying to do that using headers to pass the API Key:
client = Client(host='https://localhost:11434',headers=["x-token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"])
But after that I get a different error:
File "C:\Python312\Lib\site-packages\ollama_client.py", line 67, in init
super().init(httpx.Client, host, **kwargs)
File "C:\Python312\Lib\site-packages\ollama_client.py", line 52, in init
headers['Content-Type'] = 'application/json'
~~~~~~~^^^^^^^^^^^^^^^^
TypeError: list indices must be integers or slices, not str
@westbrook-ai commented on GitHub (Feb 24, 2025):
I was wondering the same thing and was able to get it work using the example below:
I hope this helps someone in the future!
@ramibch commented on GitHub (Nov 5, 2025):
Many thanks to @westbrook-ai for sharing that code snippet! 🙏
If someone wants to implement this Authorization feature with a Cloudflare Tunnel, you can point it to a local reverse proxy. For example, you can use something like this reverse-proxy
With this setup, you can secure your Ollama server over the internet using an authorization token.