#Issues with the https://api.openai.com/v1/files endpoint

1 messages · Page 1 of 1 (latest)

wooden crown
#

I am currently working with the APIs regarding file search. I have gotten every endpoint to work (Currently coding in C#) but when I go to upload a file using the API, I get a 413 Error saying the request size is too large for the server. The PDF I am sending is only 9mb, and I have successfully sent this exact pdf before and extracted information using file search with the Python SDK. If need be, I will write python scripts to do this separately from my sites server, but because my site is written in .Net Core I would prefer to keep it in that language.

I was wondering if anyone has run into this issue when reaching the APIs without the Node or Python SDKs, I find it odd there is no issue sending a file of this size with python but I cannot in C#. I went through the library on Github and didn't see anything they were doing differently to the file before sending to the API apart from some deep_copy and extract_files mapping.

I am also primarily a JS and C# developer and am nowhere near as well versed in python, though I know enough to get by. If noone has run into this issue, would you know if anything is happening with those 2 functions that I could try to implement in C#? (deep_copy and extract_files) here is a snippet from the repo to see

body = deepcopy_minimal(
{
"file": file,
"purpose": purpose,
}
)
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])

Any help is appreciated! Thanks

fossil ivy
wooden crown
#

Sure here is a code snippet with my call @fossil ivy -

using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://api.openai.com/v1");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", uploadApiKey);

using (var content = new MultipartFormDataContent())
{
    content.Add(new StringContent("assistants"), "purpose");

    var fileStream = File.OpenRead(filePath);
    var fileStreamContent = new StreamContent(fileStream);
    //fileStreamContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data");
    content.Add(fileStreamContent, "file", Path.GetFileName(filePath));

    var response = await client.PostAsync("files", content);
    var responseContent = await response.Content.ReadAsStringAsync();

    return responseContent;
}

}

fossil ivy
wooden crown
#

I appreciate the response but I have 15 other API calls in the file that all work the same way, and are successful in their calls,
this call reaches the server as well, that's why I am getting the error I am, and not a 404. The issue (I believe) is server side
This is .Net Core 8 btw, but again thanks for trying to help!

fossil ivy
#

.net core no longer exists so i though you were using < .net 6 which had issue how those were placed 🙂

wooden crown
#

You are absolutely right, It is .Net 8, not core wasn't trying to sound mean coolcat

fossil ivy
#

what is the request size or form if you trace it or redirect tro your own server as test

wooden crown
#

let me give that a try, I have also tried sending a byte array to no avail

#

9512339 Bytes, 9.07 MB, I know in the documentation they say the files cannot exceed 512MB so I seem to be way under the limit

#

though I don't know how you would ever send something that large over HTTP anyway lol

fossil ivy
#

🤔

#

i cant notice any issue with the code itself and the size is fine too

#

and you tried ByteArrayContent(File.ReadAllBytes(filePath)) too?

wooden crown
#

I know I was hoping to run into someone with a similar problem on here, and yes I tried that as well with the same result, here is the response I get to both calls -
<html>
<head><title>413 Request Entity Too Large</title></head>
<body>
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.23.2</center>
</body>
</html>

#

Maybe they limit clients more that don't come from the SDKs they developed, at least that's the only plausible explaination I can think of right now lmao

fossil ivy
#

btw 413 might happen before 404 depending of the config

#

but if the other endpoints worked fine with same logic its not the /

wooden crown
#

Ill also mention that before I figured out I had to send the file as form data instead of JSON I was reaching the server and getting the error "'file' required for this endpoint" or something like that

#

so I know I am hitting the endpoint

#

But I really do appreciate you working through this with me, I didnt even think to check the size of the request I was just thinking of the PDF itself before

fossil ivy
#

does simple .txt go through

wooden crown
#

let me give that a test

#

Well my friend it turns out you were absolutely right with your trailing / comment, because it didnt recognize the endpoint, the not found came after the too large error. I have been working this problem for so long I forgot I am using RestSharp for the other calls in my file. I cannot thank you enough and feel like an absolute idiot, going to close this thread, sorry for wasting you time 😅