I have just started using ChatGPT enabled Notebooks in Cloud Mathematic. Very powerful!. I enter my API key and click the Save API key and everything works as expected, Unfortunately, I’m periodically prompted to re-enter it. Perhaps it’s only saved by session. I would like to enter the API key and make it available globally and persistently. I’ve looked here and through Mathematic Help Docs, but can’t seem to find it.
You are correct that the prompt to “Save API key” in the notebook interface often only saves it for the current session or device cache, which can expire or be cleared.
To achieve the global and persistent availability you are looking for, you need to save the key to a secure, permanent location that the Wolfram System can access automatically.
Persistent Storage in the Wolfram Cloud
Using SetCloudAPICredentials
This function is designed to securely store API keys in your cloud account, making them available to any notebook or function you run there.
Note: Replace "YOUR_OPENAI_API_KEY_HERE with your actual API key.
Access the Credential
The key is now stored securely in the your Wolfram Cloud account. In any future session or notebook, you can retrieve it automatically:
$APICredentials["ChatGPT"]
Use in Code
When using a function that requires the key, you can pass the retrieved credential directly. For instance, with the built-in ChatGPT functionality:
ChatAPICredentials = $APICredentials["ChatGPT"];
(* Now the Chat function will use this key automatically *)
Chat["Explain the concept of persistent key storage in the Wolfram Cloud.", ChatAPICredentials]