# openai/openai-cli architecture

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

- Interactive diagram: https://gitdiagram.com/openai/openai-cli
- Repository: https://github.com/openai/openai-cli

## Overview

OpenAI CLI turns resource-oriented terminal commands into OpenAI REST API requests and presents responses or errors in scriptable and human-readable forms. A parallel image workflow generates and saves images, then supports local preview and optional terminal-native rendering; shell completion and help improve command discovery. The graph combines the shown entry point and sampled implementations with README-documented capabilities. Many generated API command files and image subsystems were not excerpted, so their internal call links are omitted or shown only where documentation supports them.

Main entry points: [`cmd/openai/main.go`](https://github.com/openai/openai-cli/blob/main/cmd/openai/main.go) (CLI entry), [`pkg/cmd/adminorganizationexternalstorage.go`](https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationexternalstorage.go) (Admin storage commands), [`pkg/cmd/webhook.go`](https://github.com/openai/openai-cli/blob/main/pkg/cmd/webhook.go) (Webhook commands), [`pkg/custom/image_picker_generate.go`](https://github.com/openai/openai-cli/blob/main/pkg/custom/image_picker_generate.go) (Image commands)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry and discovery"]
  node_entry["CLI entry<br/>[main.go]"]
  node_help["Help and errors<br/>[help.go]"]
  node_autocomplete["Shell completion<br/>[autocomplete.go]"]
end

subgraph group_api["API command surface"]
  node_commands["Command tree<br/>[cmd.go]"]
  node_apiresources["API resource commands"]
  node_adminstorage["Admin storage commands"]
  node_serviceaccounts["Service account commands"]
  node_servicekeys["Service account keys"]
  node_webhooks["Webhook commands<br/>[webhook.go]"]
end

subgraph group_presentation["Output and presentation"]
  node_formatting["Readable output<br/>[readable.go]"]
  node_streamprojection["Stream projection"]
  node_jsonviews["JSON presentation"]
end

subgraph group_images["Image workflows"]
  node_imagecommands["Image commands"]
  node_imageoutput["Image saving<br/>[save_response.go]"]
  node_imagepreferences[("Preview preferences<br/>[imageprefs.go]")]
  node_imagepreview["Saved image preview"]
  node_terminalimage["Terminal image rendering<br/>[font.go]"]
  node_imagegallery[("Image font gallery<br/>[gallery.go]")]
  node_imagefont["Image font processing<br/>[imagefont.go]"]
end

subgraph group_runtime["Request support"]
  node_requestflags["Request flags"]
  node_queryencoding["Query encoding<br/>[query.go]"]
end

node_user(("CLI user"))
node_restapi["OpenAI REST API"]

node_user -->|"runs command"| node_entry
node_entry -->|"runs"| node_commands
node_entry -->|"configures help"| node_help
node_entry -->|"prepares completion"| node_autocomplete
node_commands -.->|"dispatches commands"| node_apiresources
node_apiresources -->|"calls REST API"| node_restapi
node_adminstorage -->|"calls REST API"| node_restapi
node_serviceaccounts -->|"calls REST API"| node_restapi
node_servicekeys -->|"calls REST API"| node_restapi
node_webhooks -->|"calls REST API"| node_restapi
node_adminstorage -->|"reads flags"| node_requestflags
node_serviceaccounts -->|"reads flags"| node_requestflags
node_webhooks -->|"reads flags"| node_requestflags
node_adminstorage -.->|"encodes queries"| node_queryencoding
node_webhooks -->|"encodes queries"| node_queryencoding
node_restapi -.->|"returns results"| node_formatting
node_streamprojection -->|"projects stream text"| node_formatting
node_apiresources -.->|"presents JSON"| node_jsonviews
node_imagecommands -->|"requests generation"| node_restapi
node_imagecommands -->|"saves results"| node_imageoutput
node_imagepreview -->|"renders saved image"| node_terminalimage
node_terminalimage -->|"uses gallery"| node_imagegallery
node_terminalimage -->|"uses font processing"| node_imagefont
node_imagegallery -->|"encodes images"| node_imagefont
node_imagecommands -.->|"uses preferences"| node_imagepreferences

click node_entry "https://github.com/openai/openai-cli/blob/main/cmd/openai/main.go"
click node_commands "https://github.com/openai/openai-cli/blob/main/pkg/cmd/cmd.go"
click node_apiresources "https://github.com/openai/openai-cli/tree/main/pkg/cmd"
click node_adminstorage "https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationexternalstorage.go"
click node_serviceaccounts "https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationprojectserviceaccount.go"
click node_servicekeys "https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationprojectserviceaccountapikey.go"
click node_webhooks "https://github.com/openai/openai-cli/blob/main/pkg/cmd/webhook.go"
click node_requestflags "https://github.com/openai/openai-cli/tree/main/internal/requestflag"
click node_queryencoding "https://github.com/openai/openai-cli/blob/main/internal/apiquery/query.go"
click node_help "https://github.com/openai/openai-cli/blob/main/pkg/custom/help.go"
click node_autocomplete "https://github.com/openai/openai-cli/blob/main/internal/autocomplete/autocomplete.go"
click node_formatting "https://github.com/openai/openai-cli/blob/main/internal/readable/readable.go"
click node_streamprojection "https://github.com/openai/openai-cli/blob/main/pkg/transformers/project_text_stream.go"
click node_jsonviews "https://github.com/openai/openai-cli/tree/main/internal/jsonview"
click node_imagecommands "https://github.com/openai/openai-cli/blob/main/pkg/custom/image_picker_generate.go"
click node_imageoutput "https://github.com/openai/openai-cli/blob/main/internal/imageoutput/save_response.go"
click node_imagepreferences "https://github.com/openai/openai-cli/blob/main/internal/imageprefs/imageprefs.go"
click node_imagepreview "https://github.com/openai/openai-cli/blob/main/pkg/custom/preview_saved_image.go"
click node_terminalimage "https://github.com/openai/openai-cli/blob/main/internal/terminalimage/font.go"
click node_imagegallery "https://github.com/openai/openai-cli/blob/main/internal/imagegallery/gallery.go"
click node_imagefont "https://github.com/openai/openai-cli/blob/main/internal/imagefont/imagefont.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_entry,node_help,node_autocomplete,node_user toneBlue
class node_commands,node_apiresources,node_adminstorage,node_serviceaccounts,node_servicekeys,node_webhooks toneAmber
class node_formatting,node_streamprojection,node_jsonviews,node_restapi toneMint
class node_imagecommands,node_imageoutput,node_imagepreferences,node_imagepreview,node_terminalimage,node_imagegallery,node_imagefont toneRose
class node_requestflags,node_queryencoding toneIndigo
```

## Components

### CLI entry and discovery

- [CLI entry](https://github.com/openai/openai-cli/blob/main/cmd/openai/main.go): `cmd/openai/main.go`
- [Help and errors](https://github.com/openai/openai-cli/blob/main/pkg/custom/help.go): `pkg/custom/help.go`
- [Shell completion](https://github.com/openai/openai-cli/blob/main/internal/autocomplete/autocomplete.go): `internal/autocomplete/autocomplete.go`

### API command surface

- [Command tree](https://github.com/openai/openai-cli/blob/main/pkg/cmd/cmd.go): `pkg/cmd/cmd.go`
- [API resource commands](https://github.com/openai/openai-cli/tree/main/pkg/cmd): `pkg/cmd`
- [Admin storage commands](https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationexternalstorage.go): `pkg/cmd/adminorganizationexternalstorage.go`
- [Service account commands](https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationprojectserviceaccount.go): `pkg/cmd/adminorganizationprojectserviceaccount.go`
- [Service account keys](https://github.com/openai/openai-cli/blob/main/pkg/cmd/adminorganizationprojectserviceaccountapikey.go): `pkg/cmd/adminorganizationprojectserviceaccountapikey.go`
- [Webhook commands](https://github.com/openai/openai-cli/blob/main/pkg/cmd/webhook.go): `pkg/cmd/webhook.go`

### Output and presentation

- [Readable output](https://github.com/openai/openai-cli/blob/main/internal/readable/readable.go): `internal/readable/readable.go`
- [Stream projection](https://github.com/openai/openai-cli/blob/main/pkg/transformers/project_text_stream.go): `pkg/transformers/project_text_stream.go`
- [JSON presentation](https://github.com/openai/openai-cli/tree/main/internal/jsonview): `internal/jsonview`

### Image workflows

- [Image commands](https://github.com/openai/openai-cli/blob/main/pkg/custom/image_picker_generate.go): `pkg/custom/image_picker_generate.go`
- [Image saving](https://github.com/openai/openai-cli/blob/main/internal/imageoutput/save_response.go): `internal/imageoutput/save_response.go`
- [Preview preferences](https://github.com/openai/openai-cli/blob/main/internal/imageprefs/imageprefs.go): `internal/imageprefs/imageprefs.go`
- [Saved image preview](https://github.com/openai/openai-cli/blob/main/pkg/custom/preview_saved_image.go): `pkg/custom/preview_saved_image.go`
- [Terminal image rendering](https://github.com/openai/openai-cli/blob/main/internal/terminalimage/font.go): `internal/terminalimage/font.go`
- [Image font gallery](https://github.com/openai/openai-cli/blob/main/internal/imagegallery/gallery.go): `internal/imagegallery/gallery.go`
- [Image font processing](https://github.com/openai/openai-cli/blob/main/internal/imagefont/imagefont.go): `internal/imagefont/imagefont.go`

### Request support

- [Request flags](https://github.com/openai/openai-cli/tree/main/internal/requestflag): `internal/requestflag`
- [Query encoding](https://github.com/openai/openai-cli/blob/main/internal/apiquery/query.go): `internal/apiquery/query.go`

### Other components

- **CLI user**
- **OpenAI REST API**

## Connections

- CLI user → CLI entry: runs command (evidence: `README.md`)
- CLI entry → Command tree: runs (evidence: `cmd/openai/main.go`)
- CLI entry → Help and errors: configures help (evidence: `cmd/openai/main.go`)
- CLI entry → Shell completion: prepares completion (evidence: `cmd/openai/main.go`)
- Command tree → API resource commands: dispatches commands
- API resource commands → OpenAI REST API: calls REST API (evidence: `README.md`)
- Admin storage commands → OpenAI REST API: calls REST API (evidence: `pkg/cmd/adminorganizationexternalstorage.go`)
- Service account commands → OpenAI REST API: calls REST API (evidence: `pkg/cmd/adminorganizationprojectserviceaccount.go`)
- Service account keys → OpenAI REST API: calls REST API (evidence: `pkg/cmd/adminorganizationprojectserviceaccountapikey.go`)
- Webhook commands → OpenAI REST API: calls REST API (evidence: `pkg/cmd/webhook.go`)
- Admin storage commands → Request flags: reads flags (evidence: `pkg/cmd/adminorganizationexternalstorage.go`)
- Service account commands → Request flags: reads flags (evidence: `pkg/cmd/adminorganizationprojectserviceaccount.go`)
- Webhook commands → Request flags: reads flags (evidence: `pkg/cmd/webhook.go`)
- Admin storage commands → Query encoding: encodes queries
- Webhook commands → Query encoding: encodes queries (evidence: `pkg/cmd/webhook.go`)
- OpenAI REST API → Readable output: returns results
- Stream projection → Readable output: projects stream text (evidence: `pkg/transformers/project_text_stream.go`)
- API resource commands → JSON presentation: presents JSON
- Image commands → OpenAI REST API: requests generation (evidence: `README.md`)
- Image commands → Image saving: saves results (evidence: `README.md`)
- Saved image preview → Terminal image rendering: renders saved image (evidence: `pkg/custom/preview_saved_image.go`)
- Terminal image rendering → Image font gallery: uses gallery (evidence: `internal/terminalimage/font.go`)
- Terminal image rendering → Image font processing: uses font processing (evidence: `internal/terminalimage/font.go`)
- Image font gallery → Image font processing: encodes images (evidence: `internal/imagegallery/gallery.go`)
- Image commands → Preview preferences: uses preferences
