MyRelay

← Back to the notebook

Set AI Tool Environment Variables on Any OS

Start by identifying the settings your tool actually reads

Environment variables let an application read settings without storing them directly in your project. For AI coding tools, those settings often include an API key, a server address and sometimes a model choice. Setting them correctly helps prevent authentication errors and requests going to the wrong billing account.

First, check your tool’s current documentation for its exact variable names. An OpenAI-compatible SDK commonly reads OPENAI_API_KEY, but endpoint settings differ between libraries. Claude Code supports Anthropic-specific settings, including ANTHROPIC_BASE_URL. Codex and Gemini CLI have their own authentication and provider rules. A variable that works in one application is not automatically meaningful to another.

Choose your account and endpoint before adding credentials

Decide whether you want direct provider billing or a relay account. MyRelay gives an individual developer one key and one pay-as-you-go budget across supported providers, with request-level token and cost visibility. If that fits your workflow, create a MyRelay account and generate a key.

MyRelay’s API base is https://api.myapirelay.com. Follow the current integration instructions for your specific tool, including any required version suffix. Do not assume that every client expects the identical endpoint format.

Keep authentication separate from compatibility. A valid relay key does not make every provider’s native SDK interchangeable. For Codex or Gemini CLI, follow MyRelay’s tool-specific setup rather than assuming that an OpenAI-style key variable redirects all traffic.

Test temporary settings before making them persistent

Begin with settings that apply only to your current terminal session. This limits accidental reuse and makes troubleshooting easier. Use your shell’s environment-variable assignment mechanism to supply the documented key and endpoint variables, then launch the coding tool from that same terminal.

Temporary settings normally disappear when the session ends. Persistent settings apply to future sessions, but they do not usually update applications that are already running. In either case, a program inherits its environment from the process that starts it. An editor opened earlier may therefore behave differently from a newly opened terminal.

Use Windows user variables for a lasting setup

On Windows, search the Start menu for the option to edit environment variables for your account. In the Environment Variables window, add each documented variable under User variables. Enter its name and value in separate fields, without wrapping the value in quotation marks.

Prefer user variables over system variables for a personal setup. After saving, close and reopen your terminal and coding application. If the tool runs inside an editor, restart the editor too. PowerShell, Command Prompt and Windows Subsystem for Linux are distinct environments; Windows settings should not be assumed to configure a Linux session automatically.

Match persistent settings to your macOS or Linux shell

On macOS and Linux, first identify the shell your terminal actually runs. Persistent variables are commonly defined in that shell’s startup configuration, but the relevant configuration depends on the shell and whether the session is interactive or a login session.

Add the documented variables using the shell’s supported export mechanism, then open a fresh terminal. Keep credentials out of project files and version control. A local environment file is only useful when your application explicitly loads it; its presence alone does not change the terminal environment.

Applications launched from the desktop may not read terminal startup settings. If a coding tool works in your terminal but fails inside a graphical editor, test by launching the editor from the configured terminal or use the editor’s documented environment settings.

Verify one inexpensive request before enabling automation

Check whether the required variables are present without printing their secret values. Then send one short request with a small output limit. Confirm the selected endpoint, successful authentication and actual charge. With MyRelay, compare the request’s tokens and cost in your account before starting a longer coding session.

If authentication fails, check variable names, whitespace and competing saved credentials. If billing appears in the wrong account, stop and inspect provider selection. Finally, set a modest budget or alert where available, and check whether it actually blocks spending. Rotate any key exposed in logs, screenshots or shared files.

More to read