Connect with CLI Contexts
A CLI context is a named set of connection settings: the deployment URL, your credentials, a default workspace, and output preferences. The NeMo CLI and the Python SDK both read the current context, so you configure a deployment once and every nemo command and SDK client targets it.
Tutorials and guides in this documentation assume that your current context points at the deployment you want to use.
Prerequisites
- Install the NeMo CLI as described in Setup.
- Obtain the base URL for each deployment.
- For an authenticated deployment, obtain an account that can complete its login flow.
How contexts work
Contexts are saved in the CLI configuration file, ~/.config/nhx/config.yaml by default. A single file can hold contexts for any number of local and remote deployments. Each context references a cluster entry (the base URL) and a user entry (the credentials), and stores its own default workspace:
You don’t need to edit this file by hand. nemo setup, nemo config set, and nemo auth login write it for you. Context names such as local, staging, and production are labels you choose.
current_context is the default. Commands and SDK clients use it unless you select another context explicitly. For file location options, see the configuration reference.
Connect to a remote deployment
Save the deployment URL in the current CLI context:
Verify the saved URL:
If the deployment requires authentication, log in after configuring the URL:
The login stores credentials in the context, and the CLI and Python SDK refresh them as needed.
You can also run nemo setup. During interactive onboarding, setup offers to connect to a remote deployment when the configured platform is unreachable. It verifies and saves the URL, then runs the same authentication flow.
Connect to a local deployment
A local platform can coexist with remote contexts:
For a local HTTPS deployment with a private certificate authority, save the CA bundle with the cluster:
The saved cluster entry uses the certificate_authority key.
Manage multiple contexts
Create a context for each deployment. Use --activate to make one of them current:
If the saved configuration has no current context, the next written context becomes current automatically. Otherwise, creating another context does not switch the current context.
For authenticated deployments, log in to each context separately:
Switch the current context
Switch the default context for all later commands and SDK clients:
Verify the switch:
Inspect all saved connections:
Use a context for one command
To target a context for one command without switching, use the global --context option:
To target a context for every command in the current shell, set NHX_CURRENT_CONTEXT:
Set the default workspace
Each context stores a default workspace, which starts as default. Commands and SDK clients use it for workspace-scoped resources unless you pass a workspace explicitly. Change it for the current context:
Unless an example says otherwise, examples in this documentation use the default workspace. Some tutorials create a dedicated workspace and set it as the default this way. To return to the original workspace afterward, run nemo config set --workspace default.
Use contexts from the Python SDK
NemoClient.from_config() builds a client from the current context, including its base URL, default workspace, and credentials from nemo auth login:
To use a specific context without switching the current one, pass its name:
AsyncNemoClient.from_config() accepts the same arguments. Because the client reads the same configuration as the CLI, switching contexts with nemo config use-context changes the target of both. For all connection options, see Client APIs.
When to use NHX_BASE_URL
The NHX_BASE_URL environment variable overrides the base URL of every context. Most workflows don’t need it. Use the following guidelines:
-
The NeMo CLI and
NemoClient.from_config(): leaveNHX_BASE_URLunset. Setting it, even to a local default, overrides the deployment saved in your context. -
Tools that need a URL directly, such as
curlor an OpenTelemetry exporter: these can’t read the CLI configuration. Examples in this documentation use${NHX_BASE_URL:-http://localhost:8080}, which falls back to a local deployment only when the variable is unset. If your context points at a remote deployment, export its URL first. For an authenticated deployment, pass a token from the current context withnemo auth token: -
Environments without a configuration file, such as CI jobs, containers, and hosted notebooks like Google Colab: set
NHX_BASE_URL, andNHX_ACCESS_TOKENfor an authenticated deployment. The CLI andNemoClient.from_config()both read these variables.
NHX_BASE_URL and NHX_CURRENT_CONTEXT override saved configuration for all contexts. If switching contexts does not change the target deployment, unset those variables or update them for the current shell.
Delete a context
Delete a context when you no longer need it:
This follows the same convention as kubectl config delete-context: the
context is removed, but cluster and user records remain. To also remove
unreferenced cluster and user records, pass --prune-orphans.
Next Steps
- Review the configuration reference for fields, environment variables, and precedence.
- Run
nemo workspaces listto verify platform access. - Use CLI troubleshooting if the connection fails.