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

# Configuration

> SDK configuration options and environments

Configure the RunAnywhere SDK for different environments and use cases.

## SDK Initialization

```dart theme={null}
await RunAnywhere.initialize(
  apiKey: 'your-api-key',                    // Optional for development
  baseURL: 'https://api.runanywhere.ai',     // Optional for development
  environment: SDKEnvironment.production,    // development | staging | production
);
```

## Environment Modes

| Environment    | Description           | API Key  | Logging | Telemetry |
| -------------- | --------------------- | -------- | ------- | --------- |
| `.development` | Local development     | Optional | Verbose | Disabled  |
| `.staging`     | Testing with services | Required | Info    | Enabled   |
| `.production`  | Production deployment | Required | Minimal | Enabled   |

### Development Mode (Default)

```dart theme={null}
// No API key needed - perfect for local development
await RunAnywhere.initialize();

// Or explicitly set development mode
await RunAnywhere.initialize(
  environment: SDKEnvironment.development,
);
```

### Production Mode

```dart theme={null}
await RunAnywhere.initialize(
  apiKey: 'your-production-api-key',
  baseURL: 'https://api.runanywhere.ai',
  environment: SDKEnvironment.production,
);
```

## Check SDK State

```dart theme={null}
// Version
print('SDK Version: ${RunAnywhere.version}');

// Initialization state
print('Initialized: ${RunAnywhere.isSDKInitialized}');
print('Active: ${RunAnywhere.isActive}');
print('Environment: ${RunAnywhere.environment}');

// Model states
print('LLM loaded: ${RunAnywhere.isModelLoaded}');
print('Current model: ${RunAnywhere.currentModelId}');
print('STT loaded: ${RunAnywhere.isSTTModelLoaded}');
print('TTS loaded: ${RunAnywhere.isTTSVoiceLoaded}');
print('Voice Agent ready: ${RunAnywhere.isVoiceAgentReady}');
```

## Generation Options

Configure text generation behavior:

```dart theme={null}
final options = LLMGenerationOptions(
  maxTokens: 256,              // Maximum tokens to generate
  temperature: 0.7,            // Randomness (0.0–2.0)
  topP: 0.95,                  // Nucleus sampling
  stopSequences: ['END'],      // Stop at these sequences
  systemPrompt: 'You are a helpful assistant.',
);

final result = await RunAnywhere.generate(prompt, options: options);
```

### Generation Parameters

| Parameter       | Type           | Default | Range   | Description              |
| --------------- | -------------- | ------- | ------- | ------------------------ |
| `maxTokens`     | `int`          | 100     | 1–4096  | Maximum output length    |
| `temperature`   | `double`       | 0.8     | 0.0–2.0 | Higher = more creative   |
| `topP`          | `double`       | 1.0     | 0.0–1.0 | Nucleus sampling         |
| `stopSequences` | `List<String>` | `[]`    | -       | Stop generation triggers |
| `systemPrompt`  | `String?`      | `null`  | -       | System context           |

## Voice Session Configuration

```dart theme={null}
final config = VoiceSessionConfig(
  silenceDuration: 1.5,     // Seconds of silence before processing
  speechThreshold: 0.03,    // Audio level for speech detection
  autoPlayTTS: true,        // Auto-play synthesized audio
  continuousMode: true,     // Resume listening after TTS
);

final session = await RunAnywhere.startVoiceSession(config: config);
```

## Model Registration

### LLM Models (GGUF)

```dart theme={null}
LlamaCpp.addModel(
  id: 'my-llm-model',
  name: 'My LLM Model',
  url: 'https://huggingface.co/.../model.gguf',
  memoryRequirement: 500000000,  // 500MB
  supportsThinking: false,        // Chain-of-thought support
);
```

### STT Models

```dart theme={null}
Onnx.addModel(
  id: 'my-stt-model',
  name: 'My STT Model',
  url: 'https://example.com/stt-model.tar.gz',
  modality: ModelCategory.speechRecognition,
  memoryRequirement: 75000000,  // 75MB
);
```

### TTS Voices

```dart theme={null}
Onnx.addModel(
  id: 'my-tts-voice',
  name: 'My TTS Voice',
  url: 'https://example.com/tts-voice.tar.gz',
  modality: ModelCategory.speechSynthesis,
  memoryRequirement: 50000000,  // 50MB
);
```

## Storage Management

```dart theme={null}
// Get storage information
final storageInfo = await RunAnywhere.getStorageInfo();
print('Free space: ${storageInfo.deviceStorage.freeSpace} bytes');

// Get downloaded models with sizes
final models = await RunAnywhere.getDownloadedModelsWithInfo();
for (final model in models) {
  print('${model.id}: ${model.size} bytes');
}

// Delete a model
await RunAnywhere.deleteStoredModel('old-model-id');

// Refresh model discovery
await RunAnywhere.refreshDiscoveredModels();
```

## Reset SDK

```dart theme={null}
// Reset SDK state (for testing or reinitialization)
RunAnywhere.reset();
```

## Environment Variables

For production apps, store sensitive configuration securely:

```dart theme={null}
import 'package:flutter_dotenv/flutter_dotenv.dart';

await dotenv.load();

await RunAnywhere.initialize(
  apiKey: dotenv.env['RUNANYWHERE_API_KEY'],
  baseURL: dotenv.env['RUNANYWHERE_BASE_URL'],
  environment: SDKEnvironment.production,
);
```

## See Also

<CardGroup cols={2}>
  <Card title="Error Handling" icon="triangle-exclamation" href="/flutter/error-handling">
    Handle SDK errors
  </Card>

  <Card title="Best Practices" icon="star" href="/flutter/best-practices">
    Optimization tips
  </Card>
</CardGroup>
