openai-cookbook icon indicating copy to clipboard operation
openai-cookbook copied to clipboard

Http status error [429]

Open RiadHaidar opened this issue 2 years ago • 0 comments
trafficstars

First of all, I was using the same approach I'm using one week ago and I didn't face any issue, Second, I understand there is a limit usage for the API key of each free account, however, I tried several API keys, from different accounts including mine, where the usage is $0.19 / $18.00, I kept getting the same error,

the issue includes the following features: 1_Text Completion 2_Image Generation 3_Chat Completion

the issue is still not resolved it would appear on any feature of OPENAI, I looked over StackOverflow or OPENAI community

I'll show my command below using Postman as well as Flutter:

1_ Request using Postman:

openai1

2_ Here is my flutter code:

` static Future<Map<String, String?>> getResponse( String prompt, List<Map<String, String>> messages) async { String? text; String? error; // messages = messages.reversed.toList(); messages.add({"role": "user", "content": prompt});

try {
  final response = await http.post(
    Uri.parse("${Constants.baseUrl}/chat/completions"),
    headers: {
      'Authorization': 'Bearer ${Constants.OPEN_AI_KEY}',
      "Content-Type": "application/json"
    },
    body: jsonEncode({
      "model": "gpt-3.5-turbo",
      "messages": messages,
      "max_tokens": 400,
      "temperature": 0.4,
      "n": 1,
    }),
  );

  // if (response.statusCode != 200) {
  //   throw Exception('Failed to fetch data');
  // }

  final jsonResponse = jsonDecode(response.body);
  var result = jsonResponse['choices'][0]['message']['content'];
  print('result is');
  print(result);
  //  final result = jsonResponse['choices'][0]['message']['content'];
  // for (var i = 0; i < result.length; i++) {
  //   chatMessages.add(result[i]['text'].toString());
  // }
  text = truncateResponse(
      result.toString().trim().replaceAll(RegExp('^\.\\n'), ''), 400);
  print(jsonResponse);
  return {'text': text, 'error': error};
} catch (error) {
  print("error $error");
  rethrow;
}

} }`

RiadHaidar avatar May 11 '23 06:05 RiadHaidar