# google-gemini/gemini-api-cli architecture

> Architecture diagram of the GitHub repository google-gemini/gemini-api-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-gemini/gemini-api-cli
- Repository: https://github.com/google-gemini/gemini-api-cli

## Overview

Gemini API CLI is a stateless shell interface that lets a host agent invoke Gemini models, media generation and analysis, and managed agents. The typical flow is shell command → command-specific input handling → authenticated API client → Gemini service → formatted output or a saved asset/interaction ID. The README also documents administration of files, models, environments, triggers, webhooks, and voices. Source excerpts show key wiring, but many command implementations are unsampled; their subsystems are represented without speculative internal links.

Main entry points: [`internal/cli/root.go`](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/root.go) (Command routing), [`internal/cli/agent/intent_agent-run.go`](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/agent/intent_agent-run.go) (Managed agents), [`internal/client/client.go`](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/client/client.go) (HTTP API client), [`internal/sdk/webhooks.go`](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/sdk/webhooks.go) (Gemini SDK)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry"]
  node_binary["CLI executable<br/>[main.go]"]
  node_commands["Command routing<br/>[root.go]"]
end

subgraph group_capabilities["Gemini capabilities"]
  node_model_ops["Model generation<br/>[intents.go]"]
  node_media_ops["Media creation"]
  node_understand_ops["File analysis<br/>[analyze.go]"]
  node_agent_ops["Managed agents"]
  node_catalog_ops["Catalog and files"]
  node_environment_ops["Environments"]
  node_trigger_ops["Triggers"]
  node_webhook_ops["Webhooks"]
  node_voice_ops["Voices"]
end

subgraph group_platform["Client platform"]
  node_config["Credentials and config<br/>[config.go]"]
  node_interactive["Interactive prompts<br/>[interactive.go]"]
  node_runtime["Environment runtime<br/>[client.go]"]
  node_output["Output and continuation<br/>[output.go]"]
end

subgraph group_service["API service"]
  node_client["HTTP API client<br/>[client.go]"]
  node_sdk["Gemini SDK<br/>[webhooks.go]"]
  node_gemini{{"Gemini API"}}
end

node_host(("Host agent or shell"))

node_host -->|"runs command"| node_binary
node_binary -->|"executes"| node_commands
node_commands -.->|"routes commands"| node_model_ops
node_commands -.->|"routes commands"| node_media_ops
node_commands -.->|"routes commands"| node_understand_ops
node_commands -.->|"routes commands"| node_agent_ops
node_commands -.->|"routes commands"| node_catalog_ops
node_commands -.->|"routes commands"| node_environment_ops
node_commands -.->|"routes commands"| node_trigger_ops
node_commands -.->|"routes commands"| node_webhook_ops
node_commands -.->|"routes commands"| node_voice_ops
node_commands -->|"loads configuration"| node_config
node_commands -.->|"renders results"| node_output
node_agent_ops -->|"creates API client"| node_client
node_agent_ops -->|"prompts when needed"| node_interactive
node_agent_ops -->|"formats results"| node_output
node_client -->|"reads credentials"| node_config
node_client -->|"configures SDK"| node_sdk
node_sdk -.->|"sends API requests"| node_gemini
node_media_ops -->|"uses runtime transport"| node_runtime
node_runtime -.->|"connects to service"| node_gemini
node_webhook_ops -.->|"uses webhook API"| node_sdk

click node_binary "https://github.com/google-gemini/gemini-api-cli/blob/main/cmd/gemini-api/main.go"
click node_commands "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/root.go"
click node_model_ops "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/intents.go"
click node_media_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/custom"
click node_understand_ops "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/custom/analyze.go"
click node_agent_ops "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/agent/intent_agent-run.go"
click node_catalog_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/files"
click node_environment_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/environments"
click node_trigger_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/triggers"
click node_webhook_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/webhooks"
click node_voice_ops "https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/voices"
click node_config "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/config/config.go"
click node_interactive "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/interactive/interactive.go"
click node_runtime "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/custom/envruntime/client.go"
click node_output "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/output/output.go"
click node_client "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/client/client.go"
click node_sdk "https://github.com/google-gemini/gemini-api-cli/blob/main/internal/sdk/webhooks.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_binary,node_commands toneBlue
class node_model_ops,node_media_ops,node_understand_ops,node_agent_ops,node_catalog_ops,node_environment_ops,node_trigger_ops,node_webhook_ops,node_voice_ops toneAmber
class node_config,node_interactive,node_runtime,node_output toneMint
class node_client,node_sdk,node_gemini toneRose
class node_host toneIndigo
```

## Components

### CLI entry

- [CLI executable](https://github.com/google-gemini/gemini-api-cli/blob/main/cmd/gemini-api/main.go): `cmd/gemini-api/main.go`
- [Command routing](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/root.go): `internal/cli/root.go`

### Gemini capabilities

- [Model generation](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/intents.go): `internal/cli/intents.go`
- [Media creation](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/custom): `internal/cli/custom`
- [File analysis](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/custom/analyze.go): `internal/cli/custom/analyze.go`
- [Managed agents](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/agent/intent_agent-run.go): `internal/cli/agent/intent_agent-run.go`
- [Catalog and files](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/files): `internal/cli/files`
- [Environments](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/environments): `internal/cli/environments`
- [Triggers](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/triggers): `internal/cli/triggers`
- [Webhooks](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/webhooks): `internal/cli/webhooks`
- [Voices](https://github.com/google-gemini/gemini-api-cli/tree/main/internal/cli/voices): `internal/cli/voices`

### Client platform

- [Credentials and config](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/config/config.go): `internal/config/config.go`
- [Interactive prompts](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/interactive/interactive.go): `internal/interactive/interactive.go`
- [Environment runtime](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/cli/custom/envruntime/client.go): `internal/cli/custom/envruntime/client.go`
- [Output and continuation](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/output/output.go): `internal/output/output.go`

### API service

- [HTTP API client](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/client/client.go): `internal/client/client.go`
- [Gemini SDK](https://github.com/google-gemini/gemini-api-cli/blob/main/internal/sdk/webhooks.go): `internal/sdk/webhooks.go`
- **Gemini API**

### Other components

- **Host agent or shell**

## Connections

- Host agent or shell → CLI executable: runs command (evidence: `README.md`)
- CLI executable → Command routing: executes (evidence: `cmd/gemini-api/main.go`)
- Command routing → Model generation: routes commands
- Command routing → Media creation: routes commands
- Command routing → File analysis: routes commands
- Command routing → Managed agents: routes commands
- Command routing → Catalog and files: routes commands
- Command routing → Environments: routes commands
- Command routing → Triggers: routes commands
- Command routing → Webhooks: routes commands
- Command routing → Voices: routes commands
- Command routing → Credentials and config: loads configuration
- Command routing → Output and continuation: renders results
- Managed agents → HTTP API client: creates API client (evidence: `internal/cli/agent/intent_agent-run.go`)
- Managed agents → Interactive prompts: prompts when needed (evidence: `internal/cli/agent/intent_agent-run.go`)
- Managed agents → Output and continuation: formats results (evidence: `internal/cli/agent/intent_agent-run.go`)
- HTTP API client → Credentials and config: reads credentials (evidence: `internal/client/client.go`)
- HTTP API client → Gemini SDK: configures SDK (evidence: `internal/client/client.go`)
- Gemini SDK → Gemini API: sends API requests
- Media creation → Environment runtime: uses runtime transport (evidence: `internal/cli/custom/runtime_client.go`)
- Environment runtime → Gemini API: connects to service
- Webhooks → Gemini SDK: uses webhook API
