Skip to content

Instantly share code, notes, and snippets.

@mariosaputra
Created December 16, 2025 10:24
Show Gist options
  • Select an option

  • Save mariosaputra/ca7785727559703d6a966f19beafde40 to your computer and use it in GitHub Desktop.

Select an option

Save mariosaputra/ca7785727559703d6a966f19beafde40 to your computer and use it in GitHub Desktop.

PlantID - AI-Powered Plant Identification

A SwiftUI app that identifies plants using AI vision APIs (OpenAI or Gemini) with Firebase Remote Config for dynamic configuration.


πŸ“‹ Table of Contents

  1. AIProxy Setup
  2. Firebase Remote Config Setup
  3. Integrating into Your Project
  4. Testing & Verification

1. AIProxy Setup

AIProxy provides a secure way to use AI APIs in mobile apps without exposing your API keys. It supports multiple providers including OpenAI and Gemini.

πŸ“š Official Documentation

1.1 Create AIProxy Account

  1. Go to AIProxy Dashboard
  2. Create an account and log in
  3. Create a new project for your app

1.2 Configure OpenAI

  1. In AIProxy dashboard, add OpenAI as a provider
  2. Enter your OpenAI API key
  3. Copy the generated:
    • Partial Key (e.g., v2|xxxxxxxx|xxxxxxxxxxxxxx)
    • Service URL (e.g., https://api.aiproxy.com/xxxxx/xxxxx)

1.3 Configure Gemini

  1. In AIProxy dashboard, add Gemini as a provider
  2. Enter your Google AI API key
  3. Copy the generated:
    • Partial Key
    • Service URL

1.4 Device Check Bypass (Development Only)

For development and testing, you need to configure the device check bypass:

  1. In AIProxy dashboard, go to Project's Device Check
  2. Find DeviceCheck Bypass Token
  3. Copy your bypass token
  4. Add to your Xcode scheme environment variables:
AIPROXY_DEVICE_CHECK_BYPASS = your_bypass_token_here

How to add in Xcode:

  1. Select your target scheme β†’ Edit Scheme
  2. Go to Run β†’ Arguments β†’ Environment Variables
  3. Add AIPROXY_DEVICE_CHECK_BYPASS with your token value

2. Firebase Remote Config Setup

Firebase Remote Config allows you to dynamically change app behavior without releasing a new version. This project uses it to switch AI providers and models on the fly.

πŸ“š Official Documentation

2.1 Create Firebase Project

  1. Go to Firebase Console
  2. Click Add Project and follow the setup wizard
  3. Add an iOS app to your project
  4. Download GoogleService-Info.plist

2.2 Configure Remote Config Parameters

Navigate to Remote Config in your Firebase Console and add the following parameters:

Parameter Key Default Value Description
ai_provider openai Active AI provider (openai or gemini)
openai_model_name gpt-4.1-mini OpenAI model to use
gemini_model_name gemini-2.5-flash Gemini model to use
system_prompt (see below) System prompt for AI

πŸ’‘ Tip: You can leave any Remote Config parameter blank in Firebase. The app will automatically use the default values defined in RemoteConfigManager.swift. For example, you can leave system_prompt empty, and the app will use the built-in default prompt.

2.3 Adding Remote Config Values

Step-by-step:

  1. In Firebase Console, go to Remote Config
  2. Click Add Parameter
  3. Enter the parameter key (e.g., ai_provider)
  4. Set the default value (e.g., openai)
  5. Click Save
  6. Repeat for all parameters
  7. Click Publish Changes

2.4 Example: Changing AI Provider

To switch from OpenAI to Gemini:

  1. Go to Remote Config in Firebase Console
  2. Find the ai_provider parameter
  3. Change value from openai to gemini
  4. Click Save then Publish Changes
  5. The app will use Gemini on next launch or foreground

2.5 Example: Changing AI Model

To change the OpenAI model:

  1. Find openai_model_name parameter
  2. Change value (e.g., gpt-4o or gpt-4.1-nano)
  3. Save and publish

Available models:

Check the official documentation for the latest supported models:


3. Integrating into Your Project

3.1 Replace GoogleService-Info.plist

  1. Download GoogleService-Info.plist from your Firebase project
  2. Delete the existing GoogleService-Info.plist in your Xcode project
  3. Drag and drop your new GoogleService-Info.plist into Xcode
  4. Ensure "Copy items if needed" is checked
  5. Add to your app target

3.2 Replace AIProxy Service Initialization

Open AIProxyService.swift and update the initialization with your AIProxy credentials:

// MARK: - Initialization
private init() {
    // Replace with YOUR OpenAI AIProxy credentials
    self.openAIClient = AIProxy.openAIService(
        partialKey: "YOUR_OPENAI_PARTIAL_KEY",      // e.g., "v2|xxxxxxxx|xxxxxxxxxxxxxx"
        serviceURL: "YOUR_OPENAI_SERVICE_URL"       // e.g., "https://api.aiproxy.com/xxxxx/xxxxx"
    )

    // Replace with YOUR Gemini AIProxy credentials
    self.geminiClient = AIProxy.geminiService(
        partialKey: "YOUR_GEMINI_PARTIAL_KEY",      // e.g., "v2|xxxxxxxx|xxxxxxxxxxxxxx"
        serviceURL: "YOUR_GEMINI_SERVICE_URL"       // e.g., "https://api.aiproxy.com/xxxxx/xxxxx"
    )
}

Location in code:

PlantID/
└── Services/
    └── AIProxyService.swift  ← Edit lines 76-84

3.3 Customize for Your Use Case (Optional)

Modify the System Prompt

Update RemoteConfigManager.swift to change the default system prompt for your use case:

static let defaultSystemPrompt: String = """
    Your custom prompt here...
    """

Create Your Own Data Model

Modify PlantData.swift or create a new model that matches your AI response structure:

struct YourCustomResult: Codable {
    let success: Bool
    let data: YourDataResponse?
    let error: String?
}

struct YourDataResponse: Codable {
    // Your custom fields
}

4. Testing & Verification

4.1 Verify Remote Config Values


Run the app in DEBUG mode to see configuration logs in the Xcode console:

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ”§ REMOTE CONFIG VALUES:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
πŸ€– AI Provider: openai
πŸ€– OpenAI Model: gpt-4.1-mini
πŸ€– Gemini Model: gemini-2.5-flash
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

4.2 Test AI Identification

  1. Launch the app
  2. Take or select a photo
  3. Verify the identification result appears

4.3 Test Provider Switching

  1. Change ai_provider in Firebase Console from openai to gemini
  2. Publish the changes
  3. Background and foreground the app (or relaunch)
  4. Check console logs for updated provider
  5. Test identification again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment