Skip to content

Improve API Key Management by using Google Colab Secrets #35

@maxploter

Description

@maxploter

Is your feature request related to a problem? Please describe.
Currently, the tutorials in this project require users to manage API keys by creating local files (nebius_api_key, openai_api_key) and then manually uploading these files to their Google Colab environment. This process has a few drawbacks:

  • Repetitive Uploads
  • Potential Security Concerns

I propose updating the notebooks to use Google Colab's built-in "Secrets" feature for managing API keys as an alternative to current file based solution. This feature allows users to store sensitive data like API keys directly within their Colab environment, accessible via the google.colab.userdata module. Secrets are tied to the user's Google account and persist across Colab sessions for that user.

try:
    from google.colab import userdata
    IS_COLAB = True
except ImportError:
    IS_COLAB = False
import os

if not IS_COLAB:
  with open("nebius_api_key", "r") as file:
      nebius_api_key = file.read().strip()

  os.environ["NEBIUS_API_KEY"] = nebius_api_key

  with open("openai_api_key", "r") as file:
      openai_api_key = file.read().strip()

  os.environ["OPENAI_API_KEY"] = openai_api_key
if IS_COLAB:
    nebius_api_key = userdata.get("nebius_api_key")
    os.environ["NEBIUS_API_KEY"] = nebius_api_key
    print("Nebius API key loaded from Colab secrets.")

    openai_api_key = userdata.get("openai_api_key")
    os.environ["OPENAI_API_KEY"] = openai_api_key
    print("OpenAI API key loaded from Colab secrets.")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions