I encountered this error when I set the maxTokens property as 4000, and upon investigation I managed to find and resolve the issue. The issue occurs in the file packages/dart_openai/src/core/networking/client.dart line 225 which resembles to final error = jsonDecode(data)['error'];. In my case setting maxTokens to 4000 fired an error: This model's maximum context length is 4097 tokens. However, you requested 4097 tokens (97 in the messages, 4000 in the completion). Please reduce the length of the messages or completion., and trying to decode this fired the error that's mentioned in the title instead.