GradientLabs.Api 0.1.0

dotnet add package GradientLabs.Api --version 0.1.0
                    
NuGet\Install-Package GradientLabs.Api -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GradientLabs.Api" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GradientLabs.Api" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GradientLabs.Api" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GradientLabs.Api --version 0.1.0
                    
#r "nuget: GradientLabs.Api, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GradientLabs.Api@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GradientLabs.Api&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GradientLabs.Api&version=0.1.0
                    
Install as a Cake Tool

GradientLabs.Api

Official C# client library for the Gradient Labs API.

Installation

dotnet add package GradientLabs.Api

Quick start

The API uses two separate key types — Integration and Management. Instantiate one client per key.

using GradientLabs.Api;

// Integration key: conversations, back-office tasks, outbound, voice
using var integration = new GradientLabsIntegrationClient(new GradientLabsClientOptions
{
    ApiKey = Environment.GetEnvironmentVariable("GRADIENT_LABS_INTEGRATION_KEY")!,
});

// Management key: tools, procedures, articles, resources, etc.
using var management = new GradientLabsManagementClient(new GradientLabsClientOptions
{
    ApiKey = Environment.GetEnvironmentVariable("GRADIENT_LABS_MANAGEMENT_KEY")!,
});

// Start a conversation
var conversation = await integration.Conversations.StartAsync(new StartConversationRequest
{
    Id = "conv-001",
    CustomerId = "customer-001",
    Channel = ConversationChannel.Web,
});

// List tools
var tools = await management.Tools.ListAsync();

Configuration

Property Type Default Description
ApiKey string Required. The API key for this client.
BaseUri Uri https://api.gradient-labs.ai Override for local development.
HttpClient HttpClient? null Supply your own; the SDK will not dispose it.
HttpMessageHandler HttpMessageHandler? null Alternative to HttpClient for custom transports.
Timeout TimeSpan? null Applied when the SDK creates its own HttpClient.
WebhookSigningKey string? null Required to call ParseWebhook.
WebhookLeeway TimeSpan 5 minutes Maximum age for accepted webhooks.
TimeProvider TimeProvider System Override in tests.
UserAgentVersion string? Assembly version Override in pre-release builds.

Error handling

try
{
    var conv = await integration.Conversations.ReadAsync("unknown-id");
}
catch (GradientLabsApiException ex) when (ex.ErrorCode == GradientLabsErrorCode.NotFound)
{
    Console.WriteLine($"Not found. Trace: {ex.TraceId}");
}
catch (GradientLabsApiException ex) when (ex.IsRetryable)
{
    // Retry after a delay
}
catch (GradientLabsRequestException ex)
{
    // Transport failure — no response received
}

Webhook verification

var verifier = new GradientLabsWebhookVerifier(signingKey);

// In your ASP.NET Core controller or minimal API:
var body = await Request.BodyReader.ReadAsync();
var signature = Request.Headers["X-GradientLabs-Signature"].ToString();
var token = Request.Headers["X-GradientLabs-Token"].ToString();

WebhookEvent evt;
try
{
    evt = verifier.Parse(body.Buffer.FirstSpan, signature, token);
}
catch (GradientLabsWebhookSignatureException)
{
    return Results.Unauthorized();
}

switch (evt)
{
    case AgentMessageEvent msg:
        Console.WriteLine($"Message from agent: {msg.Body}");
        break;
    case ConversationHandOffEvent ho:
        Console.WriteLine($"Hand-off: {ho.Reason}");
        break;
    case UnknownWebhookEvent unknown:
        Console.WriteLine($"Unknown event type: {unknown.Type}");
        break;
}

Both clients also expose a ParseWebhook convenience method when WebhookSigningKey is set in options.

Pagination

Only Procedures.ListAsync is paginated. All other list methods return the full result.

string? cursor = null;
do
{
    var page = await management.Procedures.ListAsync(cursor: cursor);
    foreach (var p in page.Items)
        Console.WriteLine(p.Name);
    cursor = page.Next;
} while (cursor is not null);

Examples

See examples/ for runnable examples covering conversations, tools, articles, webhooks, procedures, resources, and back-office tasks.

Releasing

Releases are published to NuGet.org automatically when a version tag is pushed to main.

One-time setup (if not already done):

  1. On nuget.org, go to the package → Trusted PublishersAdd trusted publisher.
  2. Select GitHub Actions and fill in owner gradientlabs-ai, repository gradientlabs-dotnet, workflow publish.yml, policy name gradientlabs-dotnet-publish.

To publish a new version:

  1. Merge all changes into main.
  2. Push a version tag:
    git tag v1.2.3
    git push origin v1.2.3
    
  3. The publish workflow runs automatically: it packs the library and pushes the .nupkg to NuGet.org using the tag as the package version.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 58 6/22/2026