Quick setup examples

.NET (HTTP) Quickstart

Call the Unison brain from C# using System.Net.Http.HttpClient and System.Text.Json — no NuGet packages required.

HttpClient and System.Text.Json ship with .NET 6+. The snippets below work as a top-level program (no boilerplate class needed).

Prerequisites

export UNISON_TOKEN=usk_live_...

.NET 6 or later.

Recall — fetch prompt-ready context

using System.Net.Http.Headers;
using System.Text.Json;
using System.Web;

const string Base  = "https://brain.unisonlabs.ai";
string        token = Environment.GetEnvironmentVariable("UNISON_TOKEN")!;

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

var query  = HttpUtility.UrlEncode("payment service architecture");
var url    = $"{Base}/v1/brain/context?q={query}&k=5&mode=auto";
var json   = await http.GetStringAsync(url);

using var doc   = JsonDocument.Parse(json);
var root        = doc.RootElement;
bool weak       = root.GetProperty("weakEvidence").GetBoolean();
string memory   = weak ? "" : root.GetProperty("contextMd").GetString()!;

Console.WriteLine(memory);

System.Web.HttpUtility is available in .NET 6+ via the System.Web namespace without extra packages. On older targets use Uri.EscapeDataString instead.

Persist — write memory to the brain

using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

const string Base  = "https://brain.unisonlabs.ai";
string        token = Environment.GetEnvironmentVariable("UNISON_TOKEN")!;

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

var payload = new
{
    items = new[]
    {
        new
        {
            type  = "conversation",
            turns = new[]
            {
                new { role = "user",      content = "What queue library should we use?" },
                new { role = "assistant", content = "Switched to pgmq — simpler ops than Redis." },
            },
            sourceRef  = "session-1",
            visibility = "private",
        },
    },
};

var body     = JsonSerializer.Serialize(payload);
var content  = new StringContent(body, Encoding.UTF8, "application/json");
var response = await http.PostAsync($"{Base}/v1/brain/ingest", content);
var result   = await response.Content.ReadAsStringAsync();

using var doc = JsonDocument.Parse(result);
string jobId  = doc.RootElement
                   .GetProperty("items")[0]
                   .GetProperty("jobId")
                   .GetString()!;

Console.WriteLine($"jobId: {jobId}");

On this page