> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hiloop.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Configure CLI contexts

> Point the hiloop CLI at hosted, staging, or self-hosted API environments without repeating URLs.

`hiloop` commands start from one API URL. A **context** gives that URL a name, stores credentials
for that environment, and lets the CLI discover sibling services such as telemetry ingest.

## The built-in context

The built-in context is `prod`, which points at the hosted hiloop API (`api.hiloop.ai`). While the
hosted edge is being finalized it is not live yet, so commands that fall back to it fail with
`no API URL is configured` — set up a context for your deployment first.

```sh theme={null}
hiloop config current-context
```

## Add an environment

Create a context for any deployment with an API edge, select it, and sign in:

```sh theme={null}
hiloop config set-context acme --api-url https://api.acme.example
hiloop config use-context acme
hiloop login
```

Then run commands normally:

```sh theme={null}
hiloop whoami
hiloop run -- ./agent-eval.sh
```

For one command, use `--context` instead of switching the default:

```sh theme={null}
hiloop --context acme whoami
```

## Remove a context

Delete a context you no longer need:

```sh theme={null}
hiloop config remove-context acme
```

Removing the active context switches the CLI back to the built-in `prod` context. The built-in
`prod` context cannot be removed.

## How service discovery works

The CLI fetches the active API's public discovery document:

```http theme={null}
GET /v1/config
```

That document contains non-secret URLs such as the telemetry gateway and login entry point for that
deployment. The CLI caches those values briefly and refetches them when needed.

This keeps the login experience the same across hosted and self-hosted deployments: the CLI starts
from the API URL, then follows the login URLs advertised by that deployment.

## Override service URLs

Most deployments should not need service URL overrides. If your deployment cannot expose discovery
yet, store explicit URLs on the context:

```sh theme={null}
hiloop config set-context acme \
  --api-url https://api.acme.example \
  --telemetry-endpoint https://telemetry.acme.example:443
```

Precedence is:

1. Command flag or environment variable.
2. Context override.
3. API service discovery.
4. Built-in default, when the command has one.

## Automation

For CI and other automation, provide an API key with the command environment:

```sh theme={null}
export HILOOP_API_KEY="hil_..."
hiloop --context acme run -- ./agent-eval.sh
```

You can also store an API key for the selected context:

```sh theme={null}
printf '%s\n' "$HILOOP_API_KEY" | hiloop --context acme login --with-key
```

The CLI stores credentials using platform-appropriate storage and scopes them to the API URL, so a
credential for one context is not reused against another context.
