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

# Authentication

> Learn how to authenticate with the GigaReels API

# Authentication

GigaReels uses API keys to authenticate requests. You can get your API key from the [dashboard](https://gigareels.com/dashboard/settings) or use our CLI for automatic authentication.

## CLI Authentication (Recommended)

The easiest way to authenticate is using the CLI login command:

```bash theme={null}
npx @gigareels/sdk login
```

This command will:

1. **Open your browser** to the GigaReels authentication page
2. **Authenticate** with your existing account or sign up
3. **Generate an API key** automatically
4. **Store credentials** locally in `~/.gigareels/credentials.json`

> [!TIP]
>
> CLI authentication is perfect for development and personal projects. The SDK will automatically
> use stored credentials.

### Local Development

For local development, you can authenticate against a local server:

```bash theme={null}
npx @gigareels/sdk login --local
```

This connects to `http://localhost:3000` instead of the production server.

### Check Authentication Status

You can check if you're already authenticated:

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

const isLoggedIn = await GigaReels.isLoggedIn();
if (isLoggedIn) {
	console.log("✅ Already authenticated");
} else {
	console.log("❌ Please run 'npx @gigareels/sdk login'");
}
```

## Manual API Key Authentication

For production applications, you should use manual API key authentication:

### 1. Get Your API Key

1. Go to your [GigaReels Dashboard](https://gigareels.com/dashboard)
2. Navigate to **Settings** → **API Keys**
3. Click **Generate New API Key**
4. Copy your API key and store it securely

> [!WARNING]
>
> **Keep your API key secure**: Never commit API keys to version control or expose them in
> client-side code.

### 2. Initialize the Client

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

const client = new GigaReels({
	apiKey: "your-api-key-here",
	baseUrl: "https://gigareels.com", // Optional, defaults to production
});
```

## Environment Variables

For production applications, use environment variables to store your API key:

```bash theme={null}
# .env
GIGAREELS_API_KEY=your-api-key-here
```

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

const client = new GigaReels({
	apiKey: process.env.GIGAREELS_API_KEY,
});
```

## Authentication Methods Comparison

> [tab] CLI Authentication
>
> **Pros:**
>
> * ✅ Automatic credential management
> * ✅ Perfect for development
> * ✅ Browser-based login
> * ✅ No manual API key handling
>
> **Cons:**
>
> * ❌ Not suitable for production servers
> * ❌ Requires interactive login
>
> **Best for:** Development, personal projects, local testing

> [tab] Manual API Key
>
> **Pros:**
>
> * ✅ Full control over credentials
> * ✅ Perfect for production
> * ✅ Environment variable support
> * ✅ Programmatic authentication
>
> **Cons:**
>
> * ❌ Manual key management
> * ❌ Risk of key exposure if not handled properly
>
> **Best for:** Production applications, CI/CD, server environments

## SDK Initialization Patterns

### Pattern 1: Auto-Detection

The SDK can automatically detect stored credentials:

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

// SDK automatically uses stored credentials from CLI login
const client = new GigaReels();
```

If no stored credentials are found, the SDK will throw an error with helpful instructions.

### Pattern 2: Explicit Configuration

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

const client = new GigaReels({
	apiKey: process.env.GIGAREELS_API_KEY,
	baseUrl: "https://gigareels.com", // Optional
});
```

### Pattern 3: Conditional Authentication

```javascript theme={null}
import { GigaReels } from "@gigareels/sdk";

async function createClient() {
	// Check if CLI credentials exist
	const isLoggedIn = await GigaReels.isLoggedIn();

	if (isLoggedIn) {
		// Use stored credentials
		return new GigaReels();
	} else if (process.env.GIGAREELS_API_KEY) {
		// Use environment variable
		return new GigaReels({
			apiKey: process.env.GIGAREELS_API_KEY,
		});
	} else {
		throw new Error("Please authenticate with 'npx @gigareels/sdk login' or set GIGAREELS_API_KEY");
	}
}

const client = await createClient();
```

## Authentication Errors

Common authentication errors and solutions:

> [accordion] No API key provided
>
> **Error:** `No API key provided and no stored credentials found`
>
> **Solution:**
>
> ```bash theme={null}
> npx @gigareels/sdk login
> ```
>
> Or provide an API key manually:
>
> ```javascript theme={null}
> const client = new GigaReels({ apiKey: "your-key" });
> ```

> [accordion] Invalid API key
>
> **Error:** `Invalid API key` or `401 Unauthorized`
>
> **Solutions:**
>
> 1. Check your API key is correct
> 2. Regenerate your API key in the dashboard
> 3. Ensure you're using the right base URL
>
> ```bash theme={null}
> npx @gigareels/sdk logout
> npx @gigareels/sdk login
> ```

> [accordion] Expired credentials
>
> **Error:** `Authentication expired`
>
> **Solution:** Re-authenticate with the CLI:
>
> ```bash theme={null}
> npx @gigareels/sdk logout
> npx @gigareels/sdk login
> ```

## Security Best Practices

> [card] 🔒 Secure Storage
>
> * Never commit API keys to version control - Use environment variables for production - Rotate
>   API keys regularly - Store keys in secure secret management systems

> [card] 🛡️ Access Control
>
> * Use separate API keys for different environments - Implement proper error handling - Monitor
>   API key usage - Revoke unused API keys

> [card] 🌐 Network Security
>
> * Always use HTTPS - Validate SSL certificates - Implement request timeout - Use proper CORS
>   settings

> [card] 📝 Logging
>
> * Log authentication events - Never log API keys - Monitor failed authentication attempts - Set
>   up alerts for suspicious activity

## Next Steps

**1. Authenticate**

Choose your preferred authentication method and get your API key set up

**2. Test Connection**

Make a simple API call to verify your authentication is working

**3. Start Building**

Explore the [Render Types](https://gigareels.mintlify.site/render-types/overview.md) to start generating content

> [card] Need Help?
>
> If you're having trouble with authentication, check our [troubleshooting
> guide](https://gigareels.mintlify.site/guides/troubleshooting) or contact [albert@gigareels.com](mailto:albert@gigareels.com).

&#x20;


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.