I tried to use ChatAPI API in flutter App
.
And This is the code that I use.
Future<String?> getChatGPTResponse(String prompt) async {
const apiKey = "~~~~~~~~~";
const apiUrl = "https://api.openai.com/v1/completions";
final headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $apiKey'
};
final body = jsonEncode(
{
"model": "text-davinci-003",
'prompt': prompt,
'max_tokens': 1000, // Adjust as needed
},
);
try {
final response = await http.post(
Uri.parse(apiUrl),
headers: headers,
body: body,
);
if (response.statusCode == 200) {
final jsonResponse = jsonDecode(response.body);
final result = jsonResponse['choices'][0]['text'];
return result;
} else {
const result = "오류가 발생했습니다.";
print(
'Failed to call ChatGPT API: ${response.statusCode} ${response.body}',
);
return result;
}
} catch (e) {
const result = "오류가 발생했습니다.";
print("Error calling ChatGPT API: $e");
return result;
}
}
But I keep facing below error message.
I/flutter (16756): Failed to call ChatGPT API: 429 {
I/flutter (16756): "error": {
I/flutter (16756): "message": "You exceeded your current quota, please check your plan and billing details.",
I/flutter (16756): "type": "insufficient_quota",
I/flutter (16756): "param": null,
I/flutter (16756): "code": "insufficient_quota"
I/flutter (16756): }
I/flutter (16756): }
I register credit card and now I'm Pay as you go
.
And I haven't used any API service so far.
After registering my billing info, I deleted old API key and generate new key either.
But still I have this problem.
But why do I keep facing this insufficient_quota error?