google-gemini/gemini-cli · error · Error
Failed to create chat object: ${getErrorMessage(e)}
Error message
Failed to create chat object: ${getErrorMessage(e)} What it means
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.
Source
Thrown at packages/core/src/agents/local-executor.ts:1096
const chat = new GeminiChat(
this.executionContext,
systemInstruction,
[{ functionDeclarations: tools }],
startHistory,
undefined,
undefined,
);
await chat.initialize(undefined, 'subagent');
return chat;
} catch (e: unknown) {
await reportError(
e,
`Error initializing Gemini chat for agent ${this.definition.name}.`,
startHistory,
'startChat',
);
// Re-throw as a more specific error after reporting.
throw new Error(`Failed to create chat object: ${getErrorMessage(e)}`);
}
}
/**
* Executes function calls requested by the model and returns the results.
*
* @returns A new `Content` object for history, any submitted output, and completion status.
*/
private async processFunctionCalls(
chat: GeminiChat,
model: string,
functionCalls: FunctionCall[],
signal: AbortSignal,
promptId: string,
onWaitingForConfirmation?: (waiting: boolean) => void,
): Promise<{
nextMessage: Content;
submittedOutput: string | null;View on GitHub (pinned to 5024443c72)
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.
Example fix
// before: a tool schema with an unsupported type
{ name: 'x', parameters: { type: 'object', properties: { a: { type: 'any' } } } }
// after: use a supported JSON-Schema type
{ name: 'x', parameters: { type: 'object', properties: { a: { type: 'string' } } } } Defensive patterns
Strategy: try-catch
Validate before calling
// Validate tool schemas and API key before creating the chat object.
function validateTools(tools) {
for (const t of tools) {
if (!t.name) throw new Error('Tool missing name');
if (!t.parameters || t.parameters.type !== 'object')
throw new Error(`Tool ${t.name} parameters must be an object schema`);
}
}
if (!process.env['GEMINI_API_KEY'] && !process.env['GOOGLE_APPLICATION_CREDENTIALS'])
throw new Error('No Gemini credentials configured'); Try / catch
try {
await executor.createChatObject(inputs, tools);
} catch (e) {
if (e instanceof Error && e.message.startsWith('Failed to create chat object')) {
// inspect inner cause from logs (reportError), fix schema/key/model
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PromptConfig must define either `systemPrompt` or `initialMe
- Failed to create auth provider for agent '${definition.name}
- Remote agent '${definition.name}' requires a string 'query'
- Failed to initialize RemoteAgentInvocation for '${definition
- Failed to create auth provider for agent '${definition.name}
AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12).
Data as JSON: /api/errors/24356f13fcb846d4.
Report an issue: GitHub.