Migrating to SwiftOpenAI version 3.4

June 26, 2024 by Lou Zell

Updating the SwiftOpenAI package

SwiftOpenAI 3.4 contains security improvements for AIProxy customers. Please upgrade to 3.4.0 by navigating to the following section of your Xcode project:

Version 3.4 Updates

  • The AIProxy integration now uses certificate pinning to prevent threat actors from snooping on your traffic. There are no changes to your client code necessary to take advantage of this security improvement
  • The AIProxy integration has a changed method for hiding the DeviceCheck bypass token. This token is only intended to be used on iOS simulators, and the previous method of hiding was too easy to leak into production builds of the app. Please change your integration code from:
#if DEBUG && targetEnvironment(simulator)
    OpenAIServiceFactory.service(
	    aiproxyPartialKey: "hardcode-partial-key-here",
	    aiproxyDeviceCheckBypass: "hardcode-device-check-bypass-here"
    )
#else
	OpenAIServiceFactory.service(aiproxyPartialKey: "hardcode-partial-key-here")
#endif

To this:

let service: OpenAIService = OpenAIServiceFactory.service(
    aiproxyPartialKey: "hardcode-partial-key-here"
)

How to add the 'AIPROXY_DEVICE_CHECK_BYPASS' env variable to your Xcode project

This token is provided to you in the AIProxy developer dashboard, and is necessary for the iOS simulator to communicate with the AIProxy backend. Follow these steps to add it to your Xcode project:

  1. Type cmd shift , to open up the "Edit Schemes" menu in Xcode
  2. Select Run in the sidebar
  3. Select Arguments from the top nav
  4. Add to the "Environment Variables" section (not the "Arguments Passed on Launch" section) an env variable with name AIPROXY_DEVICE_CHECK_BYPASS and value that we provided you in the AIProxy dashboard