Grafana.Agento11y.OpenAI 0.4.0

Prefix Reserved
dotnet add package Grafana.Agento11y.OpenAI --version 0.4.0
                    
NuGet\Install-Package Grafana.Agento11y.OpenAI -Version 0.4.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="Grafana.Agento11y.OpenAI" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Grafana.Agento11y.OpenAI" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="Grafana.Agento11y.OpenAI" />
                    
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 Grafana.Agento11y.OpenAI --version 0.4.0
                    
#r "nuget: Grafana.Agento11y.OpenAI, 0.4.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 Grafana.Agento11y.OpenAI@0.4.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=Grafana.Agento11y.OpenAI&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=Grafana.Agento11y.OpenAI&version=0.4.0
                    
Install as a Cake Tool

Grafana.Agento11y.OpenAI

OpenAI instrumentation helpers for Grafana.Agento11y with strict official OpenAI .NET SDK types for both:

  • Chat Completions
  • Responses

Integration styles

  • Strict wrappers: call OpenAI and record in one step.
  • Manual instrumentation: call OpenAI directly, then map strict OpenAI request/response payloads with OpenAIGenerationMapper.

Public API

  • Wrappers:
    • OpenAIRecorder.CompleteChatAsync(...)
    • OpenAIRecorder.CompleteChatStreamingAsync(...)
    • OpenAIRecorder.CreateResponseAsync(...)
    • OpenAIRecorder.CreateResponseStreamingAsync(...)
    • OpenAIRecorder.GenerateEmbeddingsAsync(...)
  • Mappers:
    • OpenAIGenerationMapper.ChatCompletionsFromRequestResponse(...)
    • OpenAIGenerationMapper.ChatCompletionsFromStream(...)
    • OpenAIGenerationMapper.ResponsesFromRequestResponse(...)
    • OpenAIGenerationMapper.ResponsesFromStream(...)
    • OpenAIGenerationMapper.EmbeddingsFromRequestResponse(...)

Install

dotnet add package Grafana.Agento11y
dotnet add package Grafana.Agento11y.OpenAI
dotnet add package OpenAI

Responses Wrapper (Sync)

using Grafana.Agento11y;
using Grafana.Agento11y.OpenAI;
using OpenAI.Responses;

var agento11yConfig = new Agento11yClientConfig
{
    GenerationExport = new GenerationExportConfig
    {
        Protocol = GenerationExportProtocol.Http,
        Endpoint = "https://sigil-prod-<region>.grafana.net",
        Auth = new AuthConfig
        {
            Mode = ExportAuthMode.Basic,
            TenantId = Environment.GetEnvironmentVariable("AGENTO11Y_AUTH_TENANT_ID"),
            BasicPassword = Environment.GetEnvironmentVariable("AGENTO11Y_AUTH_TOKEN"),
        },
    },
    Api = new ApiConfig
    {
        Endpoint = "https://sigil-prod-<region>.grafana.net",
    },
};
var agento11y = new Agento11yClient(agento11yConfig);

var responsesClient = new ResponsesClient(
    "gpt-5",
    Environment.GetEnvironmentVariable("OPENAI_API_KEY")!
);

var inputItems = new List<ResponseItem>
{
    ResponseItem.CreateUserMessageItem("What's the weather in Paris?"),
};

var requestOptions = new CreateResponseOptions
{
    Instructions = "You are concise.",
    MaxOutputTokenCount = 320,
};

ResponseResult response = await OpenAIRecorder.CreateResponseAsync(
    agento11y,
    responsesClient,
    inputItems,
    requestOptions: requestOptions,
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-openai-responses-1",
        AgentName = "assistant-core",
        AgentVersion = "1.0.0",
    },
    cancellationToken: CancellationToken.None
);

Responses Wrapper (Stream)

OpenAIResponsesStreamSummary summary = await OpenAIRecorder.CreateResponseStreamingAsync(
    agento11y,
    responsesClient,
    inputItems,
    requestOptions: requestOptions,
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-openai-responses-stream-1",
        AgentName = "assistant-core",
        AgentVersion = "1.0.0",
    },
    cancellationToken: CancellationToken.None
);

foreach (var evt in summary.Events)
{
    // Inspect raw stream events if needed.
}

Chat Completions Wrapper (Sync)

using OpenAI.Chat;

var chatClient = new ChatClient(
    "gpt-5",
    Environment.GetEnvironmentVariable("OPENAI_API_KEY")!
);

var messages = new List<ChatMessage>
{
    new SystemChatMessage("You are concise."),
    new UserChatMessage("What's the weather in Paris?"),
};

ChatCompletion chat = await OpenAIRecorder.CompleteChatAsync(
    agento11y,
    chatClient,
    messages,
    requestOptions: null,
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-openai-chat-1",
        AgentName = "assistant-core",
        AgentVersion = "1.0.0",
    },
    cancellationToken: CancellationToken.None
);

Chat Completions Wrapper (Stream)

OpenAIChatCompletionsStreamSummary streamSummary = await OpenAIRecorder.CompleteChatStreamingAsync(
    agento11y,
    chatClient,
    messages,
    requestOptions: null,
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-openai-chat-stream-1",
        AgentName = "assistant-core",
        AgentVersion = "1.0.0",
    },
    cancellationToken: CancellationToken.None
);

Embeddings Wrapper

using OpenAI.Embeddings;

OpenAIEmbeddingCollection embeddingResponse = await OpenAIRecorder.GenerateEmbeddingsAsync(
    agento11y,
    new EmbeddingClient(Environment.GetEnvironmentVariable("OPENAI_API_KEY")!),
    new[] { "hello", "world" },
    requestOptions: new EmbeddingGenerationOptions { Dimensions = 256 },
    options: new OpenAIAgento11yOptions
    {
        ConversationId = "conv-openai-embeddings-1",
        AgentName = "assistant-core",
        AgentVersion = "1.0.0",
        ModelName = "text-embedding-3-small",
    },
    cancellationToken: CancellationToken.None
);

Manual instrumentation example (strict mapper)

var agento11yOptions = new OpenAIAgento11yOptions
{
    ConversationId = "conv-openai-manual-1",
    AgentName = "assistant-core",
    AgentVersion = "1.0.0",
};

var recorder = agento11y.StartGeneration(new GenerationStart
{
    ConversationId = agento11yOptions.ConversationId,
    AgentName = agento11yOptions.AgentName,
    AgentVersion = agento11yOptions.AgentVersion,
    Model = new ModelRef { Provider = "openai", Name = "gpt-5" },
});

try
{
    ResponseResult response = await responsesClient.CreateResponseAsync(
        inputItems,
        requestOptions,
        CancellationToken.None
    );

    recorder.SetResult(OpenAIGenerationMapper.ResponsesFromRequestResponse(
        "gpt-5",
        inputItems,
        requestOptions,
        response,
        agento11yOptions
    ));
}
catch (Exception ex)
{
    recorder.SetCallError(ex);
    throw;
}
finally
{
    recorder.End();
}

Raw Artifacts (Debug Opt-In)

Raw provider request/response/tools/stream-events artifacts are disabled by default.

var agento11yOptions = new OpenAIAgento11yOptions
{
    ConversationId = "conv-openai-debug-1",
    AgentName = "assistant-core",
    AgentVersion = "1.0.0",
}.WithRawArtifacts();

Delegate Overloads

All wrappers also provide delegate overloads so you can inject custom retry/transport/test-double behavior while keeping Sigil recording intact.

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 is compatible.  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.

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.4.0 83 7/21/2026