# ProtectMyAPI - Complete SDK Reference for AI Assistants > This file contains everything an AI assistant needs to help integrate ProtectMyAPI into mobile apps. > Last updated: January 2026 ## What is ProtectMyAPI? ProtectMyAPI protects API keys in mobile apps. Instead of embedding API keys in your app (where they can be extracted), your app calls ProtectMyAPI, which verifies the request comes from a legitimate app installation, then adds your API key and forwards to the destination. **Flow:** ``` Your App → ProtectMyAPI (verifies device + adds API key) → AI Provider (OpenAI, etc.) ``` **Benefits:** - API keys never in your app binary - Device attestation (App Attest on iOS, Play Integrity on Android) - Jailbreak/root detection - 20+ AI providers ready to use --- ## Quick Start ### iOS (Swift) **1. Install via Swift Package Manager:** ```swift // In Xcode: File → Add Package Dependencies // URL: https://github.com/protectmyapi/ios-sdk // Or in Package.swift: dependencies: [ .package(url: "https://github.com/protectmyapi/ios-sdk", from: "1.0.0") ] ``` **2. Initialize (in AppDelegate or App struct):** ```swift import ProtectMyAPI @main struct MyApp: App { init() { ProtectMyAPI.shared.configure( appId: "YOUR_APP_ID", // From dashboard.protectmyapi.com environment: .production ) } var body: some Scene { WindowGroup { ContentView() } } } ``` **3. Make API calls:** ```swift // Simple chat with OpenAI let openai = ProtectMyAPI.openAIService() let response = try await openai.chat( message: "Hello!", model: "gpt-4o-mini" ) print(response) // With full control let response = try await openai.createChatCompletion( request: OpenAIChatRequest( model: "gpt-4o", messages: [ .system("You are a helpful assistant."), .user("Explain quantum computing") ], temperature: 0.7, maxTokens: 1000 ) ) ``` ### Android (Kotlin) **1. Add to build.gradle.kts:** ```kotlin repositories { maven { url = uri("https://maven.pkg.github.com/protectmyapi/android-sdk") } } dependencies { implementation("com.protectmyapi:sdk:1.0.0") } ``` **2. Initialize (in Application class):** ```kotlin import com.protectmyapi.ProtectMyAPI class MyApplication : Application() { override fun onCreate() { super.onCreate() ProtectMyAPI.initialize( context = this, appId = "YOUR_APP_ID", environment = Environment.PRODUCTION ) } } ``` **3. Make API calls:** ```kotlin // Simple chat with OpenAI val openai = ProtectMyAPIAI.openAIService() val response = openai.chat( message = "Hello!", model = "gpt-4o-mini" ) println(response) // With full control val response = openai.createChatCompletion( request = OpenAIChatRequest( model = "gpt-4o", messages = listOf( OpenAIMessage.system("You are a helpful assistant."), OpenAIMessage.user("Explain quantum computing") ), temperature = 0.7, maxTokens = 1000 ) ) ``` ### Flutter (Dart) **1. Add to pubspec.yaml:** ```yaml dependencies: protectmyapi: ^1.0.0 ``` **2. Initialize (in main.dart):** ```dart import 'package:protectmyapi/protectmyapi.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await ProtectMyAPI.initialize( appId: 'YOUR_APP_ID', environment: Environment.production, ); runApp(MyApp()); } ``` **3. Make API calls:** ```dart // Simple chat with OpenAI final openai = ProtectMyAPIAI.openAIService(); final response = await openai.chat( message: "Hello!", model: "gpt-4o-mini", ); print(response); // With full control final response = await openai.createChatCompletion( request: OpenAIChatRequest( model: "gpt-4o", messages: [ OpenAIMessage.system("You are a helpful assistant."), OpenAIMessage.user("Explain quantum computing"), ], temperature: 0.7, maxTokens: 1000, ), ); ``` --- ## All Available AI Services Get a service instance, then call its methods: ```swift // iOS let openai = ProtectMyAPI.openAIService() let anthropic = ProtectMyAPI.anthropicService() let gemini = ProtectMyAPI.geminiService() let mistral = ProtectMyAPI.mistralService() let groq = ProtectMyAPI.groqService() let deepseek = ProtectMyAPI.deepSeekService() let stability = ProtectMyAPI.stabilityService() let elevenlabs = ProtectMyAPI.elevenLabsService() let perplexity = ProtectMyAPI.perplexityService() let together = ProtectMyAPI.togetherService() let replicate = ProtectMyAPI.replicateService() let fireworks = ProtectMyAPI.fireworksService() let openrouter = ProtectMyAPI.openRouterService() let brave = ProtectMyAPI.braveSearchService() let deepl = ProtectMyAPI.deepLService() let fal = ProtectMyAPI.falService() let weather = ProtectMyAPI.openMeteoService() ``` ```kotlin // Android val openai = ProtectMyAPIAI.openAIService() val anthropic = ProtectMyAPIAI.anthropicService() // ... same pattern for all services ``` ```dart // Flutter final openai = ProtectMyAPIAI.openAIService(); final anthropic = ProtectMyAPIAI.anthropicService(); // ... same pattern for all services ``` --- ## Common Patterns ### OpenAI - Chat ```swift let openai = ProtectMyAPI.openAIService() // Simple let answer = try await openai.chat(message: "Hello!", model: "gpt-4o-mini") // With conversation history let response = try await openai.createChatCompletion( request: OpenAIChatRequest( model: "gpt-4o", messages: [ .system("You are a helpful assistant."), .user("What is 2+2?"), .assistant("2+2 equals 4."), .user("And what is that times 10?") ] ) ) ``` ### OpenAI - Streaming ```swift for try await chunk in openai.createChatCompletionStream( request: OpenAIChatRequest( model: "gpt-4o", messages: [.user("Write a story")] ) ) { print(chunk.choices.first?.delta?.content ?? "", terminator: "") } ``` ### OpenAI - Vision (Image Analysis) ```swift let response = try await openai.createChatCompletion( request: OpenAIChatRequest( model: "gpt-4o", messages: [ .user(content: [ .text("What's in this image?"), .imageUrl(url: "https://example.com/image.jpg") ]) ] ) ) ``` ### OpenAI - Image Generation (DALL-E) ```swift let image = try await openai.createImage( request: OpenAIImageRequest( model: "dall-e-3", prompt: "A sunset over mountains", size: "1024x1024", quality: "hd" ) ) let imageUrl = image.data.first?.url ``` ### Anthropic - Claude ```swift let anthropic = ProtectMyAPI.anthropicService() let response = try await anthropic.createMessage( request: AnthropicMessageRequest( model: "claude-3-5-sonnet-20241022", maxTokens: 1024, messages: [ .user("Explain machine learning") ] ) ) ``` ### Google Gemini ```swift let gemini = ProtectMyAPI.geminiService() let response = try await gemini.generateContent( request: GeminiRequest( model: "gemini-2.0-flash-exp", contents: [ .user("Hello!") ] ) ) ``` ### Stability AI - Image Generation ```swift let stability = ProtectMyAPI.stabilityService() // Ultra quality let image = try await stability.generateImageUltra( prompt: "A beautiful landscape", options: StabilityUltraOptions( aspectRatio: "16:9", outputFormat: .png ) ) // Core (faster) let image = try await stability.generateImageCore( prompt: "A cat wearing a hat", options: StabilityCoreOptions( aspectRatio: "1:1" ) ) ``` ### ElevenLabs - Text-to-Speech ```swift let elevenlabs = ProtectMyAPI.elevenLabsService() let audioData = try await elevenlabs.textToSpeech( text: "Hello, how are you today?", voiceId: "21m00Tcm4TlvDq8ikWAM", // Rachel voice options: ElevenLabsTTSOptions( modelId: "eleven_multilingual_v2", stability: 0.5, similarityBoost: 0.75 ) ) // audioData is Data that can be played with AVAudioPlayer ``` ### Perplexity - AI Search ```swift let perplexity = ProtectMyAPI.perplexityService() let response = try await perplexity.createChatCompletion( request: PerplexityChatRequest( model: .sonarLarge, messages: [.user("What are the latest AI news?")] ) ) // Access citations for citation in response.citations ?? [] { print("Source: \(citation)") } ``` ### DeepL - Translation ```swift let deepl = ProtectMyAPI.deepLService() let result = try await deepl.translateText( text: "Hello, how are you?", targetLang: "DE" ) print(result.translations.first?.text) // "Hallo, wie geht es Ihnen?" ``` ### Brave Search - Web Search ```swift let brave = ProtectMyAPI.braveSearchService() let results = try await brave.webSearch(query: "Swift programming") for result in results.web?.results ?? [] { print("\(result.title): \(result.url)") } ``` ### Open-Meteo - Weather (Free, no API key needed) ```swift let weather = ProtectMyAPI.openMeteoService() let current = try await weather.getCurrentWeather( latitude: 37.7749, longitude: -122.4194 ) print("Temperature: \(current.temperature)°C") ``` --- ## Configuration Options ### Full Configuration (iOS) ```swift ProtectMyAPI.shared.configure( appId: "YOUR_APP_ID", environment: .production, // .production or .development options: ProtectMyAPIOptions( // Security requireAttestation: true, // Require App Attest (default: true) allowSimulator: false, // Allow simulators (default: false) allowDebugBuilds: false, // Allow debug builds (default: false) enableSecurityChecks: true, // Jailbreak detection (default: true) // Network timeout: 30, // Request timeout in seconds retryCount: 3, // Number of retries // Logging enableLogging: false // Debug logging (default: false) ) ) ``` ### Full Configuration (Android) ```kotlin ProtectMyAPI.initialize( context = this, appId = "YOUR_APP_ID", environment = Environment.PRODUCTION, options = ProtectMyAPIOptions( requireAttestation = true, allowEmulator = false, allowDebugBuilds = false, enableSecurityChecks = true, timeout = 30, retryCount = 3, enableLogging = false ) ) ``` ### Full Configuration (Flutter) ```dart await ProtectMyAPI.initialize( appId: 'YOUR_APP_ID', environment: Environment.production, options: ProtectMyAPIOptions( requireAttestation: true, allowSimulator: false, allowDebugBuilds: false, enableSecurityChecks: true, timeout: 30, retryCount: 3, enableLogging: false, ), ); ``` --- ## Security Features ### Check Device Security ```swift // iOS let report = ProtectMyAPI.shared.getSecurityReport() print("Jailbroken: \(report.isJailbroken)") print("Debugger: \(report.isDebuggerAttached)") print("Tampered: \(report.isAppTampered)") print("Simulator: \(report.isSimulator)") if !report.isSecure { // Handle compromised device } ``` ```kotlin // Android val checker = ProtectMyAPI.getSecurityChecker() val report = checker.performSecurityChecks() println("Rooted: ${report.isRooted}") println("Debugger: ${report.isDebuggerAttached}") println("Emulator: ${report.isEmulator}") ``` ```dart // Flutter final report = await ProtectMyAPI.instance.getSecurityReport(); print("Compromised: ${report.isDeviceCompromised}"); print("Debugger: ${report.isDebuggerAttached}"); print("Emulator: ${report.isEmulator}"); ``` --- ## Error Handling ```swift // iOS do { let response = try await openai.chat(message: "Hello", model: "gpt-4o") } catch ProtectMyAPIError.attestationFailed { // Device attestation failed - likely simulator or jailbroken } catch ProtectMyAPIError.networkError(let error) { // Network issue } catch ProtectMyAPIError.rateLimited { // Too many requests } catch ProtectMyAPIError.unauthorized { // Invalid app ID or configuration } catch { // Other error } ``` ```kotlin // Android try { val response = openai.chat(message = "Hello", model = "gpt-4o") } catch (e: ProtectMyAPIException.AttestationFailed) { // Device attestation failed } catch (e: ProtectMyAPIException.NetworkError) { // Network issue } catch (e: ProtectMyAPIException.RateLimited) { // Too many requests } catch (e: Exception) { // Other error } ``` ```dart // Flutter try { final response = await openai.chat(message: "Hello", model: "gpt-4o"); } on AttestationFailedException { // Device attestation failed } on NetworkException { // Network issue } on RateLimitedException { // Too many requests } catch (e) { // Other error } ``` --- ## Model Reference ### OpenAI Models - `gpt-4o` - Most capable, multimodal - `gpt-4o-mini` - Fast and cheap - `gpt-4-turbo` - Previous generation - `dall-e-3` - Image generation - `whisper-1` - Audio transcription - `tts-1`, `tts-1-hd` - Text-to-speech ### Anthropic Models - `claude-3-5-sonnet-20241022` - Best for coding - `claude-3-opus-20240229` - Most capable - `claude-3-haiku-20240307` - Fastest ### Google Gemini Models - `gemini-2.0-flash-exp` - Latest, fast - `gemini-1.5-pro` - Long context (2M tokens) - `gemini-1.5-flash` - Fast ### Stability AI Models - `ultra` - Highest quality images - `core` - Fast, good quality - `sd3.5-large` - Stable Diffusion 3.5 ### ElevenLabs Voice IDs - `21m00Tcm4TlvDq8ikWAM` - Rachel (female) - `AZnzlk1XvdvUeBnXmlld` - Domi (female) - `EXAVITQu4vr4xnSDxMaL` - Bella (female) - `ErXwobaYiN019PkySvjV` - Antoni (male) - `VR6AewLTigWG4xSOukaG` - Arnold (male) --- ## Important Notes 1. **Real Device Required**: Attestation (App Attest/Play Integrity) only works on real devices, not simulators/emulators. 2. **Dashboard Setup**: You must create an app at dashboard.protectmyapi.com and add your API keys there before using any AI service. 3. **Environment**: Use `.development` during testing (allows simulators), switch to `.production` for release. 4. **API Keys**: Never put API keys in your app code. Add them in the ProtectMyAPI dashboard. --- ## Links - Dashboard: https://dashboard.protectmyapi.com - Documentation: https://docs.protectmyapi.com - Support: support@protectmyapi.com