ChatGPT API - messages with line breaks

Hi, I’ve just started switching over from Davinci to the newly released gpt-3.5-turbo model. I’m having an issue where the API only accepts message prompts that don’t include line breaks. Perhaps, it’s a formatting issue with my prompt, but I’m not sure. Any tips on how to fix this?

Here’s an example:

  {“role”: “system”, “content”: “You are a helpful assistant that translates English to French.”},
  {“role”: “user”, “content”: ‘Translate the following English email to French: “{
Hi John,
Want to grab lunch Tuesday?

You can replace the actual new lines with “\n”. This should fix it!


I’m assuming you’re using Python? Try wrapping it with triple quotations:

My message
Is This

Or, you can just manually put in the newline and either escape them, or put a r infront of the string:

r"hi\nhow are you?"

1 Like

Thanks for the help. This works. Any idea why the Chat API doesn’t accept natural line breaks? For context, I’ve been calling the text-davinci-003 API with natural line breaks and having no issues.

Thanks for the response. I should have clarified that I’m using curl.

It’s not the API, more likely this is being checked on the client side.

Interesting. I’m new to all of this, so not sure what on the client side could be causing this.

I’m also having an issue when submitting prompts that include quotation marks. Assuming that’s related.

You should put \ in front of double quotation marks.


And would this also extend to “\t” for tabs?

  • Anything else I should know about?

Any advice is greatly appreciated. (^_^)