Cannot load api key from ~\.authinfo
Opened this issue · 7 comments
I have this config in doom emacs
(setq-default gptel-model 'm-gpt-4o-mini-18072024)
(setq gptel-backend (gptel-make-azure "Azure-1-GPT-4o-mini"
:protocol "https"
:host "<MY_HOST>.openai.azure.com"
:endpoint "/openai/deployments/m-gpt-4o-mini-18072024/chat/completions?api-version=2024-08-01-preview"
:stream t
:key #'gptel-api-key-from-auth-source
:models '(m-gpt-4o-mini-18072024)))
Is this correct?
Cause I have the file
~/.authinfo
with
machine api.openai.com login apikey password <MY_TOKEN>
But I'm asked for a GPT API key every time I open gptel
.
What happens if you run (gptel-api-key-from-auth-source)
? Does it return the key?
I suppose the problem is that your ~/.authinfo
's machine api.openai.com
doesn't match your gptel-backend
's :host "<MY_HOST>.openai.azure.com"
?
@tsoernes gptel-api-key-from-auth-source
looks up the :host
in your authinfo. So the authinfo entry should look like
machine <MY_HOST>.openai.azure.com login apikey password <MY_TOKEN>
OR
You can write your own function that looks up the right key in your authinfo and use that in place of gptel-api-key-from-auth-source
.
im not sure If I should answer here but I have the same Issue except with ChatGPT. Do you use windows? It doesnt find the file in windows but within WSL2 it works with just the same config and .authinfo file. Seems to be a path issue on my side.
It works on both systems if I use the following approach:
(require 'gptel)
(setq auth-sources '("~/.authinfo"))
(setq gptel-api-key (auth-source-pick-first-password :host "api.openai.com"))
I had the same problem on doom emacs and was not able to fully resolve it. On initial startup it would never read or prompt for the gpg password, but when I cleared the authinfo cache with (auth-source-forget-all-cached)
and ran the authinfo read function again, it successfully read and stored the key.
On my custom configuration it worked without any issues, which makes me think there's something that doom does in how it works with desktop environment password prompts.