Skip to content

@tanstack/ai-gemini Error 400 when sending a functionResponse #436

Closed

Description

@hugoattal

TanStack AI version

@tanstack/ai v0.10.1;

Framework/Library version

@tanstack/ai-gemini v0.8.5

Describe the bug and the steps to reproduce it

I provided a simple tool and try to use it with gemini-3.1-flash-lite-preview, but it always fires a 400 error. The call works, it crashed after the response from my server.

⚠️ EDIT: It seems to work with gemini-2.5-flash, maybe it's on Google side 🤔. Still the duplicate function response seems odd.

I feel like it may be because there are two parts :

  • one with text
  • one with functionResponse
{
  "parts": [
    {
      "text": "{\"id\":\"root\",\"name\":\"Root\",\"type\":\"folder\",\"children\":[{\"id\":\"dd2f5a5f\",\"name\":\"New page\",\"type\":\"component\"},{\"id\":\"cbadb546\",\"name\":\"New Store\",\"type\":\"store\"}]}"
    },
    {
      "functionResponse": {
        "id": "rmny7t6v",
        "name": "getProjectFileTree",
        "response": {
          "content": "{\"id\":\"root\",\"name\":\"Root\",\"type\":\"folder\",\"children\":[{\"id\":\"dd2f5a5f\",\"name\":\"New page\",\"type\":\"component\"},{\"id\":\"cbadb546\",\"name\":\"New Store\",\"type\":\"store\"}]}"
        }
      }
    }
  ],
  "role": "user"
}

I suspect it may be because of this: https://discuss.ai.google.dev/t/error-400-when-llm-response-contains-both-text-and-functioncall/70826

Also, having the response of the function call in both parts doesn't seem to be very efficient to me... I think the part with text shouldn't be here.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

Here's the full payload

{
  "contents": [
    {
      "parts": [
        {
          "text": "Check my project tree and suggest new names"
        }
      ],
      "role": "user"
    },
    {
      "parts": [
        {
          "functionCall": {
            "id": "rmny7t6v",
            "args": {},
            "name": "getProjectFileTree"
          }
        }
      ],
      "role": "model"
    },
    {
      "parts": [
        {
          "text": "{\"id\":\"root\",\"name\":\"Root\",\"type\":\"folder\",\"children\":[{\"id\":\"dd2f5a5f\",\"name\":\"New page\",\"type\":\"component\"},{\"id\":\"cbadb546\",\"name\":\"New Store\",\"type\":\"store\"}]}"
        },
        {
          "functionResponse": {
            "id": "rmny7t6v",
            "name": "getProjectFileTree",
            "response": {
              "content": "{\"id\":\"root\",\"name\":\"Root\",\"type\":\"folder\",\"children\":[{\"id\":\"dd2f5a5f\",\"name\":\"New page\",\"type\":\"component\"},{\"id\":\"cbadb546\",\"name\":\"New Store\",\"type\":\"store\"}]}"
            }
          }
        }
      ],
      "role": "user"
    }
  ],
  "systemInstruction": {
    "parts": [
      {
        "text": "You are **Sidekick**, an expert AI assistant for the **Luna Park** visual editor. [...]\r\n"
      }
    ],
    "role": "user"
  },
  "tools": [
    {
      "functionDeclarations": [
        {
          "name": "getProjectFileTree",
          "description": "Get the project file tree",
          "parameters": {
            "type": "OBJECT",
            "properties": {}
          }
        }
      ]
    }
  ],
  "generationConfig": {}
}

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Maybe, I'll investigate and start debugging

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

  1. hugoattal commented on Apr 9, 2026

    @hugoattal
    Author

    Minimum reproduction :

    import { chat, toolDefinition } from "@tanstack/ai";
    import { createGeminiChat } from "@tanstack/ai-gemini";
    import { useChat } from "@tanstack/ai-vue";
    
    const adapter = createGeminiChat("gemma-4-31b-it", "API_KEY");
    
    const coolTool = toolDefinition({
        name: "getCoolStuff",
        description: "Returns cool stuff.",
        inputSchema: {type: "object", properties: {}},
        outputSchema: {type: "object", properties: {stuff: {type: "array", items: {type: "string"}}}},
    }).server(() => {
        return ["trains", "rockets"]
    });
    
    const aiChat = useChat({
        connection: {
            connect: (messages) => chat({
                adapter,
                messages,
                systemPrompts: ["You're a helpful assistant."],
                tools: [coolTool]
            })
        }
    });
    
    await aiChat.sendMessage("List all the cool stuff");

    Sends

    {
        "parts": [
            {
                "text": "[\"trains\",\"rockets\"]"
            },
            {
                "functionResponse": {
                    "id": "6gimt3fv",
                    "name": "getCoolStuff",
                    "response": {
                        "content": "[\"trains\",\"rockets\"]"
                    }
                }
            }
        ]
    }
  2. hugoattal commented on Apr 13, 2026

    @hugoattal
    Author

    Proof that this is being sent to the LLM

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions