Chat/completions api issue

hello
i am using chat/completions api in project but i am not getting any response form api. All time error come

Exception: Error: DioException [bad response]: The request returned an invalid status code of 429.

api - v1/chat/completions

{
          'model': model,
          'messages': [
            {
              'role': 'system',
              'content': 'You have to give concise and short answers'
            },
            {
              'role': 'user',
              'content': [
                {
                  'type': 'text',
                  'text':
                      'GPT, your task is to identify plant health issues with precision. Analyze any image of a plant or leaf I provide, and detect all abnormal conditions, whether they are diseases, pests, deficiencies, or decay. Respond strictly with the name of the condition identified, and nothing else—no explanations, no additional text. If a condition is unrecognizable, reply with \'I don\'t know\'. If the image is not plant-related, say \'Please pick another image\'',
                },
                {
                  'type': 'image_url',
                  'image_url': {
                    'url': 'data:image/jpeg;base64,$base64Image',
                  },
                },
              ],
            },
          ],
          'max_tokens': maxTokens,
        }

above request use in api calling but error comes.

please help me

Hi and welcome to the community!

The 429 error message means that your account isn’t sufficiently funded.

You can reference all error codes and the prospective solutions here:

https://platform.openai.com/docs/guides/error-codes/api-errors

hello
my account is new and i am only one time using this so how isn’t sufficiently funded.

Are you aware that API calls are not free?

Make sure you have enough balance in your account.

The API isn’t free, so you have to pay for it.

In case you have not yet purchased any balance, the API won’t work for you.

Good luck! :hugs:

no
i am not konw.
it is not free.

hello
what is the price and how to purchase ?

Check this out! :hugs:

hello
i want to detect plant issue using the api but it is not give me right solution.
please help me.
I am using below api calling to getting solution.

Future sendImageToGPT4Vision({
required File image,
int maxTokens = 300,
String model = “gpt-4-turbo”,
}) async
{
final String base64Image = await encodeImage(image);

try {
  final response = await _dio.post(
    "$BASE_URL/chat/completions",
    options: Options(
      headers: {
        HttpHeaders.authorizationHeader: 'Bearer $API_KEY',
        HttpHeaders.contentTypeHeader: "application/json",
      },
    ),
    data: jsonEncode({
      'model': model,
      'messages': [
        {
          'role': 'system',
          'content': 'You have to give concise and short answers'
        },
        {
          'role': 'user',
          'content': 'GPT, your task is to identify plant health issues with precision. Analyze the image provided and detect any plant conditions. Respond only with the name of the condition identified. If a condition is unrecognizable, reply "I don\'t know". If the image is not plant-related, say "Please pick another image".'
        },
        {
          'role': 'user',
          'content': 'data:image/jpg;base64,$base64Image'
        }
      ],
      'max_tokens': maxTokens,
    }),
  );

  final jsonResponse = response.data;

  if (jsonResponse['error'] != null) {
    throw HttpException(jsonResponse['error']["message"]);
  }
  return jsonResponse["choices"][0]["message"]["content"];
} catch (e) {
  throw Exception('Error: $e');
}

}

What error are you encountering or what exactly is the issue? :blush:

I am getting
{id: chatcmpl-AQ8fHzJOELGsu3sgCPg6I9qLNhCH8, object: chat.completion, created: 1730793199, model: gpt-4-turbo-2024-04-09, choices: [{index: 0, message: {role: assistant, content: Please pick another image, refusal: null}, logprobs: null, finish_reason: stop}], usage: {prompt_tokens: 34439, completion_tokens: 4, total_tokens: 34443, prompt_tokens_details: {cached_tokens: 0}, completion_tokens_details: {reasoning_tokens: 0, accepted_prediction_tokens: 0, rejected_prediction_tokens: 0}}, system_fingerprint: fp_5db30363ff}

above response
but image in plant has issue but it is not detect.

How are you passing the image? :blush:
Some Code snippets could help us help you! :smile: