@@ -3012,33 +3012,35 @@ We offer AIProxy support so that developers can build **and** distribute apps us
3012
3012
3013
3013
### How does my SwiftOpenAI code change?
3014
3014
3015
- SwiftOpenAI supports proxying requests through AIProxy with a small change to your integration code.
3015
+ SwiftOpenAI supports proxying requests through AIProxy with two changes to your Xcode project :
3016
3016
3017
- Instead of initializing `service` with:
3017
+ 1 . Instead of initializing `service` with:
3018
3018
3019
3019
let apiKey = " your_openai_api_key_here"
3020
3020
let service = OpenAIServiceFactory.service (apiKey : apiKey)
3021
3021
3022
3022
Use:
3023
3023
3024
- #if DEBUG && targetEnvironment (simulator)
3025
3024
let service = OpenAIServiceFactory.service (
3026
3025
aiproxyPartialKey : " hardcode_partial_key_here" ,
3027
- aiproxyDeviceCheckBypass : " hardcode_device_check_bypass_here"
3028
3026
)
3029
- #else
3030
- let service = OpenAIServiceFactory.service (
3031
- aiproxyPartialKey : " hardcode_partial_key_here"
3032
- )
3033
- #endif
3034
3027
3035
- The `aiproxyPartialKey` and `aiproxyDeviceCheckBypass` values are provided to you on the [AIProxy developer dashboard](https :// developer.aiproxy.pro).
3028
+ The `aiproxyPartialKey` value is provided to you on the [AIProxy developer dashboard](https :// developer.aiproxy.pro)
3029
+
3030
+ 2 . Add an `AIPROXY_DEVICE_CHECK_BYPASS' env variable to Xcode. This token is provided to you in the AIProxy
3031
+ developer dashboard, and is necessary for the iOS simulator to communicate with the AIProxy backend.
3032
+ - Type `cmd shift ,` to open up the " Edit Schemes" menu in Xcode
3033
+ - Select `Run` in the sidebar
3034
+ - Select `Arguments` from the top nav
3035
+ - Add to the " Environment Variables" section (not the " Arguments Passed on Launch" section) an env
3036
+ variable with name `AIPROXY_DEVICE_CHECK_BYPASS` and value that we provided you in the AIProxy dashboard
3037
+
3036
3038
3037
- ⚠️ It is important that you do not let the `aiproxyDeviceCheckBypass` token leak into a distribution
3038
- build of your app (including TestFlight distributions ). Please retain the conditional compilation
3039
- checks that are present in the sample code above .
3039
+ ⚠️ The `AIPROXY_DEVICE_CHECK_BYPASS` is intended for the simulator only. Do not let it leak into
3040
+ a distribution build of your app (including a TestFlight distribution ). If you follow the steps above,
3041
+ then the constant won't leak because env variables are not packaged into the app bundle .
3040
3042
3041
- #### What is the `aiproxyDeviceCheckBypass ` constant?
3043
+ #### What is the `AIPROXY_DEVICE_CHECK_BYPASS ` constant?
3042
3044
3043
3045
AIProxy uses Apple's [DeviceCheck](https :// developer.apple.com/documentation/devicecheck) to ensure
3044
3046
that requests received by the backend originated from your app on a legitimate Apple device.
0 commit comments