Error on tryng to use batches

Hello!

I’m encountering an error when trying to make a request using batches.

The error I get is: OpenAI API Error: Invalid body: failed to parse JSON value. Please check the value to ensure it is valid JSON. (Common errors include trailing commas, missing closing brackets, missing quotation marks, etc.)

The file ID I am attaching to the request is a JSONL with the test structure from the documentation, which is as follows:

{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}
{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are an unhelpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}

I have also tried sending other data, but I always get the same error.

I’m making the request using curl with the headers and parameters indicated in the documentation.

Has anyone encountered a similar situation?

Thanks!

Hi there!

Couple of points:

  1. Could you share a couple of examples from your batch? This would help to investigate whether there are any errors in the way you’ve set up your JSONL file.

  2. Just to be sure, you are following the two step process for the creation of a batch, right? Meaning, you first upload the JSONL file via file upload request with the purpose batch, then fetch the returned file-ID and thereafter create a batch request with the file-ID.

1 Like

Hi! Thanks for the answer!

The example that i shared in the post is what i uploaded as a file using the file upload request endpoint and then making the batch request using that file id.

It is weird that i’m getting that error because i’m using the example that the documentation provides (were trying using another using the same format)

Regards.

1 Like

The easiest check would just be to paste it into a code editor and see if it throws any error. It’s probably just something minor. Without seeing your data, it’s difficult to identify the issue.

1 Like

I’m having the same problem… Did you find a solution @baezapm?

Do you have more details, @aloisejulian ?

Have you tested your data in a code editor to look for errors?

1 Like

Hello to the Community. I’m new here, so excuse my possible errors of communication.
I’m having the same problem. And to be on the safe side, I’m helped by chatGpt to proceed in the best possible way.
Again, to be on the safe side, after having tried all possoble variations in the testjson.jsonl file (with or without escaped chars sequences, shortening the content of the “messages” section, putting the parametres such as max_tokens, top_p, presence_penalty etc. before and after the messages section, and every possible combination of these pseudo-solution, I finally replaced the content of the file with the lines given in the documentation example.
You know what? This is the reply I got from the API (posting at the file URL):

{
“error”: {
“message”: “Invalid file format for Batch API. Must be .jsonl”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}

The problem is that I replaced the content of my file with the example’s one!
This is undoubfully a bug in the API uploading interface.
If this should be not, could you please provide the name of an application which is capable to recognize errors in the json content of a JSONL file?
This will be greatly appreciated.
Thanks