The Tinfoil Swift SDK is a wrapper around the MacPaw OpenAI SDK that provides secure communication with Tinfoil enclaves. It has the same API as the OpenAI SDK with additional security features including automatic verification that the endpoint is running in a secure Tinfoil enclave, TLS certificate pinning, and attestation validation.
Enter the repository URL: https://github.com/tinfoilsh/tinfoil-swift.git
Select the version you want to use
Click “Add Package”
Note: Tinfoil Swift requires the MacPaw OpenAI SDK as a dependency. When you add Tinfoil Swift through Swift Package Manager, the OpenAI SDK will be automatically included.
The TinfoilAI.create() method returns a standard OpenAI client that’s been configured with secure enclave verification, certificate pinning, and automatic TLS validation.
let chatQuery = ChatQuery( messages: [ .user(.init(content: .string("Tell me a story about AI safety"))) ], model: "llama3-3-70b", stream: true)// Stream the responsefor try await result in client.chatsStream(query: chatQuery) { if let choice = result.choices.first, let delta = choice.delta.content { print("Received: \(delta)") } // Check for completion if let finishReason = result.choices.first?.finishReason { print("Stream finished with reason: \(finishReason)") break }}
By default, Tinfoil Swift enforces strict security by failing requests when enclave verification or certificate pinning fails. With non-blocking verification, you can allow requests to proceed even if verification fails, while still being notified of the verification status through a callback.
Copy
Ask AI
// Set up a callback to handle verification resultslet verificationCallback: NonblockingVerification = { verificationPassed in if verificationPassed { print("✅ Enclave verification passed - connection is secure") } else { print("❌ Enclave verification failed - connection may not be secure") // Handle verification failure (log, alert user, etc.) }}// Create client with non-blocking verificationlet client = try await TinfoilAI.create( apiKey: ProcessInfo.processInfo.environment["TINFOIL_API_KEY"] ?? "", githubRepo: "tinfoilsh/model-repo", enclaveURL: "enclave.example.com", nonblockingVerification: verificationCallback)// Requests will proceed even if certificate verification failslet chatQuery = ChatQuery( messages: [ .user(.init(content: .string("Hello, I need a quick response!"))) ], model: "llama3-3-70b")// This request will go through regardless of verification statuslet response = try await client.chats(query: chatQuery)print(response.choices.first?.message.content ?? "No response")
Important Security Warning: When using non-blocking verification, requests will proceed even if enclave verification or certificate pinning fails. Only use this mode when availability is more important than security guarantees.
This library is a drop-in replacement for the MacPaw OpenAI Swift client that can be used with Tinfoil. All methods and types are identical. See the MacPaw OpenAI documentation for complete API usage and documentation.