Swift Examples - Stability AI
Service setup
Create a Stability AI service in the AIProxy dashboard
Follow the integration guide, selecting the Stability AI icon on the 'Create a New Service' form.
How to generate an image with Stability.ai
In the snippet below, replace NSImage with UIImage if you are building on iOS.
import AIProxy
let service = AIProxy.stabilityAIService(
partialKey: "partial-key-from-your-developer-dashboard",
serviceURL: "service-url-from-your-developer-dashboard"
)
do {
let body = StabilityAIUltraRequestBody(prompt: "Lighthouse on a cliff overlooking the ocean")
let response = try await service.ultraRequest(body: body)
let image = NSImage(data: response.imageData)
// Do something with `image`
} catch AIProxyError.unsuccessfulRequest(let statusCode, let responseBody) {
print("Received \(statusCode) status code with response body: \(responseBody)")
} catch {
print("Could not generate an image with StabilityAI: \(error.localizedDescription)")
}