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

# Setup & Configuration

> Configure SuggestKit in your iOS app

## Basic Configuration

Add this to your App file (typically `App.swift`):

```swift theme={null}
import SuggestKit
import SwiftUI

@main
struct MyApp: App {
    init() {
        // Configure SuggestKit with your public API key
        SuggestKit.configure(
            apiKey: "your_public_api_key_here",
            environment: .production // or .sandbox for testing
        )
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
```

## API Key Setup

1. **Get your API key** from the [SuggestKit Dashboard](https://dashboard.suggestkit.app)
2. **Use your public key** (starts with `public_`) - never use the secret key in mobile apps
3. **Store securely** in your app's configuration

<Warning>
  Never expose your secret API key in client-side code. Only use the public key for mobile SDKs.
</Warning>

## Environment Configuration

### Production Environment

```swift theme={null}
SuggestKit.configure(
    apiKey: "public_your_production_key",
    environment: .production
)
```

### Sandbox Environment

Use sandbox for testing and development:

```swift theme={null}
SuggestKit.configure(
    apiKey: "public_your_sandbox_key", 
    environment: .sandbox,
    debugMode: true // Enable detailed logging
)
```

## Advanced Configuration

```swift theme={null}
SuggestKit.configure(
    apiKey: "your_public_api_key",
    environment: .production,
    options: SuggestKitOptions(
        // Network settings
        requestTimeout: 30.0,
        maxRetries: 3,
        
        // Caching
        enableOfflineCache: true,
        maxCacheSize: 50, // suggestions
        
        // UI defaults
        defaultTheme: .system,
        enableHaptics: true,
        
        // Analytics
        enableAnalytics: true,
        
        // Debug
        debugMode: false
    )
)
```

## User Management

### Set Current User

Call this after user authentication:

```swift theme={null}
import SuggestKit

// Basic user setup
SuggestKit.setUser(
    id: "user_12345",
    email: "user@example.com"
)

// Advanced user setup
SuggestKit.setUser(
    id: "user_12345",
    email: "user@example.com",
    customId: "my_internal_user_id",
    monthlyRevenue: 19.99,
    country: "US",
    platform: .ios,
    locale: "en_US",
    metadata: [
        "plan": "pro",
        "signup_date": "2024-01-15"
    ]
)
```

### Clear User Session

```swift theme={null}
// On logout
SuggestKit.clearUser()
```

## Configuration Validation

Verify your setup with debug mode:

```swift theme={null}
#if DEBUG
SuggestKit.configure(
    apiKey: "your_api_key",
    environment: .sandbox,
    debugMode: true
)

// This will log configuration status
SuggestKit.validateConfiguration()
#endif
```

## Error Handling

Handle configuration errors gracefully:

```swift theme={null}
do {
    try SuggestKit.configure(
        apiKey: "your_api_key",
        environment: .production
    )
} catch SuggestKitError.invalidAPIKey {
    print("Invalid API key provided")
} catch SuggestKitError.networkError(let details) {
    print("Network configuration error: \(details)")
} catch {
    print("Configuration error: \(error)")
}
```

## Next Steps

<CardGroup cols={2}>
  <Card title="📱 Basic Usage" href="/sdks/ios/usage">
    Start showing feedback UI
  </Card>

  <Card title="🎨 Customization" href="/sdks/ios/customization">
    Style the components
  </Card>
</CardGroup>
