### Install and Start gcli2api on Linux Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Commands to install and start the service on Linux systems. ```bash curl -o install.sh "https://raw.githubusercontent.com/su-kaka/gcli2api/refs/heads/master/install.sh" && chmod +x install.sh && ./install.sh ``` ```bash cd gcli2api bash start.sh ``` -------------------------------- ### Install and Start gcli2api on macOS Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Commands to install and start the service on macOS. ```bash curl -o darwin-install.sh "https://raw.githubusercontent.com/su-kaka/gcli2api/refs/heads/master/darwin-install.sh" && chmod +x darwin-install.sh && ./darwin-install.sh ``` ```bash cd gcli2api bash start.sh ``` -------------------------------- ### Install and Start gcli2api on Windows Source: https://github.com/su-kaka/gcli2api/blob/master/README.md PowerShell command to install the service on Windows, followed by instructions to start it. ```powershell iex (iwr "https://raw.githubusercontent.com/su-kaka/gcli2api/refs/heads/master/install.ps1" -UseBasicParsing).Content ``` ```text 双击执行 start.bat ``` -------------------------------- ### Install and Start gcli2api on Termux Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Commands to download the installation script and start the service in a Termux environment. ```bash curl -o termux-install.sh "https://raw.githubusercontent.com/su-kaka/gcli2api/refs/heads/master/termux-install.sh" && chmod +x termux-install.sh && ./termux-install.sh ``` ```bash cd gcli2api bash termux-start.sh ``` -------------------------------- ### Docker Setup Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Instructions for setting up gcli2api using Docker and Docker Compose. ```APIDOC ## Docker Run Example ### Description Run gcli2api as a Docker container with MongoDB URI and API password. ### Method `docker run` ### Endpoint `ghcr.io/su-kaka/gcli2api:latest` ### Parameters #### Environment Variables - **MONGODB_URI** (string) - Required - MongoDB connection string. - **API_PASSWORD** (string) - Required - Password for API access. - **PORT** (integer) - Optional - Service port (default: 7861). ### Request Example ```bash docker run -d --name gcli2api \ -e MONGODB_URI="mongodb+srv://user:pass@cluster.mongodb.net/gcli2api" \ -e API_PASSWORD=your_password \ -p 7861:7861 \ ghcr.io/su-kaka/gcli2api:latest ``` ## Docker Compose Example ### Description Set up gcli2api and MongoDB using Docker Compose. ### Method `docker-compose up` ### Endpoint `docker-compose.yml` ### Request Example ```yaml version: '3.8' services: mongodb: image: mongo:7 container_name: gcli2api-mongodb restart: unless-stopped environment: MONGO_INITDB_ROOT_USERNAME: admin MONGO_INITDB_ROOT_PASSWORD: password123 volumes: - mongodb_data:/data/db ports: - "27017:27017" gcli2api: image: ghcr.io/su-kaka/gcli2api:latest container_name: gcli2api restart: unless-stopped depends_on: - mongodb environment: - MONGODB_URI=mongodb://admin:password123@mongodb:27017/admin - MONGODB_DATABASE=gcli2api - API_PASSWORD=your_api_password - PORT=7861 ports: - "7861:7861" volumes: mongodb_data: ``` ``` -------------------------------- ### Run gcli2api with MongoDB using Docker Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Deploy gcli2api with MongoDB integration using Docker. This example shows a single-instance MongoDB setup and connection to MongoDB Atlas. ```bash # 单机 MongoDB 部署 docker run -d --name gcli2api \ -e MONGODB_URI="mongodb://mongodb:27017" \ -e API_PASSWORD=your_password \ --network your_network \ ghcr.io/su-kaka/gcli2api:latest # 使用 MongoDB Atlas docker run -d --name gcli2api \ -e MONGODB_URI="mongodb+srv://user:pass@cluster.mongodb.net/gcli2api" \ -e API_PASSWORD=your_password \ -p 7861:7861 \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Authentication API - Start Antigravity Mode Auth Source: https://context7.com/su-kaka/gcli2api/llms.txt Begin the authentication flow specifically for Antigravity mode. ```bash curl -X POST "http://127.0.0.1:7861/auth/start" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{"mode": "antigravity"}' ``` -------------------------------- ### Start Docker Compose Services Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Command to start the services defined in your docker-compose.yml file in detached mode. ```bash docker-compose up -d ``` -------------------------------- ### Start gcli2api with MongoDB Support Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Run the gcli2api application. It automatically detects and uses the MongoDB configuration if MONGODB_URI is set. ```bash # 应用会自动检测 MongoDB 配置并使用 MongoDB 存储 python web.py ``` -------------------------------- ### Python SDK Integration Source: https://context7.com/su-kaka/gcli2api/llms.txt Example of connecting to GCLI2API using the Google GenAI Python SDK for text and image generation. ```python from io import BytesIO from PIL import Image from google.genai import Client from google.genai.types import HttpOptions from google.genai import types # 创建客户端连接到 GCLI2API client = Client( api_key="pwd", http_options=HttpOptions(base_url="http://127.0.0.1:7861"), ) # 文本生成 response = client.models.generate_content( model="gemini-2.5-pro", contents=["请解释什么是机器学习"], ) print(response.text) # 图像生成(Antigravity 模式) prompt = "画一只可爱的猫咪在阳光下玩耍" response = client.models.generate_content( model="gemini-3.1-flash-image", contents=[prompt], config=types.GenerateContentConfig( image_config=types.ImageConfig( aspect_ratio="16:9", # 横屏比例 ) ) ) # 处理响应 for part in response.candidates[0].content.parts: if part.text is not None: print(part.text) elif part.inline_data is not None: # 保存生成的图像 image = Image.open(BytesIO(part.inline_data.data)) image.save("generated_image.png") print("图像已保存到 generated_image.png") ``` -------------------------------- ### Authentication API - Start OAuth Flow (GCLI Mode) Source: https://context7.com/su-kaka/gcli2api/llms.txt Initiate the OAuth authentication process for GCLI mode, requiring a project ID. Returns an authorization URL and state. ```bash curl -X POST "http://127.0.0.1:7861/auth/start" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "project_id": "my-project-id", "mode": "geminicli" }' ``` -------------------------------- ### Docker Deployment with Separate Passwords Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example of deploying gcli2api using Docker with separate passwords for API and panel access. The PORT environment variable is also specified. ```bash docker run -d --name gcli2api \ -e API_PASSWORD=my_api_password \ -e PANEL_PASSWORD=my_panel_password \ -e PORT=7861 \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Antigravity Claude Endpoint Request Source: https://github.com/su-kaka/gcli2api/blob/master/README.md This example demonstrates how to make a request to the Antigravity Claude compatible endpoint. It requires an API key and specifies the Anthropic version. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/messages" \ -H "x-api-key: your_api_password" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-5", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello"} ] }' ``` -------------------------------- ### Thinking Model Response Example Source: https://context7.com/su-kaka/gcli2api/llms.txt Example response structure for thinking models, including both the final answer and the reasoning process. ```json { "choices": [{ "message": { "role": "assistant", "content": "解: x = -2 或 x = -3", "reasoning_content": "让我分析这个二次方程...\n首先,我需要找到两个数..." }, "finish_reason": "stop" }] } ``` -------------------------------- ### OpenAI-Compatible API Response Example Source: https://context7.com/su-kaka/gcli2api/llms.txt A JSON structure representing the model list response format. ```json { "object": "list", "data": [ {"id": "gemini-2.5-pro", "object": "model", "owned_by": "google"}, {"id": "gemini-2.5-pro-high", "object": "model", "owned_by": "google"}, {"id": "gemini-2.5-pro-search", "object": "model", "owned_by": "google"}, {"id": "gemini-3-pro-preview", "object": "model", "owned_by": "google"} ] } ``` -------------------------------- ### Docker Deployment with Common Password Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example of deploying gcli2api using Docker with a single common password for API and panel access. Ensure the PORT environment variable is set. ```bash docker run -d --name gcli2api \ -e PASSWORD=mypassword \ -e PORT=7861 \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Interact with Gemini Native Endpoints Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Examples of using curl to interact with the Gemini-native API using different authentication methods. ```bash # x-goog-api-keyヘッダーを使用 curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-pro:generateContent" \ -H "x-goog-api-key: your_api_password" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ] }' # URLパラメータを使用 curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-pro:streamGenerateContent?key=your_api_password" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ] }' ``` -------------------------------- ### Claude API Format with System Parameter (JSON) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example JSON payload for the Claude API format endpoint, including the system parameter for setting assistant behavior. Supports standard Claude parameters. ```json { "model": "gemini-2.5-pro", "max_tokens": 1024, "system": "You are a helpful assistant", "messages": [ {"role": "user", "content": "Hello"} ] } ``` -------------------------------- ### Run gcli2api with Separate Passwords on Docker Mac Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Configure gcli2api on Docker Mac with separate API and panel passwords. This example includes port mapping and volume mounting for persistent data. ```bash docker run -d \ --name gcli2api \ -p 7861:7861 \ -p 8080:8080 \ -e API_PASSWORD=api_pwd \ -e PANEL_PASSWORD=panel_pwd \ -e PORT=7861 \ -v $(pwd)/data/creds:/app/creds \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Configure MongoDB URI for gcli2api Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Set the MONGODB_URI environment variable to connect gcli2api to a MongoDB instance. Examples include local, Atlas, and authenticated connections. ```bash # 本地 MongoDB export MONGODB_URI="mongodb://localhost:27017" # MongoDB Atlas 云服务 export MONGODB_URI="mongodb+srv://username:password@cluster.mongodb.net" # 带认证的 MongoDB export MONGODB_URI="mongodb://admin:password@localhost:27017/admin" # 可选:自定义数据库名称(默认: gcli2api) export MONGODB_DATABASE="my_gcli_db" ``` -------------------------------- ### Credentials API - Get Status List Source: https://context7.com/su-kaka/gcli2api/llms.txt Query the status of credentials, supporting pagination, filtering by status, and specifying the mode (GCLI or Antigravity). ```bash curl -X GET "http://127.0.0.1:7861/creds/status?mode=geminicli&offset=0&limit=50&status_filter=enabled" \ -H "Authorization: Bearer pwd" ``` -------------------------------- ### Antigravity OpenAI Format Request (cURL) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example cURL request for the Antigravity endpoint using OpenAI format. Authentication is via the Authorization: Bearer header. Supports streaming. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/chat/completions" \ -H "Authorization: Bearer your_api_password" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-5", "messages": [ {"role": "user", "content": "Hello"} ], "stream": true }' ``` -------------------------------- ### Gemini Native Generate Content Request (cURL) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example cURL request for generating content using the Gemini native endpoint with x-goog-api-key authentication. Ensure the Content-Type is set to application/json. ```bash curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-pro:generateContent" \ -H "x-goog-api-key: your_api_password" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ] }' ``` -------------------------------- ### Gemini API Request Body Example Source: https://github.com/su-kaka/gcli2api/blob/master/src/api/Response_example.txt Example of a request body for the Gemini API, specifying the model and content for the request. This structure is used for both streaming and non-streaming calls. ```json { "model": "gemini-2.5-flash", "request": { "contents": [ { "role": "user", "parts": [ { "text": "Hello, tell me a joke in one sentence." } ] } ] } } ``` -------------------------------- ### Gemini API Streaming Response Chunk Example Source: https://github.com/su-kaka/gcli2api/blob/master/src/api/Response_example.txt An example of a single chunk received from a streaming Gemini API response. It includes metadata and the actual text content from the model. ```json { "response": { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "Why did the scarecrow win an award? Because he was outstanding in his field." } ] }, "finishReason": "STOP" } ], "usageMetadata": { "promptTokenCount": 10, "candidatesTokenCount": 17, "totalTokenCount": 51, "trafficType": "PROVISIONED_THROUGHPUT", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 10 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 17 } ], "thoughtsTokenCount": 24 }, "modelVersion": "gemini-2.5-flash", "createTime": "2026-01-10T01:55:29.168589Z", "responseId": "kbFhaY2lCr-ZseMPqMiDmAU" }, "traceId": "55650653afd3c738" } ``` -------------------------------- ### Gemini API Non-Streaming Response Content Example Source: https://github.com/su-kaka/gcli2api/blob/master/src/api/Response_example.txt Example of the content part of a non-streaming Gemini API response. This shows the structure of the model's generated text within the response. ```json { "response": { "candidates": [ { "content": { "role": "model", "parts": [ { ``` -------------------------------- ### Configure MongoDB Connection Strings Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Set environment variables to optimize MongoDB connections, including pooling, replica sets, and read preferences. ```bash # コネクションプールとタイムアウト設定 export MONGODB_URI="mongodb://localhost:27017?maxPoolSize=10&serverSelectionTimeoutMS=5000" # レプリカセット設定 export MONGODB_URI="mongodb://host1:27017,host2:27017,host3:27017/gcli2api?replicaSet=myReplicaSet" # リード・ライト分離設定 export MONGODB_URI="mongodb://localhost:27017/gcli2api?readPreference=secondaryPreferred" ``` -------------------------------- ### Environment Variables Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Configuration options available via environment variables. ```APIDOC ## Environment Variables ### Basic Settings - **PORT**: Service port (default: 7861) - **HOST**: Server listen address (default: 0.0.0.0) ### Password Settings - **API_PASSWORD**: Password for chat API access (overrides PASSWORD if set). - **PANEL_PASSWORD**: Password for control panel access (overrides PASSWORD if set). - **PASSWORD**: Common password, overrides API_PASSWORD and PANEL_PASSWORD if set (default: pwd). ### Performance and Stability - **RETRY_429_ENABLED**: Enable automatic retries for 429 errors (default: true). - **RETRY_429_MAX_RETRIES**: Maximum number of retries for 429 errors (default: 3). - **RETRY_429_INTERVAL**: Retry interval for 429 errors in seconds (default: 1.0). - **ANTI_TRUNCATION_MAX_ATTEMPTS**: Maximum retry attempts for anti-truncation (default: 3). ### Network and Proxy Settings - **PROXY**: HTTP/HTTPS proxy address (format: `http://host:port`). - **OAUTH_PROXY_URL**: OAuth authentication proxy endpoint. - **GOOGLEAPIS_PROXY_URL**: Google APIs proxy endpoint. - **METADATA_SERVICE_URL**: Metadata service proxy endpoint. ### Automation Settings - **AUTO_BAN**: Enable automatic credential banning (default: true). - **AUTO_LOAD_ENV_CREDS**: Automatically load credentials from environment variables on startup (default: false). ### Compatibility Settings - **COMPATIBILITY_MODE**: Enable compatibility mode, converting system messages to user messages (default: false). ### Log Settings - **LOG_LEVEL**: Log level (DEBUG/INFO/WARNING/ERROR, default: INFO). - **LOG_FILE**: Log file path (default: log.txt). ### Storage Settings #### SQLite Settings (Default) - No configuration needed; uses local SQLite database automatically. - Database file is created in the project directory. #### MongoDB Settings (Optional Cloud Storage) - **MONGODB_URI**: MongoDB connection string (enables MongoDB mode when set). - **MONGODB_DATABASE**: MongoDB database name (default: gcli2api). ``` -------------------------------- ### Run gcli2api with Password Configurations Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Deploy the container using either a common password or specific API and panel passwords. ```bash # 共通パスワードを使用 docker run -d --name gcli2api \ -e PASSWORD=mypassword \ -e PORT=7861 \ ghcr.io/su-kaka/gcli2api:latest # 個別パスワードを使用 docker run -d --name gcli2api \ -e API_PASSWORD=my_api_password \ -e PANEL_PASSWORD=my_panel_password \ -e PORT=7861 \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Authentication API - Complete Auth from Callback URL Source: https://context7.com/su-kaka/gcli2api/llms.txt Finalize authentication using a full callback URL, including code and state parameters. ```bash curl -X POST "http://127.0.0.1:7861/auth/callback-url" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "callback_url": "http://localhost:8080/callback?code=xxx&state=yyy", "mode": "geminicli" }' ``` -------------------------------- ### Docker Deployment Commands Source: https://context7.com/su-kaka/gcli2api/llms.txt Various Docker run commands and a Docker Compose configuration for deploying GCLI2API. ```bash # 基础部署(使用通用密码) docker run -d --name gcli2api \ --network host \ -e PASSWORD=pwd \ -e PORT=7861 \ -v $(pwd)/data/creds:/app/creds \ ghcr.io/su-kaka/gcli2api:latest # 使用分离密码(API 和面板分开) docker run -d --name gcli2api \ --network host \ -e API_PASSWORD=api_pwd \ -e PANEL_PASSWORD=panel_pwd \ -e PORT=7861 \ -v $(pwd)/data/creds:/app/creds \ ghcr.io/su-kaka/gcli2api:latest # macOS 部署(端口映射模式) docker run -d --name gcli2api \ -p 7861:7861 \ -p 8080:8080 \ -e PASSWORD=pwd \ -e PORT=7861 \ -v "$(pwd)/data/creds":/app/creds \ ghcr.io/su-kaka/gcli2api:latest # 使用 MongoDB 存储 docker run -d --name gcli2api \ -e MONGODB_URI="mongodb://admin:password@mongodb:27017/admin" \ -e MONGODB_DATABASE="gcli2api" \ -e API_PASSWORD=your_password \ -p 7861:7861 \ ghcr.io/su-kaka/gcli2api:latest # Docker Compose 完整配置 cat > docker-compose.yml << 'EOF' version: '3.8' services: mongodb: image: mongo:7 container_name: gcli2api-mongodb restart: unless-stopped environment: MONGO_INITDB_ROOT_USERNAME: admin MONGO_INITDB_ROOT_PASSWORD: password123 volumes: - mongodb_data:/data/db ports: - "27017:27017" gcli2api: image: ghcr.io/su-kaka/gcli2api:latest container_name: gcli2api restart: unless-stopped depends_on: - mongodb environment: - MONGODB_URI=mongodb://admin:password123@mongodb:27017/admin - MONGODB_DATABASE=gcli2api - API_PASSWORD=your_api_password - PORT=7861 ports: - "7861:7861" volumes: mongodb_data: EOF docker-compose up -d ``` -------------------------------- ### Configuration Management API Source: https://context7.com/su-kaka/gcli2api/llms.txt Endpoints for retrieving and updating system configurations with hot-reload support. ```bash curl -X GET "http://127.0.0.1:7861/config/get" \ -H "Authorization: Bearer pwd" ``` ```bash curl -X POST "http://127.0.0.1:7861/config/save" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "config": { "retry_429_enabled": true, "retry_429_max_retries": 5, "retry_429_interval": 1.5, "anti_truncation_max_attempts": 5, "compatibility_mode_enabled": false, "return_thoughts_to_frontend": true, "keepalive_url": "https://example.com/keepalive", "keepalive_interval": 300 } }' ``` -------------------------------- ### Configuration Management API Source: https://context7.com/su-kaka/gcli2api/llms.txt APIs for retrieving and saving system configurations. Supports hot-swapping of some configuration items, with environment variables taking precedence over database configurations. ```APIDOC ## GET /config/get ### Description Retrieves the current system configuration. ### Method GET ### Endpoint /config/get ### Request Example ```bash curl -X GET "http://127.0.0.1:7861/config/get" \ -H "Authorization: Bearer pwd" ``` ### Response #### Success Response (200) - **config** (object) - The current configuration settings. - **host** (string) - The host address. - **port** (integer) - The port number. - **api_password** (string) - API password. - **panel_password** (string) - Panel password. - **auto_ban_enabled** (boolean) - Whether auto-ban is enabled. - **retry_429_enabled** (boolean) - Whether retrying 429 errors is enabled. - **retry_429_max_retries** (integer) - Maximum retries for 429 errors. - **retry_429_interval** (number) - Interval for retrying 429 errors. - **anti_truncation_max_attempts** (integer) - Maximum attempts for anti-truncation. - **compatibility_mode_enabled** (boolean) - Whether compatibility mode is enabled. - **return_thoughts_to_frontend** (boolean) - Whether to return thoughts to the frontend. - **keepalive_url** (string) - URL for keep-alive checks. - **keepalive_interval** (integer) - Interval for keep-alive checks. - **env_locked** (array of strings) - Configuration items locked by environment variables. #### Response Example ```json { "config": { "host": "0.0.0.0", "port": 7861, "api_password": "pwd", "panel_password": "pwd", "auto_ban_enabled": true, "retry_429_enabled": true, "retry_429_max_retries": 5, "retry_429_interval": 1.0, "anti_truncation_max_attempts": 3, "compatibility_mode_enabled": false, "return_thoughts_to_frontend": true, "keepalive_url": "", "keepalive_interval": 60 }, "env_locked": ["PORT", "PASSWORD"] } ``` ``` ```APIDOC ## POST /config/save ### Description Saves the system configuration. ### Method POST ### Endpoint /config/save ### Parameters #### Request Body - **config** (object) - Required - The configuration object to save. Can include fields like: - **retry_429_enabled** (boolean) - **retry_429_max_retries** (integer) - **retry_429_interval** (number) - **anti_truncation_max_attempts** (integer) - **compatibility_mode_enabled** (boolean) - **return_thoughts_to_frontend** (boolean) - **keepalive_url** (string) - **keepalive_interval** (integer) ### Request Example ```bash curl -X POST "http://127.0.0.1:7861/config/save" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "config": { "retry_429_enabled": true, "retry_429_max_retries": 5, "retry_429_interval": 1.5, "anti_truncation_max_attempts": 5, "compatibility_mode_enabled": false, "return_thoughts_to_frontend": true, "keepalive_url": "https://example.com/keepalive", "keepalive_interval": 300 } }' ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. - **saved_config** (object) - The configuration that was saved. #### Response Example ```json {"message": "配置保存成功", "saved_config": {...}} ``` ``` -------------------------------- ### Enable Compatibility Mode Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Set this environment variable to enable compatibility mode, which converts system messages to user messages for better compatibility with certain clients. ```bash # 启用兼容性模式 export COMPATIBILITY_MODE=true ``` -------------------------------- ### Run gcli2api with Separate Passwords (Docker) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Deploy gcli2api with distinct passwords for API and panel access. This enhances security for production environments. Mount the data directory for credential storage. ```bash docker run -d --name gcli2api --network host -e API_PASSWORD=api_pwd -e PANEL_PASSWORD=panel_pwd -e PORT=7861 -v $(pwd)/data/creds:/app/creds ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Authentication API - User Login Source: https://context7.com/su-kaka/gcli2api/llms.txt Authenticate users by providing a password. Returns a token upon successful login. ```bash curl -X POST "http://127.0.0.1:7861/auth/login" \ -H "Content-Type: application/json" \ -d '{"password": "pwd"}' ``` -------------------------------- ### Claude API Format Request (cURL) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example cURL request for interacting with the Claude API format endpoint. Supports x-api-key or Authorization: Bearer header for authentication. Specify the anthropic-version header. ```bash curl -X POST "http://127.0.0.1:7861/v1/messages" \ -H "x-api-key: your_api_password" \ -H "anthropic-version: 2023-06-01" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-2.5-pro", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Hello, Claude!"} ] }' ``` -------------------------------- ### Deploy gcli2api with Docker Compose Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Orchestrate gcli2api and a local MongoDB instance using Docker Compose. ```yaml version: '3.8' services: mongodb: image: mongo:7 container_name: gcli2api-mongodb restart: unless-stopped environment: MONGO_INITDB_ROOT_USERNAME: admin MONGO_INITDB_ROOT_PASSWORD: password123 volumes: - mongodb_data:/data/db ports: - "27017:27017" gcli2api: image: ghcr.io/su-kaka/gcli2api:latest container_name: gcli2api restart: unless-stopped depends_on: - mongodb environment: - MONGODB_URI=mongodb://admin:password123@mongodb:27017/admin - MONGODB_DATABASE=gcli2api - API_PASSWORD=your_api_password - PORT=7861 ports: - "7861:7861" volumes: mongodb_data: ``` -------------------------------- ### Antigravity API - OpenAI Format Source: https://context7.com/su-kaka/gcli2api/llms.txt Use this endpoint to interact with Antigravity services using the OpenAI API format. Supports streaming responses. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/chat/completions" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "model": "claude-sonnet-4-5", "messages": [ {"role": "user", "content": "Hello"} ], "stream": true }' ``` -------------------------------- ### Antigravity Gemini Format Non-Streaming Request (cURL) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example cURL request for the Antigravity endpoint using Gemini format for non-streaming content generation. Supports x-goog-api-key or URL parameter key authentication. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/claude-sonnet-4-5:generateContent" \ -H "x-goog-api-key: your_api_password" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ], "generationConfig": { "temperature": 0.7 } }' ``` -------------------------------- ### Authentication API - Handle OAuth Callback Source: https://context7.com/su-kaka/gcli2api/llms.txt Process the callback from an OAuth provider for GCLI mode authentication. ```bash curl -X POST "http://127.0.0.1:7861/auth/callback" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "project_id": "my-project-id", "mode": "geminicli" }' ``` -------------------------------- ### Gemini Native Stream Generate Content Request (cURL) Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Example cURL request for streaming content generation using the Gemini native endpoint with URL parameter key authentication. Ensure the Content-Type is set to application/json. ```bash curl -X POST "http://127.0.0.1:7861/v1/models/gemini-2.5-pro:streamGenerateContent?key=your_api_password" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ] }' ``` -------------------------------- ### Antigravity API - Gemini Format Source: https://context7.com/su-kaka/gcli2api/llms.txt Interact with Antigravity services using the Gemini API format. Allows configuration of generation parameters like temperature. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/models/gemini-2.5-flash:generateContent" \ -H "x-goog-api-key: pwd" \ -H "Content-Type: application/json" \ -d '{ "contents": [ {"role": "user", "parts": [{"text": "Hello"}]} ], "generationConfig": {"temperature": 0.7} }' ``` -------------------------------- ### Docker Compose Configuration for gcli2api Source: https://github.com/su-kaka/gcli2api/blob/master/README.md A sample docker-compose.yml file to deploy gcli2api. It supports both universal and separate password configurations and includes a healthcheck. ```yaml version: '3.8' services: gcli2api: image: ghcr.io/su-kaka/gcli2api:latest container_name: gcli2api restart: unless-stopped network_mode: host environment: # 使用通用密码(推荐用于简单部署) - PASSWORD=pwd - PORT=7861 # 或使用分离密码(推荐用于生产环境) # - API_PASSWORD=your_api_password # - PANEL_PASSWORD=your_panel_password volumes: - ./data/creds:/app/creds healthcheck: test: ["CMD-SHELL", "python -c \"import sys, urllib.request, os; port = os.environ.get('PORT', '7861'); req = urllib.request.Request(f'http://localhost:{port}/v1/models', headers={'Authorization': 'Bearer ' + os.environ.get('PASSWORD', 'pwd')}); sys.exit(0 if urllib.request.urlopen(req, timeout=5).getcode() == 200 else 1)\"] interval: 30s timeout: 10s retries: 3 start_period: 40s ``` -------------------------------- ### Antigravity API - Chat Completions (OpenAI Format) Source: https://context7.com/su-kaka/gcli2api/llms.txt Accesses Google Antigravity services using the OpenAI format for chat completions. Supports Claude and Gemini models and image generation. ```APIDOC ## POST /antigravity/v1/chat/completions ### Description Sends a chat completion request to the Antigravity API using OpenAI format. Supports various models and streaming. ### Method POST ### Endpoint `/antigravity/v1/chat/completions` ### Request Body - **model** (string) - Required - The model to use for generation (e.g., "claude-sonnet-4-5", "gemini-3.1-flash-image-4k-16x9"). - **messages** (array) - Required - An array of message objects representing the conversation history. - **role** (string) - Required - The role of the message sender (e.g., "user", "assistant"). - **content** (string) - Required - The content of the message. - **stream** (boolean) - Optional - Whether to stream the response. ### Request Example ```json { "model": "claude-sonnet-4-5", "messages": [ {"role": "user", "content": "Hello"} ], "stream": true } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the response. - **type** (string) - The type of the response. - **role** (string) - The role of the sender (e.g., "assistant"). - **content** (array) - The content of the message, potentially with different types. - **type** (string) - The type of content (e.g., "text"). - **text** (string) - The text content. - **model** (string) - The model used for the response. - **stop_reason** (string) - The reason the generation stopped. - **usage** (object) - Token usage information. - **input_tokens** (integer) - Number of input tokens. - **output_tokens** (integer) - Number of output tokens. #### Response Example ```json { "id": "msg_xxx", "type": "message", "role": "assistant", "content": [{"type": "text", "text": "你好!很高兴见到你..."}], "model": "gemini-2.5-pro", "stop_reason": "end_turn", "usage": {"input_tokens": 10, "output_tokens": 50} } ``` ``` -------------------------------- ### Antigravity API - Image Generation Source: https://context7.com/su-kaka/gcli2api/llms.txt Use the OpenAI format endpoint for image generation with Antigravity, specifying image-capable models. ```bash curl -X POST "http://127.0.0.1:7861/antigravity/v1/chat/completions" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-3.1-flash-image-4k-16x9", "messages": [{"role": "user", "content": "画一只可爱的猫"}] }' ``` -------------------------------- ### Special Model Feature - Pseudo-Streaming Mode Source: https://context7.com/su-kaka/gcli2api/llms.txt Utilize a pseudo-streaming mode for compatibility scenarios by using models with the '-假流式' suffix. This mode still requires 'stream: true'. ```bash curl -X POST "http://127.0.0.1:7861/v1/chat/completions" \ -H "Authorization: Bearer pwd" \ -H "Content-Type: application/json" \ -d '{ "model": "gemini-2.5-pro-假流式", "messages": [{"role": "user", "content": "Hello"}], "stream": true }' ``` -------------------------------- ### Advanced MongoDB Connection Options Source: https://github.com/su-kaka/gcli2api/blob/master/README.md Configure advanced MongoDB connection parameters via the MONGODB_URI, such as connection pooling, timeouts, replica sets, and read preferences. ```bash # 连接池和超时配置 export MONGODB_URI="mongodb://localhost:27017?maxPoolSize=10&serverSelectionTimeoutMS=5000" # 副本集配置 export MONGODB_URI="mongodb://host1:27017,host2:27017,host3:27017/gcli2api?replicaSet=myReplicaSet" # 读写分离配置 export MONGODB_URI="mongodb://localhost:27017/gcli2api?readPreference=secondaryPreferred" ``` -------------------------------- ### Deploy gcli2api with MongoDB Atlas Source: https://github.com/su-kaka/gcli2api/blob/master/docs/README_JA.md Run the gcli2api container using a MongoDB Atlas connection string. ```bash docker run -d --name gcli2api \ -e MONGODB_URI="mongodb+srv://user:pass@cluster.mongodb.net/gcli2api" \ -e API_PASSWORD=your_password \ -p 7861:7861 \ ghcr.io/su-kaka/gcli2api:latest ``` -------------------------------- ### Environment Variable Configuration Source: https://context7.com/su-kaka/gcli2api/llms.txt A comprehensive list of environment variables for configuring GCLI2API server, security, performance, and storage. ```bash # 服务器基础配置 export PORT=7861 # 服务端口(默认:7861) export HOST=0.0.0.0 # 监听地址(默认:0.0.0.0) export WORKERS=1 # Worker 数量(默认:1) # 密码配置 export PASSWORD=pwd # 通用密码(默认:pwd) export API_PASSWORD=api_pwd # API 访问密码(覆盖 PASSWORD) export PANEL_PASSWORD=panel_pwd # 控制面板密码(覆盖 PASSWORD) # 性能和稳定性配置 export RETRY_429_ENABLED=true # 启用 429 错误自动重试(默认:true) export RETRY_429_MAX_RETRIES=5 # 429 错误最大重试次数(默认:5) export RETRY_429_INTERVAL=1.0 # 429 错误重试间隔秒数(默认:1.0) export ANTI_TRUNCATION_MAX_ATTEMPTS=3 # 抗截断最大重试次数(默认:3) # 自动封禁配置 export AUTO_BAN=true # 启用凭证自动封禁(默认:true) export AUTO_BAN_ERROR_CODES=403 # 触发封禁的错误码(逗号分隔) # 兼容性配置 export COMPATIBILITY_MODE=false # 兼容性模式(默认:false) export RETURN_THOUGHTS_TO_FRONTEND=true # 返回思维链(默认:true) # 网络代理配置 export PROXY=http://proxy:8080 # HTTP/HTTPS 代理 export OAUTH_PROXY_URL=https://oauth2.googleapis.com # OAuth 代理 export GOOGLEAPIS_PROXY_URL=https://www.googleapis.com # Google APIs 代理 # 存储配置 export MONGODB_URI=mongodb://localhost:27017 # MongoDB 连接(可选) export MONGODB_DATABASE=gcli2api # MongoDB 数据库名(默认:gcli2api) # 日志配置 export LOG_LEVEL=INFO # 日志级别(DEBUG/INFO/WARNING/ERROR) export LOG_FILE=log.txt # 日志文件路径 # 保活配置 export KEEPALIVE_URL= # 保活 URL(留空禁用) export KEEPALIVE_INTERVAL=60 # 保活间隔秒数(默认:60) ```