Sending picture for OCR error HTTP 400 (invalid_request_error: ) Parameter: purpose ' vision' is not valid

When I a picture to OpenAI using OpenAI C# library, with some pictures I get this error:

Exception: $HTTP 400 (invalid_request_error: )
Parameter: purpose


vision’ is not one of [‘fine-tune’, ‘assistants’, ‘batch’, ‘user_data’, ‘vision’, ‘evals’] - ‘purpose’ | $ at OpenAI.ClientPipelineExtensions.ProcessMessage(ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
at OpenAI.Files.OpenAIFileClient.UploadFile(BinaryContent content, String contentType, RequestOptions options)
at OpenAI.Files.OpenAIFileClient.UploadFile(Stream file, String filename, FileUploadPurpose purpose, CancellationToken cancellationToken)

It seems like it does not recognize the purpose because it has a carriage return in the parameter.

But I am passing the parameter as expected by the library:
var _uploadFile = _fileClient.UploadFile(_stream, fileFS, FileUploadPurpose.Vision);

Maybe the content of the file could raise a bug in the library?

Thankyou.

After some tests, it seems like the C# OpenAI library (or the API, I am not sure), messes up the data in case of some particular filename (the second parameter in UploadFile(_stream, fileName, FileUploadPurpose.Vision);

As of my tests (using the same binary data), passing the filename “picture.jpg” works and the API responds with the OCR executed correctly.

Instead, some other files like:

  • picture.jpeg
  • Picture1Name_3bdf4b12db404692a1f05b0e9b3a103f.jpeg
  • Picture1Name_3bdf4b12db404692a1f05b0e9b3a103f.jpg

cause the unexpected error.

Since the filename is not important for me, I’ll pass always “picture.jpg”.

Thankyou.