Swift · iOS · macOS

Call AI from Swift without shipping the provider key.

Use generated provider APIs or a generic HTTP client, preserve streaming and realtime behavior, and require Apple device proof before a request reaches the provider.

Swift 6.2iOS 15+Provider-native payloads
Mobile security boundary

An App Store binary is a public place for secrets.

Obfuscation can slow extraction down, but it cannot make a provider key private. Move the credential boundary to a server and give the app only the narrowly scoped access it needs.

01

Keep keys off-device

The provider key is stored as a split-key envelope. The usable value exists only in gateway memory while a request is forwarded.

02

Verify the installation

Require DeviceCheck, an App Attest device token, or a Secure Enclave assertion that covers the method, URL, body and routing controls.

03

Limit the blast radius

Restrict endpoints and models, rate-limit by app key, IP or device, and rotate named keys with a grace period for older releases.

Typed Swift client

Keep provider concepts in your code.

HyperProxySwift exposes generated request and response types for supported providers while the gateway preserves each provider's path, body and streaming format.

  • Async/await APIs and typed errors.
  • SSE, JSONL, binary downloads and multipart uploads.
  • Provider-native WebSockets and realtime frames.
  • Generic requests for APIs outside the generated catalog.
Proxied.swiftSwift
import HyperProxyOpenAI

let openAI = HyperProxy.openAI(
  gatewayURL: gatewayURL,
  appKey: appKey
)

let response: OpenAIResponse =
  try await openAI.responsesCreate(
    OpenAICreateResponse(
      input: "Hello", model: "gpt-5"
    )
  )
App Attest

Add proof before forwarding.

Choose the trade-off per service. Attestation is enforced before HyperProxy opens the credential envelope or contacts the provider.

Device token

Attest once and exchange the result for a short-lived HyperProxy device token. It avoids an Apple round-trip on every AI request.

Per-request assertion

Sign a canonical request digest in Secure Enclave. Monotonic counters and one-time challenges defend against replay.

DeviceCheck

Use a fresh Apple proof for lightweight validation when the stronger App Attest integration is not required.

Transport support

Do not trade mobile security for a smaller AI API.

WorkloadSwift supportGateway behavior
Chat and responsesTyped request and response modelsProvider-native JSON
Streaming outputAsyncSequence for typed SSE or raw eventsStreamed without response buffering
Audio, images and filesMultipart upload and binary progressIncremental upload and download
RealtimeTyped JSON and binary WebSocket framesProvider-native socket transport
FAQ

Swift AI gateway questions.

Can an iOS app safely contain a provider API key?

No distributed app can keep a long-lived credential secret. HyperProxy moves it behind the gateway and gives the app a service-scoped app key.

Does HyperProxySwift support streaming?

Yes. The transport includes typed SSE and JSONL, binary responses, uploads, polling and provider-native WebSockets.

Do I have to use the Swift SDK?

No. Any HTTP client can call the gateway by preserving the provider path and body and replacing the upstream credential with X-HyperProxy-Key.

Build the AI feature. Keep its master key off the phone.