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.xrelease.
dotnet add package Openlayerusing 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; });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),
});Non-2xx responses throw Microsoft.Kiota.Abstractions.ApiException; ResponseStatusCode holds the HTTP status. A missing API key throws Openlayer.OpenlayerException.
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.NET 8+ or any netstandard2.0 runtime. Building needs the .NET 10 SDK (Kiota runs on it).
Apache-2.0