leeguooooo/agent-cli-to-api

48 stars · Last commit 2026-05-26

Expose agent CLIs (Codex, Cursor Agent, Claude Code, Gemini) as an OpenAI-compatible /v1 API gateway.

README preview

# agent-cli-to-api

Expose popular **agent CLIs** as a small **OpenAI-compatible** HTTP API (`/v1/*`).

Works great as a local gateway (localhost) or behind a reverse proxy.

Think of it as **LiteLLM for agent CLIs**: you point existing OpenAI SDKs/tools at `base_url`, and choose a backend by `model`.

Supported backends:
- **OpenAI Codex** - defaults to backend `/responses` for vision and **image generation** (DALL-E / `gpt-image`-class output); falls back to `codex exec`
- **Cursor Agent** - via `cursor-agent` CLI
- **Claude Code** - via CLI or **direct API** (auto-detects `~/.claude/settings.json` config)
- **Gemini** - via CLI or CloudCode direct (set `GEMINI_USE_CLOUDCODE_API=1`)

Why this exists:
- Many tools/SDKs only speak the OpenAI API (`/v1/chat/completions`) - this lets you plug agent CLIs into that ecosystem.
- One gateway, multiple CLIs: pick a backend by `model` (with optional prefixes like `cursor:` / `claude:` / `gemini:`).
- **Expose your ChatGPT Plus / Pro subscription's image generation as an HTTP API.** No `OPENAI_API_KEY` required — the gateway reuses the OAuth token from `codex login`, lets you call `image_generation` via plain chat completions, and returns the PNG inline (data URI). See [Image generation (ChatGPT subscription)](#image-generation-chatgpt-subscription).

## Table of Contents

View full repository on GitHub →