How to add OpenAI to your iOS app
What OpenAI does for an iOS app
OpenAI's API lets your app generate text, answer questions, transcribe audio, and create images. Typical features are an in-app assistant, smart summaries of user content, autocomplete, or natural-language search. The technical catch is security. Unlike a public client key, the OpenAI key is a true secret: anyone who extracts it from your binary can spend against your account. That is why the correct architecture always routes calls through a backend you own, where the key lives in an environment variable, and the app only ever sees your endpoint.
Adding OpenAI with AppFlight
In AppFlight you open the integrations panel, choose OpenAI, and provide your API key. AppFlight stores it as a backend secret in your own Supabase, never as a client value, so it does not ship in the app. The app calls a Supabase edge function, that function adds the key and forwards the request to OpenAI, and the response comes back to the app. From there you can ask the AI to add a chat screen or a summarize button, and it generates the SwiftUI client plus the server call that keeps the key safe.
A SwiftUI example
The app posts a prompt to your own proxy endpoint, which holds the secret key:
import SwiftUI
struct AssistantView: View {
@State private var prompt = ""
@State private var answer = ""
var body: some View {
VStack {
TextField("Ask anything", text: $prompt)
Button("Send") { Task { answer = await ask(prompt) } }
Text(answer)
}
.padding()
}
// Calls your server, not OpenAI directly. The secret key stays server-side.
func ask(_ text: String) async -> String {
var request = URLRequest(url: URL(string: "https://yourproject.supabase.co/functions/v1/ask")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONEncoder().encode(["prompt": text])
guard let (data, _) = try? await URLSession.shared.data(for: request),
let reply = try? JSONDecoder().decode([String: String].self, from: data)
else { return "Something went wrong." }
return reply["answer"] ?? ""
}
}
Alternatives
Anthropic's Claude API and Google's Gemini API fill the same role and have the same key-handling rule: keep the secret server-side. Apple's on-device Foundation Models can run simple language tasks locally with no key and no network, which is best for privacy-sensitive features, though it is less capable than a frontier hosted model. OpenAI is the broad default when you want strong general models and a wide feature set, accessed through a server you control.
FAQ
Can I put my OpenAI API key in the iOS app?
No. The OpenAI API key is a secret that grants full billing access to your account. If it ships in the binary it can be extracted and abused. The app should call your own server, which holds the key and forwards the request. AppFlight keeps it server-side in your Supabase.
How does the app talk to OpenAI without the key?
Through a proxy. The app sends the prompt to an endpoint you control, that endpoint adds the secret key and calls OpenAI, then returns the result. With AppFlight this proxy can be a Supabase edge function so the key never leaves the server.
Is the AI in AppFlight the same as OpenAI in my app?
No. AppFlight uses your own Claude Code or Codex to build the app on your Mac. OpenAI as an integration is a runtime feature inside the app you ship, like an in-app assistant. They are separate things.