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

# Authentication

> Learn how to authenticate with nodepick.ai using the Python CLI and Python API / SDK.

nodepick.ai uses API key authentication for all programmatic access and CLI operations. Every request you make through the Python CLI (`np`), Python SDK, or HTTP API requires a valid API key.

## Generating an API Key

You generate API keys from the nodepick.ai dashboard. Follow these steps:

1. Register at [nodepick.ai](https://www.nodepick.ai) and log in.
2. Set up your credit card in the dashboard.
3. In the left-hand navigation, open **Developer**, then go to **API Keys**.
4. Click **Generate** and give the key a descriptive name (for example, `dev` or `ci-pipeline`).
5. Copy and save the key immediately — it will not be shown again after you leave the page.

You can create multiple keys for different environments or applications and revoke any of them independently from the same settings page.

***

## Python CLI Authentication (`np auth`)

The `np` command-line tool provides built-in authentication commands to store, test, and clear your credentials securely in your operating system's keyring.

### Configure Credentials (`np auth configure`)

Run `np auth configure` to save your API key securely into your OS keyring. When prompted, paste your API key:

```bash theme={null}
np auth configure
```

The CLI securely stores your API key using the OS keyring (`nodepick-cli` service).

#### Custom API Base URL

If you need to target a custom API endpoint, pass the `--base-url` (`-u`) option:

```bash theme={null}
np auth configure --base-url https://api.nodepick.ai
```

### Test API Access (`np auth test`)

Verify your stored credentials and display your user and organization information:

```bash theme={null}
np auth test
```

#### Example Output

```text theme={null}
API access OK
API URL: https://api.nodepick.ai
User: user_01KZHCPH4S4WMED0R9CGKHVMBC
Organization: org_01KZHF48NPJZVR0CARK9829VED
```

### Clear Credentials (`np auth clear`)

Remove the stored API key from your OS keyring:

```bash theme={null}
np auth clear
```

### Non-Interactive Authentication (Environment Variable)

For CI/CD workflows, automated scripts, or headless environments, set the `NODEPICK_API_KEY` environment variable:

```bash theme={null}
export NODEPICK_API_KEY="YOUR_API_KEY"
```

The CLI will automatically detect and use `NODEPICK_API_KEY` if present, overriding any key stored in the OS keyring.

***

## Python API / SDK Authentication

When using the `nodepick` Python SDK, pass your API key directly when initializing the client.

### Initialize with Explicit API Key

```python theme={null}
from nodepick import nodepick

client = nodepick(api_key="YOUR_API_KEY")
```

Every SDK method called on `client` automatically includes your key in the request headers.

### Initialize with Environment Variable (Recommended)

To avoid hardcoding secrets in your source code, load your API key from an environment variable:

```python theme={null}
import os
from nodepick import nodepick

client = nodepick(api_key=os.environ["NODEPICK_API_KEY"])
```

### Using Context Manager

You can also use the client as a context manager (`with` block) to ensure connections close automatically:

```python theme={null}
import os
from nodepick import nodepick

with nodepick(api_key=os.environ["NODEPICK_API_KEY"]) as client:
    nodes = client.node_list()
    print(nodes)
```

***

## HTTP API Bearer Token

If you are calling the REST API directly from tools like `curl`, Postman, or other languages, include your API key as a `Bearer` token in the `Authorization` header:

```bash theme={null}
curl -X GET https://api.nodepick.ai/nodes \
  -H "Authorization: Bearer YOUR_API_KEY"
```

***

## Keeping Your API Key Secure

<Warning>
  Never commit your API key to source code or check it into version control. If a key is exposed in a public repository, revoke it immediately from Developer Settings and generate a new one.
</Warning>

* **Use `.env` files**: For local development, store secrets in a `.env` file and load them with [`python-dotenv`](https://pypi.org/project/python-dotenv/).
* **Add to `.gitignore`**: Ensure `.env` is listed in your `.gitignore` file.
* **Rotate Compromised Keys**: If a key is compromised, generate a replacement in **Developer Settings** > **API Keys**, update your applications, and delete the old key.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Create a Node" icon="circle-plus" href="/nodes/create">
    Provision a new compute node using the Python CLI, SDK, or HTTP API.
  </Card>

  <Card title="Manage Nodes" icon="sliders" href="/nodes/manage">
    List, inspect, control power, and delete compute nodes.
  </Card>
</CardGroup>
