Wandb disable local api key storage

I am using a public computing server with a shared user, I’ve specify my wandb api key in the wandb.init() api call, however, after execution, it will store my api key in ~/.netrc, and overwrite the previous api key (may used by other users). Can I disable this behavior, or specify another file to cache my API key?

Hi @zqbi , happy to help. There is currently no option to list multiple api keys in a single netrc file. If you were to do this manually, wandb will default to the last listed api key to authenticate the user. The recommended approach for shared machine is:

  • set your api key in your environment os.environ["WANDB_API_KEY"]="<api-key>"
  • set your api key with wandb.login(key="<api-key>")

Please let me know if you have any questions.

Hi @mohammadbakir , thanks for replying.

I’ve tried to use this method, however, although now the wandb system use the API key specified in wandb.login(<api-key>) , the private API key is still saved in ~/.netrc, is there an approach to use the API key only in current session without saving?

Hi @zqbi ,

Unfortunately not, my recommendation here is to delete the file at the end of your code

import os
import wandb

wandb.login(key="<your api key>")
... #Business Logic

file_path = os.path.expanduser("~/.netrc")

# Check if the file exists before attempting to delete it
if os.path.exists(file_path):
    print(f"{file_path} has been deleted.")
    print(f"{file_path} does not exist.")

Hi @zqbi , since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!