{"record":{"id":"6cd55570be9cb1e7","repo":"Mintplex-Labs/anything-llm","slug":"gemini-this-model-does-not-support-tool-callin","errorCode":null,"errorMessage":"Gemini: ${this.model} does not support tool calling.","messagePattern":"Gemini: (.+?) does not support tool calling\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/aibitat/providers/gemini.js","lineNumber":248,"sourceCode":"        // ignore\n      }\n    }\n  }\n\n  #formatFunctions(functions) {\n    return functions.map((func) => ({\n      type: \"function\",\n      function: {\n        name: this.prefixToolCall(func.name, \"add\"),\n        description: func.description,\n        parameters: func.parameters,\n      },\n    }));\n  }\n\n  async stream(messages, functions = [], eventHandler = null) {\n    if (!this.supportsToolCalling)\n      throw new Error(`Gemini: ${this.model} does not support tool calling.`);\n    this.providerLog(\"Gemini.stream - will process this chat completion.\");\n    this.resetUsage();\n\n    try {\n      const msgUUID = v4();\n      /** @type {OpenAI.OpenAI.Chat.ChatCompletion} */\n      const response = await this.client.chat.completions.create({\n        model: this.model,\n        messages: this.#formatMessages(messages),\n        stream: true,\n        stream_options: { include_usage: true },\n        ...(Array.isArray(functions) && functions?.length > 0\n          ? {\n              tools: this.#formatFunctions(functions),\n              tool_choice: \"auto\",\n              // AIbitat runs one tool per turn; parallel calls cause a 400\n              // on the next request due to a tool call/result count mismatch.\n              parallel_tool_calls: false,","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/aibitat/providers/gemini.js#L230-L266","documentation":"GeminiProvider.stream() refuses to run when supportsToolCalling is false (gemini.js:247-248). The getter (gemini.js:68-71) returns true only when the model id starts with the literal string \"gemini\"; tool-call streaming on the v1beta/openai endpoint against any other model yields a 400/503, so the provider guards up front with a model-specific message.","triggerScenarios":"Constructing GeminiProvider with a non-gemini model id (e.g. a legacy \"text-bison\", an embedding model, a typo, or a copied value from another provider) and then calling stream() while agent tools are attached.","commonSituations":"Model name typo in the picker, an outdated model id left in the DB, or selecting a Gemini-family alias whose id does not begin with \"gemini\".","solutions":["Set the model to a current gemini-* id (e.g. gemini-2.0-flash or gemini-2.5-pro) so supportsToolCalling returns true.","If you must use a non-gemini model, disable agent tools / native tool calling so stream() is not invoked with functions.","Cross-check the id against Google's published Gemini model list.","Verify the model id persisted in workspace settings matches a starts-with(\"gemini\") name."],"exampleFix":"// before\nconst p = new GeminiProvider({ model: \"text-bison-001\" });\nawait p.stream(msgs, funcs);\n\n// after\nconst p = new GeminiProvider({ model: \"gemini-2.0-flash\" });\nawait p.stream(msgs, funcs);","handlingStrategy":"validation","validationCode":"// Validate the model supports tool calling before calling stream().\nfunction geminiSupportsTools(model) {\n  return typeof model === \"string\" && model.startsWith(\"gemini\");\n}\nif (functions?.length > 0 && !geminiSupportsTools(provider.model)) {\n  throw new Error(`Refusing to stream: model ${provider.model} cannot use tools.`);\n}","typeGuard":"// Narrow to a tool-capable Gemini model id.\n/** @param {string} model\n * @returns {boolean} */\nfunction isToolCapableGeminiModel(model) {\n  return typeof model === \"string\" && model.startsWith(\"gemini\");\n}","tryCatchPattern":"try {\n  await provider.stream(messages, functions, handler);\n} catch (e) {\n  if (/does not support tool calling/.test(e.message)) {\n    // fall back to a non-tool flow or switch model instead of retrying\n    return await provider.stream(messages, [], handler);\n  }\n  throw e;\n}","preventionTips":["Always set the model id explicitly from a vetted allow-list of gemini-* names.","Gate tool flows behind a starts-with('gemini') check in your provider factory.","Validate persisted model ids on settings save, not only at call time."],"tags":["gemini","tool-calling","config","model-selection"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}