FAQ - Help and questions

How do I keep my AI API key safe when I use the Ruststudio assistant?

#ai#secrets#securitypublished 2 replies0 views
ReplyWatch
Share
Hacker NewsRedditLinkedInE-mail
Last post

Short answer

Prefer the env:NAME form in the API key field, so the key lives in an environment variable and not in the settings file. A pasted key is stored as plain text in ai.json in Ruststudio's settings folder. Never put a key in project files or Git, set a spending limit at the provider, and revoke any key that leaked.

Checked with Ruststudio source code (core/rs-core/src/ai.rs and settings.rs); no Rust code was run for this thread

Frequently asked question, written and answered by the Ruststudio team. Replies are open: corrections are welcome.

#1

Answer#

There are two ways to give Ruststudio a key, and they differ in where the secret ends up.

The answers below describe the two options with their trade-offs.

    QuoteReply
    Share
    Hacker NewsRedditLinkedInE-mail

    2 answers from the Ruststudio team: different approaches, each with its own trade-offs

    Sort: Oldest Newest
    #2

    Approach 1: an environment variable (env:NAME)#

    In AI > AI Providers..., type env: and the variable's name into the API key (or env:VARIABLE) field, for example env:OPENAI_API_KEY. Ruststudio stores only that text. When it sends a request it reads the variable's value from its own environment.

    Best when: you share the machine or back up your settings folder, or you already keep keys in environment variables. Cost: the variable must be set in the environment of the process that starts Ruststudio, so after setting it permanently you must start Ruststudio again. On Windows, set it for your user in the system environment variable settings.

      QuoteReply
      Share
      Hacker NewsRedditLinkedInE-mail
      #3

      Approach 2: paste the key#

      Paste the key into the field. It is saved as plain text in ai.json, in the Ruststudio folder under your settings location: %APPDATA% on Windows, ~/Library/Application Support on macOS, otherwise $XDG_CONFIG_HOME or ~/.config. The file is protected only by your operating system's file permissions.

      Best when: one personal machine and convenience matters. Cost: anyone who can read your user folder, or a backup or sync of it, can read the key. Do not copy this file into a project, a repository or a chat.

      Rules for either option#

      • Never put a key in source code, Cargo.toml, a .env file inside a repository that is not ignored, or a screenshot.
      • If the folder of a project is under Git, add private files to .gitignore: for example a line .env and a line *.key.
      • Create a separate key for the editor at the provider, give it a spending limit if the provider offers one, and revoke it there when in doubt.
      • If a key was ever committed or shared, treat it as public: revoke it and create a new one. Removing the file from Git does not remove it from history.
      • The key is sent only to the provider's base URL in the same provider entry. Check that URL when you add a custom endpoint.

      Where does Ruststudio keep other settings?#

      In settings.json in the same folder; ai.json holds the providers.

      Can the assistant see my key?#

      The key is used by Ruststudio to authenticate the request. It is not added to the text of your question.

        QuoteReply
        Share
        Hacker NewsRedditLinkedInE-mail