Call ChatGPT

Call ChatGPT in a reliable manner, in seconds

Usage

Step 1. Get an API key

For more information, consult OpenAI's official documentation.

⚠️ Please take precautions to keep your API key secure per OpenAI's guidance:

Remember that your API key is a secret! Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your backend server where your API key can be securely loaded from an environment variable or key management service.

SwiftOpenAI has built-in support for AIProxy, which is a backend for AI apps, to satisfy this requirement. To configure AIProxy, see the instructions here.

Step 2. Add SwiftOpenAI SDK

  • Go to File -> Add Package Dependency.
  • In the search bar, enter this URL.
  • Choose the version you'd like to install.
  • Click Add Package.

Step 3. Send chat completion request

AI.shared.sendCompletion(prompt: T##String, shouldRetry: T##Bool, shouldUseLatestModel: T##Bool?, completion: T##(String?, Error?) -> ())