{"record":{"id":"24356f13fcb846d4","repo":"google-gemini/gemini-cli","slug":"failed-to-create-chat-object-geterrormessage-e","errorCode":null,"errorMessage":"Failed to create chat object: ${getErrorMessage(e)}","messagePattern":"Failed to create chat object: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/agents/local-executor.ts","lineNumber":1096,"sourceCode":"      const chat = new GeminiChat(\n        this.executionContext,\n        systemInstruction,\n        [{ functionDeclarations: tools }],\n        startHistory,\n        undefined,\n        undefined,\n      );\n      await chat.initialize(undefined, 'subagent');\n      return chat;\n    } catch (e: unknown) {\n      await reportError(\n        e,\n        `Error initializing Gemini chat for agent ${this.definition.name}.`,\n        startHistory,\n        'startChat',\n      );\n      // Re-throw as a more specific error after reporting.\n      throw new Error(`Failed to create chat object: ${getErrorMessage(e)}`);\n    }\n  }\n\n  /**\n   * Executes function calls requested by the model and returns the results.\n   *\n   * @returns A new `Content` object for history, any submitted output, and completion status.\n   */\n  private async processFunctionCalls(\n    chat: GeminiChat,\n    model: string,\n    functionCalls: FunctionCall[],\n    signal: AbortSignal,\n    promptId: string,\n    onWaitingForConfirmation?: (waiting: boolean) => void,\n  ): Promise<{\n    nextMessage: Content;\n    submittedOutput: string | null;","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/core/src/agents/local-executor.ts#L1078-L1114","documentation":"Catch-all thrown by createChatObject when constructing or initializing GeminiChat raised. The original error is reported via reportError and re-thrown wrapped with getErrorMessage(e). The underlying cause is whatever made the GeminiChat start fail.","triggerScenarios":"new GeminiChat(...) or chat.initialize(undefined, 'subagent') throwing — e.g. invalid/missing API key, requested model not available for the project, malformed FunctionDeclaration schema in the tools array, network/transport failure reaching the model endpoint.","commonSituations":"GEMINI_API_KEY / ADC not set or revoked; model name typo or model not enabled in the project; a tool's FunctionDeclaration has an invalid JSON schema (e.g. unsupported types, missing required fields); quota/billing disabled; transient network outage.","solutions":["Read the wrapped message (getErrorMessage(e)) — it identifies whether it is auth, model-not-found, schema, or network.","Verify the API key / ADC and that the chosen model is enabled for the project.","Inspect each FunctionDeclaration passed in `tools`; simplify schemas and remove unsupported types until the call succeeds.","Check quota/billing; retry on transient network errors.","Run with debug logging to capture the reportError output for the full original stack."],"exampleFix":"// before: a tool schema with an unsupported type\n{ name: 'x', parameters: { type: 'object', properties: { a: { type: 'any' } } } }\n\n// after: use a supported JSON-Schema type\n{ name: 'x', parameters: { type: 'object', properties: { a: { type: 'string' } } } }","handlingStrategy":"try-catch","validationCode":"// Validate tool schemas and API key before creating the chat object.\nfunction validateTools(tools) {\n  for (const t of tools) {\n    if (!t.name) throw new Error('Tool missing name');\n    if (!t.parameters || t.parameters.type !== 'object')\n      throw new Error(`Tool ${t.name} parameters must be an object schema`);\n  }\n}\nif (!process.env['GEMINI_API_KEY'] && !process.env['GOOGLE_APPLICATION_CREDENTIALS'])\n  throw new Error('No Gemini credentials configured');","typeGuard":null,"tryCatchPattern":"try {\n  await executor.createChatObject(inputs, tools);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to create chat object')) {\n    // inspect inner cause from logs (reportError), fix schema/key/model\n  }\n  throw e;\n}","preventionTips":["Keep FunctionDeclaration schemas simple and JSON-Schema-compliant.","Verify model availability and API key before agent runs.","Run with debug logging to capture reportError output."],"tags":["agents","gemini","config","network"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}