API Reference
Complete API documentation for Gemini CLI with detailed method descriptions, parameters, and practical examples.
API Sections
Navigate to different API categories
Core API
Main API for interacting with Gemini models and managing conversations
chat()
Start an interactive chat session with Gemini
Signature:
chat(options?: ChatOptions): Promise<ChatSession>
Example:
import { GeminiCLI } from '@google/generative-ai-cli';
const cli = new GeminiCLI();
const session = await cli.chat({
model: 'gemini-pro',
temperature: 0.7
});
ask()
Send a single prompt and get a response
Signature:
ask(prompt: string, options?: AskOptions): Promise<string>
Example:
const response = await cli.ask("What is machine learning?", {
maxTokens: 1000,
temperature: 0.5
});
analyze()
Analyze files or code with AI assistance
Signature:
analyze(files: string[], options?: AnalyzeOptions): Promise<AnalysisResult>
Example:
const analysis = await cli.analyze(['src/main.js'], {
type: 'code-review',
includeMetrics: true
});
Plugin API
API for developing custom plugins and extensions
registerPlugin()
Register a new plugin with the CLI
Signature:
registerPlugin(plugin: Plugin): void
Example:
const myPlugin = {
name: 'my-custom-plugin',
version: '1.0.0',
commands: {
'custom-command': async (args) => {
// Plugin logic here
return 'Plugin executed successfully';
}
}
};
cli.registerPlugin(myPlugin);
createTool()
Create a custom tool for AI to use
Signature:
createTool(definition: ToolDefinition): Tool
Example:
const weatherTool = cli.createTool({
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
location: { type: 'string', required: true }
},
execute: async ({ location }) => {
// Fetch weather data
return `Weather in ${location}: Sunny, 25Β°C`;
}
});
Configuration API
API for managing CLI configuration and settings
getConfig()
Get current configuration values
Signature:
getConfig(key?: string): any
Example:
// Get all config
const config = cli.getConfig();
// Get specific config value
const model = cli.getConfig('model');
setConfig()
Set configuration values
Signature:
setConfig(key: string, value: any): void
Example:
// Set model
cli.setConfig('model', 'gemini-pro');
// Set multiple values
cli.setConfig('temperature', 0.8);
cli.setConfig('maxTokens', 2000);
resetConfig()
Reset configuration to defaults
Signature:
resetConfig(key?: string): void
Example:
// Reset all config
cli.resetConfig();
// Reset specific key
cli.resetConfig('temperature');
Tools API
API for managing and executing built-in tools
listTools()
Get list of available tools
Signature:
listTools(): Tool[]
Example:
const tools = cli.listTools();
console.log(tools.map(t => t.name));
// ['read_file', 'write_file', 'run_shell_command', ...]
executeTool()
Execute a specific tool
Signature:
executeTool(name: string, args: any): Promise<any>
Example:
// Read a file
const content = await cli.executeTool('read_file', {
path: './package.json'
});
// Run shell command
const result = await cli.executeTool('run_shell_command', {
command: 'ls -la'
});
Common Types
TypeScript interfaces and types used across the API
ChatOptions
Options for starting a chat session
model
Model to use (e.g., "gemini-pro")
temperature
Creativity level (0-1)
maxTokens
Maximum response length
systemPrompt
System instructions
ToolDefinition
Definition for creating custom tools
name
Unique tool name
description
Tool description for AI
parameters
Parameter schema
execute
Tool execution function