TenancyEngine/ docs

SDKs

Two .NET packages wrap the runtime API so you don't hand-roll HttpClient calls. Both are built from real source in this repo and verified to build and pass tests. Five more languages (Go, Java, PHP, Python, and Ruby) have complete client implementations in source today; see Other languages below for their current status.

Publish status. TenancyEngine.Sdk is published to the GitHub Packages feed (current version 1.0.1, matching source). Install it with the command below. TenancyEngine.SaaSRuntime.Client is also on the feed, but at an older version (0.1.0) than the current source (0.1.3). Install the version below and note that newer public types land only once 0.1.3 is pushed.

API key tiers

Every organization API key is one of three tiers. Pick the narrowest one that does the job. It's the single biggest lever you have over a leaked key's blast radius.

TierScopeUse it when…
Org-wide Works across every application your organization owns. You're an ISV managing multiple TenancyEngine apps from one backend (shared billing/ops service, internal tooling) and genuinely need cross-app reach.
App-scoped Bound server-side to exactly one application. URLs are unchanged. You still address the application by slug/id, but the platform rejects the key outright for every other application, regardless of what scopes it holds. The common case: a single app's own backend calling its own runtime APIs. Smaller blast radius if the key ever leaks.
Admin scopes The reserved admin scope (and any future admin.*-prefixed scope): organization-administration operations such as managing other API keys. Only an org-wide key may ever hold an admin scope; the platform rejects an attempt to grant one to an app-scoped key at creation time, unconditionally. Platform/ISV-admin tooling only, never a single app's own runtime integration.

Create keys in TE Console under API keys: choose org-wide or bind to one application, and add an optional caller-IP/CIDR allowlist (blank = no restriction, the default). An app-scoped key can only pick from non-admin scopes. The admin-scope checkboxes are disabled the moment an application is selected.

TenancyEngine.Sdk

A minimal client for the runtime and analytics API, plus webhook signature verification. No dependencies beyond the .NET base class library.

dotnet add package TenancyEngine.Sdk --version 2.9.0

Usage

using TenancyEngine.Sdk;
using TenancyEngine.Sdk.Environments;

var builder = WebApplication.CreateBuilder(args);

// Pick the lane (production unless you ask for another), then read the key for that lane. The host's own environment name decides
// whether this is a development machine; never hard-code "Development", or a deployment of this code would count as one.
var lane = builder.Configuration.AddTenancyEngineEnvironment(builder.Environment.EnvironmentName);
var key = LaneApiKey.FromEnvironment(lane);   // TENANCYENGINE_API_KEY_LAB on lab; production also accepts TENANCYENGINE_API_KEY
using var http = TenancyEngineClient.CreateLaneHttpClient(lane);
var client = TenancyEngineClient.ForLane(http, key);

// Look up your application.
var app = await client.GetApplicationAsync("your-app-slug");

// Fetch a tenant's runtime context (features, roles, claims, offerings) in one call.
var context = await client.GetRuntimeContextAsync("your-app-slug", environment: "Production", tenantId: null);

// Meter usage against a tenant's plan.
var result = await client.ConsumeUsageAsync(
    applicationSlug: "your-app-slug",
    tenantSlug: "acme-corp",
    environment: "Production",
    featureKey: "exports_per_month",
    amount: 1,
    idempotencyKey: Guid.NewGuid().ToString());

// Record an analytics event.
await client.TrackEventAsync(new AnalyticsEvent(
    EventName: "report.generated",
    ApplicationId: app!.Id,
    TenantId: null,
    UserId: null,
    Properties: null,
    OccurredAtUtc: DateTimeOffset.UtcNow));

App-scoped vs org-wide client

using TenancyEngine.Sdk;

// Org-wide key: works across every application the org owns.
var orgWide = new TenancyEngineClient(http, apiKey: orgWideKey);

// App-scoped key: bound to one application. Every call's applicationSlug/applicationId argument
// is checked against this up front — a clear client-side error instead of waiting for the
// platform's own 403.
var appScoped = TenancyEngineClient.ForApplication(http, apiKey: appScopedKey, applicationSlug: "your-app-slug");
await appScoped.GetApplicationAsync("your-app-slug"); // OK
await appScoped.GetApplicationAsync("someone-elses-app"); // throws InvalidOperationException, no request sent

Webhook signature verification

using TenancyEngine.Sdk;

// rawPayload = the exact request body bytes as a string; signatureHeader = the
// X-TenancyEngine-Signature header value; secret = your webhook's signing secret from TE Console.
if (!WebhookSignatureVerifier.Verify(rawPayload, signatureHeader, secret))
{
    return Results.Unauthorized();
}

TenancyEngine.SaaSRuntime.Client

A dependency-injection-friendly typed client (ISaaSRuntimeClient) covering the same runtime surface plus storage grants and import proxying, the shared package extracted from StudioDash/StatusBeacon/VectraLabel's own hand-rolled clients, so adopting it replaces a per-app AddHttpClient<SaaSRuntimeClient>(...) registration.

dotnet add package TenancyEngine.SaaSRuntime.Client --version 0.1.0

Register it

using TenancyEngine.SaaSRuntime.Client;

builder.Services.AddSaaSRuntimeClient(builder.Configuration);
// reads SaaSRuntime:ApiBaseUrl and SaaSRuntime:ApiKey from configuration
{
  "SaaSRuntime": {
    "ApiBaseUrl": "https://auth.saasruntime.com",
    "ApiKey": "te_your_key_here"
  }
}

Usage

using TenancyEngine.SaaSRuntime.Client;

public sealed class MyFeatureGate(ISaaSRuntimeClient runtime)
{
    public async Task<bool> CanExportAsync(Guid applicationId, string tenantSlug)
    {
        var context = await runtime.GetRuntimeContextAsync("your-app-slug", "Production");
        return context?.Features.Contains("exports") == true;
    }
}

Other languages

Go, Java, PHP, Python, and Ruby clients exist as complete, real source in the tenancyengine repo under packages/tenancyengine-{go,java,php,python,ruby}/: each with its own tests, README, and package metadata (module path / pom.xml / composer.json / pyproject.toml / gemspec) already filled in for a real release.

Publish status. None of the five are on a public registry yet (Go module proxy, Maven Central, Packagist, PyPI, RubyGems). That is a one-time, credentialed, human action for each registry, the same category of step as the GitHub Packages pushes for the .NET SDKs above. Until then, install directly from source (each SDK's own README documents the local build/install steps for its language). Track publish status per registry before depending on a package name that doesn't exist yet.

For any language without an SDK at all (or if you'd rather not add a dependency), every runtime endpoint is a plain HTTP call with an X-TenancyEngine-Api-Key header. See Authentication for the mechanism and API reference for every route.

// A production key; a lab or staging key lives in TENANCYENGINE_API_KEY_LAB / TENANCYENGINE_API_KEY_STAGING and is sent only there.
const res = await fetch("https://auth.saasruntime.com/api/v1/runtime/applications/your-app-slug", {
  headers: { "X-TenancyEngine-Api-Key": process.env.TENANCYENGINE_API_KEY! },
});
if (!res.ok) throw new Error(`TenancyEngine API ${res.status}`);
const application = await res.json();

Source