Skip to documentation
Open Workflow Studio
On this page

.NET SDK

Documentation | SDK samples | API and persistence reference

Use the Benchius SDK to run the same workflow definition inside your application, through your own HTTP service, or against a remote control plane. The libraries and runnable samples target .NET 11.

Choose an integration boundary

Your application needs Integration What your application owns
Local execution, batch processing, or disconnected business rules Benchius.Runtime Engine lifetime, cancellation, input, credentials, and runtime services
Remote workflows, sequenced events, human input, or shared libraries Benchius.Client The endpoint, API workspace key, request identity, and explicit run cancellation
A local HTTP API for .NET and other languages Benchius.AspNetCore Authentication configuration, private storage, Data Protection keys, and host lifetime
Visual workflow authoring inside a Blazor application Source-hosted WorkflowComposerWorkspace The application shell, editor session, workflow handoff, persistence, and execution

WorkflowDefinition is shared across these boundaries. A graph authored in Workflow Studio can be validated and executed with the runtime or submitted through the HTTP client.

Run a workflow in process

Reference sdk\Benchius.Runtime\Benchius.Runtime.csproj from a source-checkout application, or package it with the commands in the control-plane guide.

using AspireDemo.Workflows;
using Benchius;

var definition = WorkflowJson.Deserialize(
    await File.ReadAllTextAsync("workflow.json", cancellationToken));
using var engine = new BenchiusEngine();
var issues = engine.Validate(definition);
if (issues.Count > 0)
    throw new InvalidOperationException(string.Join(" ", issues.Select(issue => issue.Message)));

await foreach (var item in engine.RunAsync(new()
{
    Definition = definition,
    Input = definition.PreviewInput
}, cancellationToken: cancellationToken))
{
    Console.WriteLine($"{item.Kind}: {item.Message}");
}

Expressions, variables, conditions, loops, and cached data run disconnected. Model calls, MCP, REST, cloud resources, and provider-dependent tools require their configured services. Supply human-input sessions, budget controls, data stores, media processors, and approved JIT implementations through the runtime APIs as needed.

Inspect the terminal event. A Failed or Cancelled event is an explicit execution outcome. The offline purchase-policy sample demonstrates a complete local run with typed receipts.

Connect through HTTP

Reference Benchius.Client and configure BENCHIUS_API_KEY and, optionally, BENCHIUS_ENDPOINT. The default endpoint is https://benchius.com/.

using Benchius;

using var client = new BenchiusClient();
var started = await client.Workflows.StartAsync(new()
{
    Definition = definition,
    Input = "Synthetic support request",
    IdempotencyKey = "application-request-204"
}, cancellationToken);

long observedSequence = 0;
await foreach (var item in client.Workflows.WatchAsync(
    started.Id, after: observedSequence, cancellationToken: cancellationToken))
{
    observedSequence = item.Sequence;
    Console.WriteLine($"{item.Sequence}: {item.Kind}");
}

Persist the last observed sequence if your application needs to reconnect. Answer human input using the exact pending request ID. Disconnecting a stream leaves server execution active; use CancelAsync when your application intends to stop the run. Idempotency reuses a retained run only when its request is unchanged.

The public free-tier key shares one API workspace among its callers. Configure a private key for private documents, credentials, and results. Model-provider credentials are separate caller-owned bindings. See authentication and OpenAPI.

Embed Workflow Studio

Standalone Workflow Studio with a host-provided purchase-policy graph and an SDK execution action

The HostedDesigner sample renders a minimal Blazor root with the Studio pane. Its root owns the HTML document, styles, router, and framework scripts. The host can place the same component inside its existing layout or a same-origin frame.

The editor is currently a source-hosted component from AspireDemo.Web. Reference that project and preserve BenchiusDesignerHost=true when building the sample. BenchiusWebFrontEnd.Create<TApp> reuses the configured frontend services and API integration while allowing the application to provide its own root component. The sample's root includes the frontend's routes so model-configuration frames continue to work.

@using AspireDemo
@using AspireDemo.WorkflowComponents
@using AspireDemo.Workflows
@implements IDisposable

<WorkflowComposerWorkspace @key="session" Session="@session"
                           OnSave="AcceptWorkflowAsync" SaveLabel="Use workflow"
                           ShowLibrary="false" ShowPackaging="false"
                           ShowAutomations="false" ShowChat="false" />

@code {
    private readonly WorkflowComposerSession session = new();

    protected override void OnInitialized()
    {
        session.Replace(initialDefinition);
        session.PreviewInput = initialInput;
        session.MarkSaved();
    }

    private Task AcceptWorkflowAsync(WorkflowDefinition document) =>
        applicationWorkflows.SaveAsync(document);

    public void Dispose() => session.Dispose();
}

In this excerpt, initialDefinition, initialInput, and applicationWorkflows are supplied by the embedding application. The callback receives an independent graph snapshot with its Preview input. It applies pending editor settings and validates the graph before the handoff. Runtime credential dictionaries and preview runs remain in the editor session. The application supplies execution credentials separately.

Parameter Host integration
Session Supply the editable graph, Preview input, resource limits, and session-scoped preview credentials before rendering
OnSave Receive the validated WorkflowDefinition to persist, publish, or execute
SaveLabel Name the application's workflow-handoff action
ShowLibrary Control the Studio's browser-library UI
ShowPackaging Control package-generation actions
ShowAutomations Control persistent-schedule UI
ShowChat Control AI-assisted authoring UI
HostContent Display application-owned status or results within the Studio pane

Use @key to remount the editor when replacing its session. Dispose sessions and cancel application-owned work when closing the editor. If a handoff fails, throw an actionable exception; the Studio displays the error and retains the unsaved state. A successful callback marks the handed-off snapshot as accepted.

Continue to enforce authorization, allowed operations, credentials, and execution limits in your host. UI visibility parameters configure presentation. The checked-in sample uses its own minimal root and leaves the website's navigation, consent dialog, notification host, and deployment monitor outside that root.

Explore contracts and synthetic requests

OpenAPI explorer showing an editable synthetic request and request and response contracts

Open /openapi on the control-plane host. The viewer loads the OpenAPI contract anonymously, supports operation and schema searches, and links request/response references to their component definitions.

Expand an operation, inspect its parameters, and choose Load synthetic request. Local examples cover graph validation, expression evaluation, workflow starts, parallel comparisons, library documents, and matching vector spaces. Schema-derived starter bodies cover the remaining interfaces and require review for operation-specific prerequisites.

The execution field starts with the host's configured free-tier API key when public access is enabled. Replace it with a private workspace key before using private data. Operations that can change data require explicit authorization in the form. The explorer displays the HTTP request with its API key redacted, actual status and duration, response headers, JSON, incremental events, and downloadable binary responses. Reading is bounded; larger downloads belong in the SDK or a native HTTP client.

After starting a run or creating a document, load synthetic parameters in a related operation to reuse the observed run ID, document ID, or revision. Use the same synthetic collection name for vector upsert, search, and explicit deletion. Keep synthetic exercises in a dedicated API workspace.

Storage and production boundaries

Runs, checkpoints, and retained media belong to the hosting process and its retention window. Library documents use encrypted private storage. Persist both that storage and Data Protection keys for restart-safe access. Plan durable dispatch and shared state before scaling execution across instances.

The control-plane reference documents feature coverage, provider credentials, packages, persistence, and client regeneration. The SDK samples provide complete applications for each integration boundary.

An unhandled error has occurred. Reload 🗙