Skip to content

About

The official C# / .NET library for Openlayer, the Evaluation Platform for AI. πŸ“ˆ

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Openlayer C# / .NET library

The official C# / .NET library for the Openlayer REST API β€” the Evaluation Platform for AI.

Targets net8.0 and netstandard2.0 (so .NET Framework 4.6.2+ works too).

Preview. This SDK is pre-1.0. Its API layer is generated from the Openlayer OpenAPI spec, and class and method names can change in any 0.x release.

Install

dotnet add package Openlayer

Usage

using Openlayer;
using Openlayer.Api.InferencePipelines.Item.DataStream;
using Openlayer.Api.Models;

var client = new OpenlayerClient(); // reads OPENLAYER_API_KEY

var response = await client.InferencePipelines[pipelineId].DataStream.PostAsync(new DataStreamPostRequestBody
{
    Config = new DataStreamPostRequestBody.DataStreamPostRequestBody_config
    {
        LLMData = new LLMData
        {
            InputVariableNames = new() { "user_query" },
            OutputColumnName = "output",
            NumOfTokenColumnName = "tokens",
            CostColumnName = "cost",
            TimestampColumnName = "timestamp",
        },
    },
    Rows = new()
    {
        new DataStreamPostRequestBody_rows
        {
            AdditionalData = new Dictionary<string, object>
            {
                ["user_query"] = "what is the meaning of life?",
                ["output"] = "42",
                ["tokens"] = 7,
                ["cost"] = 0.02,
                ["timestamp"] = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
            },
        },
    },
});

The full example is in examples/StreamData.

The client is a tree that follows the REST paths:

REST C#
GET /projects client.Projects.GetAsync()
POST /projects client.Projects.PostAsync(project)
GET /projects/{id}/inference-pipelines client.Projects[id].InferencePipelines.GetAsync()
GET /inference-pipelines/{id} client.InferencePipelines[id].GetAsync()
POST /inference-pipelines/{id}/data-stream client.InferencePipelines[id].DataStream.PostAsync(body)
GET /versions/{id}/results client.Versions[id].Results.GetAsync()

Query parameters go in the configuration callback:

var page = await client.Projects.GetAsync(c => { c.QueryParameters.Name = "churn"; c.QueryParameters.PerPage = 50; });

Configuration

Option (OpenlayerClientOptions) Environment variable Default
ApiKey OPENLAYER_API_KEY β€” (required)
BaseUrl OPENLAYER_BASE_URL https://api.openlayer.com/v1
Timeout 60 seconds
HttpClient Kiota's default handler chain: retries with backoff on 429/503/504, redirects, compression
var client = new OpenlayerClient(new OpenlayerClientOptions
{
    ApiKey = "...",
    BaseUrl = "https://openlayer.example.com/v1", // on-prem
    Timeout = TimeSpan.FromSeconds(30),
});

Errors

Non-2xx responses throw Microsoft.Kiota.Abstractions.ApiException; ResponseStatusCode holds the HTTP status. A missing API key throws Openlayer.OpenlayerException.

How this SDK is built

The API layer under src/Openlayer/Generated is generated by Kiota from the Openlayer OpenAPI spec. Do not edit it by hand β€” every spec change overwrites the whole folder. Everything else (the OpenlayerClient wrapper, tests, examples) is hand-written.

scripts/generate path/to/openapi.yaml   # regenerate (CI does this on every spec change)
dotnet test tests/Openlayer.Tests       # unit tests
scripts/parity                          # same requests as the Python SDK, byte for byte
scripts/parity --live                   # same results as the Python SDK against a real backend

Requirements

.NET 8+ or any netstandard2.0 runtime. Building needs the .NET 10 SDK (Kiota runs on it).

License

Apache-2.0

About

The official C# / .NET library for Openlayer, the Evaluation Platform for AI. πŸ“ˆ

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages