How justlovemaki/gemini-cli-2-api works
Project Type and Purpose
• This is a backend‐only Node.js proxy service that wraps the Google Gemini CLI and exposes both the native Gemini API (v1beta) and an OpenAI‐compatible API (v1) over HTTP.
• Its goal is to let any client (e.g., curl, LobeChat, NextChat, VS Code plugin) talk to Gemini as if it were a local OpenAI‐style REST API, handling OAuth, token refresh, request/response translation, streaming, logging, and API‐key validation.
File Structure Analysis
• Only two JS files in the root:
• gemini-api-server.js – the entry point, HTTP server, request router, CLI invocation orchestration, OpenAI‐ and Gemini‐path handlers, CLI flags, logging setup.
• gemini-core.js – the “heart” module: auth flow, token store, CLI or Google Cloud API invocation, format‐conversion between OpenAI↔Gemini, prompt log writer, streaming.
• package.json + package-lock.json define dependencies (google-auth-library, uuid) and set "type":"module".
• No database or frontend; everything runs in one Node.js process**.
Key Architecture Insights from README
• Single HTTP server listens on configurable host/port.
• Supports three API‐key modes: bearer token, query param, x-goog-api-key.
• OAuth token storage on disk, auto‐refresh.
• Two logical API layers:
• /v1/... for OpenAI compatibility (models, chat/completions, streaming)
• /v1beta/... for native Gemini (listModels, generateContent, streamGenerateContent)
• Logging subsystem captures and persists prompts.
• Extensibility hooks: system‐prompt injection, caching, filtering.