code: def write_key(
      settings: "Settings",
      key: Optional[str],
      api: Optional["InternalApi"] = None,
      anonymous: bool = False,
  ) -> None:
      if not key:
          raise ValueError("No API key specified.")
  
      # TODO(jhr): api shouldn't be optional or it shouldn't be passed, clean up callers
      api = api or InternalApi()
  
      # Normal API keys are 40-character hex strings. On-prem API keys have a
      # variable-length prefix, a dash, then the 40-char string.
      _, suffix = key.split("-", 1) if "-" in key else ("", key)
  
      if len(suffix) != 40:
          raise ValueError(
              "API key must be 40 characters long, yours was %s"
              % len(key)
          )
  
      if anonymous:
          api.set_setting(
              "anonymous", "true", globally=True, persist=True
          )
      else:
          api.clear_setting("anonymous", globally=True, persist=True)
  
      write_netrc(settings.base_url, "user", key)
  
file_path: wandb/wandb/sdk/lib/apikey.py
imports: import os
  import stat
  import sys
  import textwrap
  from functools import partial
  from typing import TYPE_CHECKING, Callable, Dict, Optional, Union
  from urllib.parse import urlparse
  import click
  import requests.utils
  import wandb
  from wandb.apis import InternalApi
  from wandb.errors import term
  from wandb.util import _is_databricks, isatty, prompt_choices
  from .wburls import wburls
label_desc: Use image node_id 5 for calling a global function with example usage: write_key(settings, key, api, anonymous) without return types