# CLI login

Use `instantml login` on any machine with a browser so scripts can run without
pasting API keys.

## Log in, check, and log out

Authenticate:

```bash
instantml login
```

Print the current credential context:

```bash
instantml whoami
```

Remove stored credentials:

```bash
instantml logout
```

`instantml login` runs an OAuth 2.0 device-code flow: it prints a code, opens
the browser confirmation page, and stores the resulting credential in
`~/.instantml/credentials`.

The stored credential carries the `sdk:ingest`, `artifacts:write`,
`imports:write`, and `export:read` scopes. That covers run creation, metric
logging, file and checkpoint uploads, imports, and reads or exports. Create a
key from the dashboard only when a job needs additional scopes such as
`artifacts:manage` or `runs:control` — see
[API-key scopes](/docs/sdk/installation-auth.md).

## Understand credential resolution

`im.init(...)` resolves credentials in this order:

1. Explicit `api_key=...`.
2. `INSTANTML_API_KEY`.
3. CLI-stored credentials from `instantml login`.
4. No credentials — top-level `im.init(...)` raises `InstantMLError` before it
   creates a run.

```python
import instantml as im

# Explicit key
run = im.init(project="cartpole", api_key="instantml_...")

# Environment key (INSTANTML_API_KEY is set)
run = im.init(project="cartpole")

# After `instantml login`
run = im.init(project="cartpole")
```

> **Note:** `instantml login --api-host ...` only changes the host the login flow contacts. It does not change the SDK host for future scripts; set `INSTANTML_API_BASE_URL` or pass `base_url=...` if your team uses a non-default endpoint.

## Confirm in the browser

The device-code confirmation page formats codes as `XXXX-XXXX`, requires a
browser session, and tells you when the terminal can continue.

## Next steps

- [Install and authenticate the SDK](/docs/sdk/installation-auth.md) — API keys and scopes
- [Quickstart](/docs/quickstart.md) — log your first run
- [SDK logging](/docs/sdk/logging.md) — create runs and log metrics
- [Manage API keys in the dashboard](/docs/dashboard/settings-api-keys.md)

## Agent navigation

- [Docs index](/llms.txt)
- [Full docs bundle](/llms-full.txt)

### Get Started

- [Overview](/docs/index.md)
- [Quickstart](/docs/quickstart.md)
- [Core Concepts](/docs/concepts/core-concepts.md)
- [Pricing](/docs/pricing.md)
- [Benchmarks](/docs/benchmarks.md)
- [Examples](/docs/guides/examples.md)
- [Troubleshooting](/docs/troubleshooting.md)

### SDK

- [Installation Auth](/docs/sdk/installation-auth.md)
- [Logging](/docs/sdk/logging.md)
- [Tracing](/docs/sdk/tracing.md)
- [Metrics Steps](/docs/sdk/metrics-steps.md)
- [Config Tags Notes](/docs/sdk/config-tags-notes.md)
- [Artifacts Checkpoints](/docs/sdk/artifacts-checkpoints.md)
- [Rich Objects](/docs/sdk/rich-objects.md)
- [Distributed Training](/docs/sdk/distributed-training.md)
- [Console System Integrations](/docs/sdk/console-system-integrations.md)
- [Reliability](/docs/sdk/reliability.md)
- [Cli Login](/docs/sdk/cli-login.md) (current page)
- [Querying Data](/docs/sdk/querying-data.md)
- [Agent Mcp](/docs/sdk/agent-mcp.md)
- [Examples Patterns](/docs/sdk/examples-patterns.md)

### Integrations

- [Overview](/docs/integrations/overview.md)
- [Pytorch Lightning](/docs/integrations/pytorch-lightning.md)
- [Huggingface Transformers](/docs/integrations/huggingface-transformers.md)
- [Keras](/docs/integrations/keras.md)
- [Wandb](/docs/integrations/wandb.md)

### Dashboard

- [Tour](/docs/dashboard/tour.md)
- [Organizations Workspaces](/docs/dashboard/organizations-workspaces.md)
- [Runs Workspace](/docs/dashboard/runs-workspace.md)
- [Metrics Charts](/docs/dashboard/metrics-charts.md)
- [Run Detail](/docs/dashboard/run-detail.md)
- [Traces](/docs/dashboard/traces.md)
- [Compare Runs](/docs/dashboard/compare-runs.md)
- [Research Dashboards](/docs/dashboard/research-dashboards.md)
- [Artifacts Files](/docs/dashboard/artifacts-files.md)
- [Run Health](/docs/dashboard/alerts.md)
- [Datasets](/docs/dashboard/datasets.md)
- [Checkpoints](/docs/dashboard/checkpoints.md)
- [Reports](/docs/dashboard/reports.md)
- [Settings Api Keys](/docs/dashboard/settings-api-keys.md)
- [Api Tab](/docs/dashboard/api-tab.md)
- [Onboarding Team Billing](/docs/dashboard/onboarding-team-billing.md)

### Data

- [Imports](/docs/guides/imports.md)
- [W&B alternative](/docs/guides/wandb-alternative.md)
- [InstantML vs MLflow](/docs/guides/instantml-vs-mlflow.md)
- [W&B import guide](/docs/guides/wandb-import-guide.md)
- [W&B and Neptune imports](/docs/guides/wandb-neptune-imports.md)
- [Export Usage Limits](/docs/guides/export-usage-limits.md)
- [Pricing Limits Billing](/docs/guides/pricing-limits-billing.md)
- [Auth Billing Storage](/docs/guides/auth-billing-storage.md)
- [Customer Owned Clickhouse](/docs/guides/customer-owned-clickhouse.md)
- [Observability](/docs/guides/observability.md)

### API

**Practical API guides**

- [Authentication](/docs/api/authentication.md)
- [Errors And Limits](/docs/api/errors-and-limits.md)
- [Health Observability](/docs/api/health-observability.md)
- [Projects Runs](/docs/api/projects-runs.md)
- [Metrics Series](/docs/api/metrics-series.md)
- [Attributes Objects](/docs/api/attributes-objects.md)
- [Artifacts](/docs/api/artifacts.md)
- [Reports](/docs/api/reports.md)
- [Iframe Embeds](/docs/api/iframe-embeds.md)
- [Import Export Usage](/docs/api/import-export-usage.md)
- [Dashboard Control State](/docs/api/dashboard-control-state.md)
**Architecture**

- [System Overview](/docs/architecture/system-overview.md)
- [Service Planes](/docs/architecture/service-planes.md)
- [Storage Model](/docs/architecture/storage-model.md)
- [Google Clickhouse](/docs/architecture/google-clickhouse.md)
- [Auth Tenancy](/docs/architecture/auth-tenancy.md)
- [Schema Reference](/docs/architecture/schema-reference.md)

### API Reference

- [API Reference](/docs/api-reference.md)
