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.
Initializing a new client is pretty straightforward. Find your project url and public key from the admin panel and pass it into your client initialization function.
Supabase is heavily dependent on Models deriving from BaseModel. To interact with the API, one must have the associated model (see example) specified.
Leverage Table, PrimaryKey, and Column attributes to specify names of classes/properties that are different from their C# Versions.
AddSupabase() from the Supabase.Extensions.DependencyInjection package. For other apps (console, desktop, mobile, Unity), create a Supabase.Client yourself, call InitializeAsync(), and reuse it. A new client per operation means a new HttpClient (and socket) each time.AddSupabase() registers a scoped Supabase.Client, and each sub-client individually: IGotrueClient<User, Session>, IPostgrestClient, IStorageClient<Bucket, FileObject>, IFunctionsClient, and IRealtimeClient<RealtimeSocket, RealtimeChannel>. Inject only the one a class needs.Client, with its own Auth state. In ASP.NET Core a scope is one request. In Blazor Server it is one circuit, and in Blazor WebAssembly it lasts as long as the app runs.HttpClients from IHttpClientFactory. Without the extension, a scoped or transient Client builds a new HttpClient per resolution, which exhausts the connection pool under load. AddSupabase() sets SupabaseOptions.HttpClient and the three StorageClientOptions HTTP clients (HttpRequestClient, HttpUploadClient, HttpDownloadClient) itself, so values you set for those in configureOptions are replaced. Everything else you set stays, including Proxy, StorageClientOptions.Proxy, the Storage timeouts, and the retry options such as PostgrestRetry.AddSupabase() does not call InitializeAsync() on the client it creates. AutoConnectRealtime and restoring a persisted session only happen in InitializeAsync(), so call it yourself if you rely on either. Subscribe() on a Realtime channel connects the socket on its own.ILoggerFactory is registered in the service provider and you did not set SupabaseOptions.LoggerFactory, the client uses it.System.Diagnostics and propagates trace context. See client-side tracing.SupabaseOptions.ThirdPartyAccessToken authenticates the client through a third-party auth provider instead of Supabase Auth.var url = Environment.GetEnvironmentVariable("SUPABASE_URL");
var key = Environment.GetEnvironmentVariable("SUPABASE_KEY");
var options = new Supabase.SupabaseOptions
{
AutoConnectRealtime = true
};
var supabase = new Supabase.Client(url, key, options);
await supabase.InitializeAsync();
using Supabase.Core.Http;
using Supabase.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSupabase(
supabaseUrl: builder.Configuration["Supabase:Url"]!,
supabaseKey: builder.Configuration["Supabase:Key"]!,
configureOptions: options =>
{
options.AutoConnectRealtime = true;
options.PostgrestRetry = new RetryOptions { MaxRetries = 3 };
});
var app = builder.Build();
app.MapGet("/todos", async (Supabase.Client supabase) =>
{
var result = await supabase.From<Todo>().Get();
return result.Models;
});
public class TodoService
{
private readonly Supabase.Client _supabase;
public TodoService(Supabase.Client supabase) => _supabase = supabase;
public async Task<List<Todo>> GetOpen()
{
var result = await _supabase
.From<Todo>()
.Where(t => t.IsComplete == false)
.Get();
return result.Models;
}
}
app.MapGet("/todos", async (IPostgrestClient postgrest) =>
await postgrest.Table<Todo>().Get());
app.MapGet("/todos", async (Supabase.Client supabase) =>
{
await supabase.InitializeAsync();
var result = await supabase.From<Todo>().Get();
return result.Models;
});
@page "/todos"
@using Supabase
@inject Client SupabaseClient
<ul>
@foreach (var todo in _todos)
{
<li>@todo.Task</li>
}
</ul>
@code {
private List<Todo> _todos = new();
protected override async Task OnInitializedAsync()
{
var result = await SupabaseClient.From<Todo>().Get();
_todos = result.Models;
}
}
public static MauiApp CreateMauiApp()
{
// ...
var builder = MauiApp.CreateBuilder();
var url = Environment.GetEnvironmentVariable("SUPABASE_URL");
var key = Environment.GetEnvironmentVariable("SUPABASE_KEY");
var options = new SupabaseOptions
{
AutoRefreshToken = true,
AutoConnectRealtime = true,
// SessionHandler = new SupabaseSessionHandler() <-- This must be implemented by the developer
};
// Note the creation as a singleton.
builder.Services.AddSingleton(provider => new Supabase.Client(url, key, options));
}
var options = new Supabase.SupabaseOptions
{
SessionHandler = new MySessionHandler() // Implements IGotrueSessionPersistence<Session>
};
var supabase = new Supabase.Client(url, key, options);
await supabase.InitializeAsync();
var options = new Supabase.SupabaseOptions
{
AuthFlowType = Supabase.Gotrue.Constants.OAuthFlowType.PKCE
};
var supabase = new Supabase.Client(url, key, options);
var options = new Supabase.SupabaseOptions
{
LoggerFactory = loggerFactory
};
var supabase = new Supabase.Client(url, key, options);
var options = new Supabase.SupabaseOptions
{
HttpClient = new HttpClient(new MyLoggingHandler())
};
var supabase = new Supabase.Client(url, key, options);
var options = new Supabase.SupabaseOptions
{
TracePropagation = Supabase.Core.Http.TracePropagation.Disabled
};
var supabase = new Supabase.Client(url, key, options);
// Given the following Model representing the Supabase Database (Message.cs)
[Table("messages")]
public class Message : BaseModel
{
[PrimaryKey("id")]
public int Id { get; set; }
[Column("username")]
public string UserName { get; set; }
[Column("channel_id")]
public int ChannelId { get; set; }
public override bool Equals(object obj)
{
return obj is Message message &&
Id == message.Id;
}
public override int GetHashCode()
{
return HashCode.Combine(Id);
}
}
// Get All Messages
var response = await supabase.From<Message>().Get();
List<Message> models = response.Models;
// Insert
var newMessage = new Message { UserName = "acupofjose", ChannelId = 1 };
await supabase.From<Message>().Insert(newMessage);
// Update
var model = response.Models.First();
model.UserName = "elrhomariyounes";
await model.Update<Message>();
// Delete
await response.Models.Last().Delete<Message>();
// etc.