Before invoking LAS operators, you must first generate an API Key for operator authentication. Because API Key information is sensitive, leaking your API Key may result in your model usage being consumed by others, causing losses. Therefore, after obtaining the API Key, it is recommended to store the API Key in an environment variable to facilitate safe and proper usage of the API Key.
After logging in to LAS Console , on the Resource management > API key managementpage, click the Create API key in the upper left corner. Create the API Key according to the interface instructions.
warning
When using the LAS development environment to invoke operators for data processing task development, it is recommended to configure the API Key in environment variables rather than hardcoding it in code. This prevents the API Key from being leaked with the code, which could result in your quota being used by others and incurring additional costs.
Environment variables are operating system-level key-value pairs used to store configuration information and can affect the behavior of running processes. They are divided into two categories:
Configuration overview examples for mainstream operating systems are as follows.
Operating system | Shell | Temporary setting (current session) | Permanent setting (recommended file) |
|---|---|---|---|
macOS / Linux | Bash / Zsh |
|
|
PowerShell |
|
| |
Windows | Command Prompt |
|
|
PowerShell |
|
|
Detailed configuration guidance can be found below.
In Unix-like systems, environment variable configuration is closely related to the Shell you use.
~/.bash_profile: Loaded when Bash login Shell starts. Typically used to define variables intended to be available throughout the entire user session.~/.bashrc: Loaded when Bash interactive non-login Shell starts. Suitable for defining aliases and functions.~/.zshenv: (Recommended for environment variables) Loaded every time Zsh starts, regardless of whether it is a login or interactive Shell. This is the most reliable place to set environment variables.~/.zprofile: Loaded when Zsh login Shell starts, after .zshenv.~/.zshrc: Loaded when Zsh interactive Shell starts. Suitable for configuring Shell interaction-related settings (such as prompts and aliases).tip
To ensure that environment variables are available in all scenarios (including GUI applications), it is recommended to place the export statement in the ~/.zshenv (Zsh) or ~/.bash_profile (Bash) file.
Run the export command in the terminal.
# Example: Temporarily set LAS_API_KEY export LAS_API_KEY="your-las-api-key-here"
Open the terminal and use the following command to check the default shell type.
echo $SHELL # Returns /bin/zsh: The default shell type is Zsh (Z shell). # Returns /bin/bash: The default shell type is Bash.
Open your shell configuration file. For Zsh users, ~/.zshenv is recommended.
# Zsh users nano ~/.zshenv # Bash users nano ~/.bash_profile
Add an export statement at the end of the file.
# Set the LAS_API_KEY environment variable export LAS_API_KEY="your-las-api-key-here"
Save the file, then run the source command or restart the terminal to apply the configuration.
# Zsh users source ~/.zshrc # Bash users source ~/.bash_profile
The behavior of PowerShell is generally consistent across all platforms.
$env:LAS_API_KEY = "your-las-api-key-here"
Edit the PowerShell profile file.
# This will automatically open the configuration file with the default editor code $profile
Add the following line to the file:
$env:LAS_API_KEY = "your-las-api-key-here"
Save the file, then run the . command or restart PowerShell.
. $profile
Windows divides environment variables into "User variables" and "System variables". The former is only effective for the current user, while the latter applies to all users.
Use the set command.
set LAS_API_KEY=your-las-api-key-here
Use the setx command.
:: Set user variables setx LAS_API_KEY "your-las-api-key-here" :: Set system variables (requires administrator privileges) setx LAS_API_KEY "your-las-api-key-here" /m
Caution: Variables set by setx only take effect in new Command Prompt windows and do not affect the current window.
$env:LAS_API_KEY = "your-las-api-key-here"
Using the .NET API is the most reliable method.
# Set user variable [Environment]::SetEnvironmentVariable("LAS_API_KEY", "your-las-api-key-here", "User") # Set system variable (requires administrator privileges) [Environment]::SetEnvironmentVariable("LAS_API_KEY", "your-las-api-key-here", "Machine")
LAS_API_KEY and your key as the variable value.After completing the configuration, you can verify it in the following ways:
macOS / Linux:
echo $LAS_API_KEY
Windows (CMD):
echo %LAS_API_KEY%
PowerShell (all platforms):
echo $env:LAS_API_KEY # Or Get-ChildItem env:LAS_API_KEY
For permanent configuration, be sure to restart your terminal or IDE and check again to ensure the configuration is loaded correctly.
Warning: Never commit configuration files containing sensitive information such as LAS_API_KEY to Git or other version control systems.
.gitignore: Ensure that local configuration files containing sensitive information (such as .envrc, .env) are added to the .gitignore file..env file to manage environment variables, and to load them at application startup using libraries such as dotenv (Node.js) and python-dotenv (Python).direnv direnv is a powerful tool that can automatically load or unload environment variables when entering or leaving a project directory.
Installation (using macOS Homebrew as an example):
brew install direnv
Configuration: Create a .envrc file in the root directory of the project.
# .envrc export LAS_API_KEY="your-project-specific-key"
Authorization: When entering the directory for the first time, run direnv allow. From then on, each time you enter the directory, the variables in .envrc will automatically take effect.