Issue with "null" responses after generating multiple meta-titles and meta-descriptions using ChatGPT 3.5 API

Hello everyone,

I’ve recently integrated ChatGPT 3.5 API functionalities into a script to automatically generate meta-titles and meta-descriptions for my products. When I manually call the script to modify a product, everything works correctly. However, when the script is automatically triggered for multiple products, after creating 2 meta-titles and 1 meta-description, all subsequent responses turn to “null”.

I’m wondering if anyone has encountered this issue before and if there are any suggestions for resolving it. Here’s a snippet of the code I’m using:

	while IFS='|' read -r col1 col2 col3 col4 col5; do
		json_titre='{"model": "gpt-3.5-turbo", "messages": [{"role": "system", "content": "'"${prompt_meta_titre}"'"}]}'
		meta_titre=$(curl -X POST "" -H "Authorization: Bearer [CLE_API]" -H "Content-Type: application/json" -d "${json_titre}" | jq -r '.choices[0].message.content')
		meta_titre=$(echo "$meta_titre" | tr '|' '-')
		json_desc='{"model": "gpt-3.5-turbo", "messages": [{"role": "system", "content": "'"${prompt_meta_description}"'"}]}'
		meta_description=$(curl -X POST "" -H "Authorization: Bearer [CLE_API]" -H "Content-Type: application/json" -d "${json_desc}" | jq -r '.choices[0].message.content')
		printf "%s|%s|%s|%s|%s\n" "$col1" "$col2" "$col3" "$meta_titre" "$meta_description" >> .totranslatedb2.tmp
	done < .totranslatedb.tmp
	mv .totranslatedb2.tmp .totranslatedb.tmp
}Preformatted text

I’ve checked my API calls, and they seem correct. Are there any limitations or specific parameters to consider when using the API in an automated and repetitive manner?

Thanks in advance for your help!

Hi, welcome to the forum!

I’m not super fond of shell scripts, so I’m not gonna read it too closely :sweat_smile:

One thing you may need to keep in mind is that depending on what tier you’re in, you might be getting rate-limited.

If you’re not explicitly catching errors, it’s quite possible that the object you’re expecting from a 200 just isn’t there, and you might be getting a null back.

Does that sound plausible?

Sure, I’ll try adding a sleep between the API calls to see if that could be the issue. I’ll let you know as soon as I’ve tested it, and I’ll get back to you if it resolves the situation. Thanks again for your quick assistance!

1 Like