For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.

Swift: Invoke a Supabase Edge Function and stream the response

Invoke a Supabase Edge Function and read the response body as it arrives. Use it for text/event-stream responses and large downloads.

Examples

Invocation with streamed response

let response = try await supabase.functions.stream(
  "hello",
  body: .json(["foo": "bar"])
)

// Write each chunk to a file, so memory use stays small.
let fileURL = FileManager.default.temporaryDirectory
  .appendingPathComponent("hello-response")
FileManager.default.createFile(atPath: fileURL.path, contents: nil)
let file = try FileHandle(forWritingTo: fileURL)
defer { try? file.close() }

for try await chunk in response.body {
  try file.write(contentsOf: chunk)
}