Hanzo
SDKs

Swift SDK

The Hanzo Swift Cloud SDK — native iOS/macOS client via Swift Package Manager. Coming soon.

Swift SDK

A native Cloud SDK for Swift — async/await, Codable models, first-class on iOS, macOS, and the rest of the Apple platforms.

Coming soon

The Swift package is in active development in the per-language org hanzo-swift. Until it ships, reach the Open AI Cloud from Swift with URLSession against https://api.hanzo.ai/v1 (OpenAI-compatible).

Install (planned)

Swift Package Manager:

// Package.swift
dependencies: [
    .package(url: "https://github.com/hanzo-swift/sdk", branch: "main"),
]

Or in Xcode: File → Add Packages…https://github.com/hanzo-swift/sdk.

Quick start (planned)

import Hanzo

let client = HanzoClient(apiKey: ProcessInfo.processInfo.environment["HANZO_API_KEY"]!)

let response = try await client.chat.completions.create(
    model: "zen-omni",
    messages: [.user("Explain quantum computing")]
)
print(response.choices.first?.message.content ?? "")

Meanwhile — raw HTTP

var request = URLRequest(url: URL(string: "https://api.hanzo.ai/v1/chat/completions")!)
request.httpMethod = "POST"
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: [
    "model": "zen-omni",
    "messages": [["role": "user", "content": "Hello"]],
])
let (data, _) = try await URLSession.shared.data(for: request)

Resources

How is this guide?

Last updated on

On this page