Skip to main content
Configure the RunAnywhere SDK for different environments and use cases.

SDK Initialization

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

EnvironmentDescriptionAPI KeyLoggingTelemetry
.developmentLocal developmentOptionalVerboseDisabled
.stagingTesting with servicesRequiredInfoEnabled
.productionProduction deploymentRequiredMinimalEnabled

Development Mode (Default)

// No API key needed - perfect for local development
await RunAnywhere.initialize();

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

Production Mode

await RunAnywhere.initialize(
  apiKey: 'your-production-api-key',
  baseURL: 'https://api.runanywhere.ai',
  environment: SDKEnvironment.production,
);

Check SDK State

// 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:
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

ParameterTypeDefaultRangeDescription
maxTokensint1001–4096Maximum output length
temperaturedouble0.80.0–2.0Higher = more creative
topPdouble1.00.0–1.0Nucleus sampling
stopSequencesList<String>[]-Stop generation triggers
systemPromptString?null-System context

Voice Session Configuration

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)

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

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

Onnx.addModel(
  id: 'my-tts-voice',
  name: 'My TTS Voice',
  url: 'https://example.com/tts-voice.tar.bz2',
  modality: ModelCategory.textToSpeech,
  memoryRequirement: 50000000,  // 50MB
);

Storage Management

// 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

// Reset SDK state (for testing or reinitialization)
RunAnywhere.reset();

Environment Variables

For production apps, store sensitive configuration securely:
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