Overview
Invoke Supabase Edge Functions from Ruby — per-call control over body, headers, region routing, and response decoding.
The supabase.functions client invokes deployed Edge Functions. A single invoke method that always POSTs, with kwargs for body, headers, region, and how to decode the response. The full surface fits on one page.
First call
require "supabase"
supabase = Supabase.create_client(
ENV.fetch("SUPABASE_URL"),
ENV.fetch("SUPABASE_ANON_KEY")
)
result = supabase.functions.invoke(
"hello-world",
body: { name: "Ada" },
response_type: :json
)
puts result # => { "message" => "Hello, Ada!" }API
| Method | What it does |
|---|---|
functions.invoke(name, body:, headers:, region:, response_type:, return_response:) | Invoke a deployed Edge Function. POSTs <base_url>/<name>; returns the decoded response body. |
Authentication
supabase.functions reuses the bearer token of the umbrella client — sign in via supabase.auth and invoke automatically sends the right Authorization header. To override the bearer for a single call, pass it via headers:; to swap the bearer for every subsequent call on this functions client, use supabase.functions.set_auth(token).
# Per-call override
supabase.functions.invoke(
"hello-world",
headers: { "Authorization" => "Bearer #{custom_jwt}" },
body: { name: "Ada" }
)
# Persistent swap
supabase.functions.set_auth(service_role_jwt)Errors
| Class | Raised when |
|---|---|
Supabase::Functions::Errors::FunctionsHttpError | The function returned a non-2xx response. Carries :status and the parsed message from the response body. |
Supabase::Functions::Errors::FunctionsRelayError | The Supabase relay (in front of the function) signaled failure via the x-relay-error: true response header. |
Supabase::Functions::Errors::FunctionsError | Common base class — rescue this to catch any Functions-API failure. |
Async mode
If the umbrella client was constructed with async: true, supabase.functions.invoke runs on async-http-faraday — call sites should wrap calls in Async do ... end to actually get concurrency. The public method signature is unchanged.
require "supabase"
require "async"
supabase = Supabase.create_client(
ENV.fetch("SUPABASE_URL"),
ENV.fetch("SUPABASE_ANON_KEY"),
async: true
)
Async do |task|
calls = %w[hello-world goodbye-world].map do |name|
task.async { supabase.functions.invoke(name, body: { id: 1 }, response_type: :json) }
end
results = calls.map(&:wait)
results.each { |r| puts r.inspect }
endSee the invoke page for the full signature, every parameter, the response-decoding rules, and a note on streaming.