In CodeArts Agent CLI, you can perform authorization by configuring process-level variables or system environment variables. The process-level configuration is used for temporary authorization, and the system environment variable configuration is used for permanent authorization.
Preparations
- Create access keys by referring to Access Keys.
- In the Create Access Key dialog box, select the agreement check box and click Next. Enter a description for the access key and click OK.
After the access key is created, download it and keep it secure. Once the dialog box is closed, the key cannot be obtained.
- Configure environment variables based on your operating system (see the following). Obtain the values of Access Key Id and Secret Access Key from the downloaded credentials.csv file.
Windows
The following describes how to perform authorization by configuring process-level variables and system environment variables in Windows.
Configuring Process-Level Variables
You can configure process-level variables to grant temporary authorization for the current window.
- If you are using CMD, run the following commands to configure variables:
set CODEARTS_CLI_AK=Access Key Id
set CODEARTS_CLI_SK=Secret Access Key
After the commands are executed, run the following commands in the current window to check whether the configuration has taken effect:
echo %CODEARTS_CLI_AK%
echo %CODEARTS_CLI_SK%
If the content you just set is displayed, the configuration has taken effect. If "%CODEARTS_CLI_AK%" or "%CODEARTS_CLI_SK%" is displayed, the configuration has not taken effect.
- If you are using PowerShell, run the following commands to configure variables:
$env:CODEARTS_CLI_AK="Access Key Id"
$env:CODEARTS_CLI_SK="Secret Access Key"
After the commands are executed, run the following commands to check whether the configuration has taken effect. If no error message is displayed, the configuration has taken effect.
echo $env:CODEARTS_CLI_AK
echo $env:CODEARTS_CLI_SK
Configuring System Environment Variables
You can configure system environment variables to make the configuration permanently effective.
- Open the System Properties dialog box and click Environment Variables on the Advanced tab.
- Create CODEARTS_CLI_AK and CODEARTS_CLI_SK under user variables or system variables.
Set CODEARTS_CLI_AK to the value of Access Key Id and CODEARTS_CLI_SK to the value of Secret Access Key.
- After the configuration is complete, right-click the project you want to launch and choose Open Windows Terminal here, enter codearts, and press Enter.
Enter the TUI development environment. The configuration is permanently effective.
macOS
The following describes how to perform authorization by configuring process-level variables and system environment variables in macOS.
Configuring Process-Level Variables
- Open the terminal and run the following commands to grant temporary authorization for the current window:
export CODEARTS_CLI_AK="Access Key Id"
export CODEARTS_CLI_SK="Secret Access Key"
- After the commands are executed, run the following commands in the current window to check whether the configuration has taken effect:
echo $CODEARTS_CLI_AK
echo $CODEARTS_CLI_SK
If the key information is displayed, the configuration has taken effect. If no output or an empty line is displayed, the configuration has not taken effect.
Configuring System Environment Variables
- Run the following commands to add environment variables to the ~/.zshrc file:
echo 'export CODEARTS_CLI_AK="Access Key Id"' >> ~/.zshrc
echo 'export CODEARTS_CLI_SK="Secret Access Key"' >> ~/.zshrc
- Run the following command to permanently save the two variables:
source ~/.zshrc
- Run the following commands to check whether the configuration has taken effect:
echo $CODEARTS_CLI_AK
echo $CODEARTS_CLI_SK
If the key information is displayed, the configuration has taken effect. If no output or an empty line is displayed, the configuration has not taken effect.
Linux
You can select an authorization method as required.
Table 1 Comparison of different authorization methods | Authorization Method | Effective Scope | Lifecycle | Applicable Shell | Permission Requirements | Typical Scenarios |
| Temporary process authorization | Current terminal window only | Expires immediately after the terminal is closed; cleared upon a server restart | bash, zsh, and sh | Common users | Temporary debugging, one-off tests, and temporary script execution, without the need to retain keys |
| Permanent Bash user authorization | Currently logged-in users and all new terminals | Persists permanently; remains effective after a terminal or server restart | Linux default Bash (CentOS, Ubuntu, or Kylin) | Common users | Personal servers, frequent daily use, operations only performed by the user |
Temporary Process Authorization
The configuration takes effect only in the current terminal window. After the window is closed, the configuration automatically becomes invalid. This method is suitable for one-time debugging and temporary command execution. Keys are not stored permanently.
- Configure temporary environment variables (AK/SK).
Run the following commands in the terminal to inject temporary access credentials to the current session window:
export CODEARTS_CLI_AK="Access Key Id"
export CODEARTS_CLI_SK="Secret Access Key"
Replace Access Key Id and Secret Access Key with the actual values. For details about how to obtain the values, see Preparations.
- Check whether the authorization is successful.
For example, run the codearts models command in the terminal to check whether the authorization is successful.
- If information similar to the following is displayed, the authorization is successful.
root@szvphis32149187:~# codearts models
model_id model_name
-------------------------------------------------------------
huaweicloud-maas/GLM-5.1 GLM-5.1
huaweicloud-maas/GLM-5.2 GLM-5.2
- If an authentication failure or error message is displayed, run the following commands to check whether the AK/SK is correct:
echo $CODEARTS_CLI_AK
echo $CODEARTS_CLI_SK
Permanent Bash User Authorization
If the current login user needs to be used for a long time, you are advised to use this method for permanent authorization. Then, the configuration will be retained even if the terminal or the server is restarted. Administrator permissions are not required.
- Add the environment variables to the Bash configuration file.
Run the following commands to add the environment variables CODEARTS_CLI_AK and CODEARTS_CLI_SK to the
.bashrc file of the current user:
echo 'export CODEARTS_CLI_AK="Access Key Id"' >> ~/.bashrc
echo 'export CODEARTS_CLI_SK="Secret Access Key"' >> ~/.bashrc
Replace Access Key Id and Secret Access Key with the actual values. For details about how to obtain the values, see Preparations.
- Reload the Bash configuration for the added environment variables to take effect immediately.
source ~/.bashrc
- Check whether the authorization is permanently effective.
Close the current terminal window, open a new terminal session, and run the codearts models command to check whether the authorization is effective.