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

# Authentication

> Set up authentication for the Legnext Python SDK

## Get Your API Key

1. Visit [Legnext Dashboard](https://dashboard.legnext.ai)
2. Log in to your account
3. Navigate to **API Keys** section
4. Create a new API key
5. Copy and save it securely

## Using Your API Key

### Method 1: Direct Initialization

```python theme={null}
from legnext import Client

client = Client(api_key="your-api-key-here")
```

### Method 2: Environment Variable (Recommended)

Set the environment variable:

```bash theme={null}
# macOS/Linux
export LEGNEXT_API_KEY="your-api-key-here"

# Windows PowerShell
$env:LEGNEXT_API_KEY="your-api-key-here"
```

Then in your code:

```python theme={null}
import os
from legnext import Client

client = Client(api_key=os.getenv("LEGNEXT_API_KEY"))
```

### Method 3: .env File

Create a `.env` file:

```env theme={null}
LEGNEXT_API_KEY=your-api-key-here
```

Load it in your code:

```python theme={null}
from dotenv import load_dotenv
import os
from legnext import Client

load_dotenv()
client = Client(api_key=os.getenv("LEGNEXT_API_KEY"))
```

## Security Best Practices

⚠️ **Never hardcode API keys in your code**

✅ **Always use environment variables or .env files**

✅ **Add `.env` to `.gitignore` to prevent accidental commits**

✅ **Rotate keys regularly and revoke compromised ones**

***

## Next Steps

* [Quick Start](/sdk/python/quickstart)
* [Image Generation API](/sdk/python/image-generation)
