# ProtectMyAPI Integration Rules You are helping integrate ProtectMyAPI into a mobile app. ProtectMyAPI protects API keys by proxying requests through a secure server with device attestation. ## Key Concepts - API keys are stored in the ProtectMyAPI dashboard, NOT in the app - The SDK verifies the device is legitimate before forwarding requests - Works with iOS (App Attest), Android (Play Integrity), and Flutter ## Quick Reference ### iOS Setup ```swift import ProtectMyAPI // In App init or AppDelegate ProtectMyAPI.shared.configure( appId: "APP_ID_FROM_DASHBOARD", environment: .production ) // Use AI services let openai = ProtectMyAPI.openAIService() let response = try await openai.chat(message: "Hello", model: "gpt-4o-mini") ``` ### Android Setup ```kotlin import com.protectmyapi.ProtectMyAPI // In Application.onCreate() ProtectMyAPI.initialize( context = this, appId = "APP_ID_FROM_DASHBOARD", environment = Environment.PRODUCTION ) // Use AI services val openai = ProtectMyAPIAI.openAIService() val response = openai.chat(message = "Hello", model = "gpt-4o-mini") ``` ### Flutter Setup ```dart import 'package:protectmyapi/protectmyapi.dart'; // In main() await ProtectMyAPI.initialize( appId: 'APP_ID_FROM_DASHBOARD', environment: Environment.production, ); // Use AI services final openai = ProtectMyAPIAI.openAIService(); final response = await openai.chat(message: "Hello", model: "gpt-4o-mini"); ``` ## Available Services ``` ProtectMyAPI.openAIService() - ChatGPT, DALL-E, Whisper ProtectMyAPI.anthropicService() - Claude ProtectMyAPI.geminiService() - Google Gemini ProtectMyAPI.mistralService() - Mistral AI ProtectMyAPI.groqService() - Groq (fast inference) ProtectMyAPI.deepSeekService() - DeepSeek (reasoning) ProtectMyAPI.stabilityService() - Image generation ProtectMyAPI.elevenLabsService() - Text-to-speech ProtectMyAPI.perplexityService() - AI search with citations ProtectMyAPI.togetherService() - Open source models ProtectMyAPI.replicateService() - ML models ProtectMyAPI.fireworksService() - Fast LLMs ProtectMyAPI.openRouterService() - Multi-provider routing ProtectMyAPI.braveSearchService() - Web search ProtectMyAPI.deepLService() - Translation ProtectMyAPI.falService() - Fast image gen ProtectMyAPI.openMeteoService() - Weather (free) ``` ## Common Patterns ### Chat with OpenAI ```swift let openai = ProtectMyAPI.openAIService() let response = try await openai.createChatCompletion( request: OpenAIChatRequest( model: "gpt-4o", messages: [ .system("You are helpful."), .user("Hello!") ] ) ) print(response.choices.first?.message.content ?? "") ``` ### Streaming ```swift for try await chunk in openai.createChatCompletionStream(request: request) { print(chunk.choices.first?.delta?.content ?? "", terminator: "") } ``` ### Image Generation ```swift let stability = ProtectMyAPI.stabilityService() let image = try await stability.generateImageUltra( prompt: "A sunset over mountains", options: StabilityUltraOptions(aspectRatio: "16:9") ) ``` ### Text-to-Speech ```swift let elevenlabs = ProtectMyAPI.elevenLabsService() let audio = try await elevenlabs.textToSpeech( text: "Hello world", voiceId: "21m00Tcm4TlvDq8ikWAM" ) ``` ## Important Rules 1. NEVER put API keys in app code - they go in the dashboard 2. Use .development environment for testing (allows simulators) 3. Use .production environment for release builds 4. Attestation requires real devices, not simulators 5. Always handle errors (attestation can fail) ## Error Handling ```swift do { let response = try await openai.chat(message: "Hi", model: "gpt-4o") } catch ProtectMyAPIError.attestationFailed { // Device failed verification (simulator, jailbroken, etc.) } catch ProtectMyAPIError.networkError { // Network issue } catch ProtectMyAPIError.rateLimited { // Too many requests } ``` ## Full Documentation For complete API reference: https://docs.protectmyapi.com For comprehensive AI context: https://docs.protectmyapi.com/llms-full.txt