Skip to content

[BUG] GetContainerFileAsync throws InvalidOperationException #733

@didrh

Description

@didrh

Describe the bug

When calling GetContainerFileAsync with a valid container id and file id i get this Error:

System.InvalidOperationException: 'The requested operation requires an element of type 'Number', but the target element has type 'Null'.' at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType) at System.Text.Json.JsonElement.GetInt32() at OpenAI.Containers.ContainerFileResource.DeserializeContainerFileResource(JsonElement element, ModelReaderWriterOptions options) at OpenAI.Containers.ContainerFileResource.op_Explicit(ClientResult result) at OpenAI.Containers.ContainerClient.<GetContainerFileAsync>d__38.MoveNext()

Steps to reproduce

  1. Call Code Intepreter to Generate a File
  2. Wait for the StreamingResponseTextAnnotationAddedUpdate
  3. Try to get the File form the Container (Getting FileContent works fine)

Code snippets

OpenAIResponseClient client = new(model: "gpt-4.1", apiKey: "[API KEY]");
ContainerClient containerClient = new(apiKey: "[API KEY]");


var rco = new ResponseCreationOptions()
{
    Tools = { CodeInterpreterTool.CreateCodeInterpreterTool(new CodeInterpreterToolContainer(CodeInterpreterToolContainerConfiguration.CreateAutomaticContainerConfiguration(new List<string>()))) }
};

await foreach (StreamingResponseUpdate update in client.CreateResponseStreamingAsync("Generate an Excel with 3 columns. Ue generic data", rco))
{
    if (update is StreamingResponseOutputTextDeltaUpdate delta)
    {
        Console.Write(delta.Delta);
    }
    else if(update is StreamingResponseTextAnnotationAddedUpdate textAnnotationUpdate)
    {
        var annotation = JsonSerializer.Deserialize<ContainerFileCitation>(textAnnotationUpdate.Annotation, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
        if (annotation.Type != "container_file_citation")
        {
            continue;
        }

        var containerdata = await containerClient.GetContainerFileContentAsync(annotation.ContainerId, annotation.FileId); //this works
        var containerfile = await containerClient.GetContainerFileAsync(annotation.ContainerId, annotation.FileId); //this throws error
    }
}

OS

Windows

.NET version

.NET 8

Library version

2.5.0

Metadata

Metadata

Assignees

Labels

area: serviceThis issue is an inquiry about a bug in the OpenAI service or requesting a new service feature.questionCategory: The issue is seeking information about the library or its usage.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions