Skip to content

feat(ollama): add bearer token as optional setting#165325

Open
ziouf wants to merge 6 commits intohome-assistant:devfrom
ziouf:feat/ollama-bearer-token
Open

feat(ollama): add bearer token as optional setting#165325
ziouf wants to merge 6 commits intohome-assistant:devfrom
ziouf:feat/ollama-bearer-token

Conversation

@ziouf
Copy link

@ziouf ziouf commented Mar 11, 2026

This is my first contribution to this wonderful project. Please do not hesitate to point out any mistakes I may have made.

Proposed change

Implements ollama bearer token as an optional ollama integration setting

As described here : https://docs.ollama.com/api/authentication#api-keys

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings March 11, 2026 11:27
@ziouf ziouf requested a review from synesthesiam as a code owner March 11, 2026 11:27
Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ziouf

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant bot marked this pull request as draft March 11, 2026 11:27
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link

Hey there @synesthesiam, mind taking a look at this pull request as it has been labeled with an integration (ollama) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of ollama can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign ollama Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for authenticating to an Ollama endpoint using an optional Bearer token, intended for setups (e.g., proxies) that require an Authorization header.

Changes:

  • Add api_key field to the Ollama config flow UI strings.
  • Introduce CONF_API_KEY and attempt to use it to pass an Authorization: Bearer ... header when creating the Ollama client.
  • Update integration setup to also pass the optional Authorization header at runtime.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
homeassistant/components/ollama/strings.json Adds UI label for an API key field in the config flow.
homeassistant/components/ollama/const.py Introduces CONF_API_KEY constant.
homeassistant/components/ollama/config_flow.py Attempts to read api_key from user input and pass Authorization headers during connection validation.
homeassistant/components/ollama/__init__.py Passes optional Authorization headers when creating the runtime ollama.AsyncClient.

@ziouf ziouf force-pushed the feat/ollama-bearer-token branch 2 times, most recently from 38ca91d to c07595a Compare March 11, 2026 12:54
@ziouf ziouf marked this pull request as ready for review March 11, 2026 12:59
Copilot AI review requested due to automatic review settings March 11, 2026 12:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so the Ollama integration integrates with Ollama. In the issue linked, people talk about running a proxy in front of Ollama which requires the auth. So I don't think this is something the integration should be concerned about. Now bearer tokens are used, tomorrow basic auth, and another day later someone comes with OAuth, which would grow the scope of the integration, while from what I understand, Ollama doesn't support it.

So I personally think we should close this PR as from what I understand, this isn't a feature offered by Ollama

@home-assistant home-assistant bot marked this pull request as draft March 11, 2026 15:53
@ziouf
Copy link
Author

ziouf commented Mar 11, 2026

Okay so the Ollama integration integrates with Ollama. In the issue linked, people talk about running a proxy in front of Ollama which requires the auth. So I don't think this is something the integration should be concerned about. Now bearer tokens are used, tomorrow basic auth, and another day later someone comes with OAuth, which would grow the scope of the integration, while from what I understand, Ollama doesn't support it.

So I personally think we should close this PR as from what I understand, this isn't a feature offered by Ollama

It's very strange reasoning to close a PR that implements a feature missing from the integration on the pretext that one day someone might ask to add another feature that is unrelated to this PR...

I personally need to be able to connect with Ollama's bearer token. The issue linked in the PR mentioned the same need, in my opinion. So I linked it as a courtesy.

If, one day, someone ever asks to integrate an authentication feature that is not natively supported by ollama, you will be perfectly justified in refusing.
But refusing the bearer token today makes no sense.

FYI: https://docs.ollama.com/api/authentication#api-keys

@ziouf ziouf marked this pull request as ready for review March 11, 2026 19:13
Copilot AI review requested due to automatic review settings March 11, 2026 19:13
@home-assistant home-assistant bot requested a review from joostlek March 11, 2026 19:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama integration does not support Bearer tokens

4 participants