**GeminiException** status code 404

Hello, I’ve been trying to build a flutter app with gemini API. It will be like a chatbot with additional features. I try to send a media file to Gemini but I get this error:

rror: GeminiException => This exception was thrown because the response has a status code of 404 and RequestOptions.validateStatus was configured to throw for this status code.

I/flutter (12001): The status code of 404 has the following meaning: “Client error - the request contains bad syntax or cannot be fulfilled”

I/flutter (12001): Read more about status codes at HTTP response status codes - HTTP | MDN

I/flutter (12001): In order to resolve this exception you typically have either to verify and fix your request code or you have to fix the server code.

Before sending a prompt to Gemini it was working fine but now even when I delete the prompt it doesn’t work.

 void _sendMessage(ChatMessage chatMessage) {
    setState(() {
      messages = [chatMessage, ...messages];
    });
    try {
      String question = chatMessage.text;
      List<Uint8List>? images;
      if (chatMessage.medias?.isNotEmpty ?? false) {
        images = [
          File(chatMessage.medias!.first.url).readAsBytesSync(),
        ];
      }
      gemini
          .streamGenerateContent(
        question,
        images: images,
      )
          .listen((event) {
        ChatMessage? lastMessage = messages.firstOrNull;
        if (lastMessage != null && lastMessage.user == geminiUser) {
          lastMessage = messages.removeAt(0);
          String response = event.content?.parts?.fold(
                  "", (previous, current) => "$previous ${current.text}") ??
              "";
          lastMessage.text += response;
          setState(
            () {
              messages = [lastMessage!, ...messages];
            },
          );
        } else {
          String response = event.content?.parts?.fold(
                  "", (previous, current) => "$previous ${current.text}") ??
              "";
          ChatMessage message = ChatMessage(
            user: geminiUser,
            createdAt: DateTime.now(),
            text: response,
          );
          setState(() {
            messages = [message, ...messages];
          });
        }
      });
    } catch (e) {
      print(e);
    }
  }

I get the error at .listen(event) part

Thanks in advance!

Welcome to the forums!

You don’t show how you’re creating the gemini object or what model you’re using.

Could you be using a Gemini 1.0 Pro Vision model? That model was recently discontinued using AI Studio’s API and may finally have been shut down.

I just created an API Key and used that key so I don’t know which model I’m using… I tried to look for information about it but I couldn’t find anything. Can I choose the model I want? I’m new to this so I don’t know

Can you show the code you used to create the gemini object?

here `class _MealsScreenState extends State {
final Gemini gemini = Gemini.instance;

List messages = ;

ChatUser currentUser = ChatUser(id: “0”, firstName: “User”);
ChatUser geminiUser = ChatUser(
id: “1”,
firstName: “Gemini”,
profileImage:
https://seeklogo.com/images/G/google-gemini-logo-A5787B2669-seeklogo.com.png”,
);`

This doesn’t look like a Google package, and whoever created it didn’t document how to use a different model very well.

I’m not a Flutter/Dart expert, but reading through the code I think you can specify the modelName as a parameter when you call gemini.streamGenerateContent(). So perhaps something like

gemini.streamGenerateContent(
  question,
  modelName: 'gemini-1.5-flash',
);

It’s a team project and my teammate used flutter_gemini package. I tried this but I still get the same error.