Positron not loading Anthropic API keys from R environment vars #15244
|
In the Configure Language Model Providers dialog, it says: I have both of these defined in my .Renviron file, and can confirm that they are loaded into the environment. Yet even after restarting Positron, I cannot authenticate with Anthropic. (If I enter the key directly into the dialog, it works fine). |
Replies: 1 comment 1 reply
|
Ah, I can see how this might be confusing. When R starts up it reads flowchart TB
shell["Shell config<br/>(~/.zshenv, ~/.zprofile, ...)"]
renviron["~/.Renviron"]
subgraph positron["Positron"]
assistant["Assistant<br/>looks for ANTHROPIC_API_KEY<br/>in Positron's environment"]
rsession["R session<br/>(child process)<br/>Sys.getenv() sees the key"]
assistant -- "sends code, asks for variables" --> rsession
rsession -- "returns output and results" --> assistant
end
shell == "environment inherited when Positron starts" ==> positron
renviron -. "read by R alone, when the R session starts" .-> rsession
Notice the dotted arrow and how it stops at the R session and never reaches the assistant. To make the variables visible to Positron itself, set them in your shell environment rather than in
You can leave them in That said, entering the key directly in the dialog is a perfectly good option too. It gets stored in your OS keychain rather than sitting in a dotfile, so there is no need to switch if that is working for you. |
Ah, I can see how this might be confusing.
.Renvironis read by R itself, not by Positron.When R starts up it reads
.Renvironand sets those variables in its own process environment. SoSys.getenv("ANTHROPIC_API_KEY")in the R console shows the value, and everything looks correct from inside R. But the R session is a child process that lives inside Positron, and the variables only exist there. The assistant looks forANTHROPIC_API_KEYandANTHROPIC_BASE_URLin Positron's own environment, which never sees.Renviron:flowchart TB shell["Shell config<br/>(~/.zshenv, ~/.zprofile, ...)"] renviron["~/.Renviron"] subgraph positron["Positron"] assistant["Assistant<br/>loo…