Describe the bug
The deserialization code is looking for top-level "code", "message", and "param" properties (which maps to how it's documented in the OpenAI API reference docs). But in the actual JSON OpenAI sends back, those properties are nested on an "error" object.
Steps to reproduce
#pragma warning disable OPENAI001
#pragma warning disable SCME0001
using OpenAI.Responses;
using System.Text;
var client = new OpenAIResponseClient("gpt-4o-mini", Environment.GetEnvironmentVariable("AI:OpenAI:ApiKey"));
string input = string.Join(". ", Enumerable.Repeat("This is a test input that is way too long", 128_000));
await foreach (var update in client.CreateResponseStreamingAsync(input))
{
if (update is StreamingResponseErrorUpdate errorUpdate)
{
Console.WriteLine($"{errorUpdate.Code}: {errorUpdate.Message}");
var data = update.Patch.GetJson("$."u8);
Console.WriteLine(Encoding.UTF8.GetString(data));
}
}
That outputs:
:
{"type":"error","sequence_number":2,"error":{"type":"invalid_request_error","code":"context_length_exceeded","message":"Your input exceeds the context window of this model. Please adjust your input and try again.","param":"input"}}
Code snippets
OS
Windows
.NET version
.NET 10
Library version
2.7.0
Describe the bug
The deserialization code is looking for top-level "code", "message", and "param" properties (which maps to how it's documented in the OpenAI API reference docs). But in the actual JSON OpenAI sends back, those properties are nested on an "error" object.
Steps to reproduce
That outputs:
Code snippets
OS
Windows
.NET version
.NET 10
Library version
2.7.0