### Rebuild Script Usage Example for Windows Packaging Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This example demonstrates how to use the `rebuild.ps1` script in PowerShell to perform a local Windows build of the Tauri application, creating both NSIS installer and portable versions. It also shows how to use the `-AllPlatforms` flag to trigger GitHub workflows for cross-platform releases, including specifying Git references, release tags, and GitHub tokens. ```powershell # 本地 Windows 构建 pwsh -NoLogo -NoProfile -File scripts/rebuild.ps1 -Bundle nsis -CleanDist -Portable # 触发 release workflow(并下载工件) pwsh -NoLogo -NoProfile -File scripts/rebuild.ps1 ` -AllPlatforms ` -GitRef main ` -ReleaseTag v0.0.9 ` -GithubToken ``` -------------------------------- ### Start Service and Initialize RPC Call (Bash) Source: https://context7.com/qxcnm/codex-manager/llms.txt Demonstrates how to start the CodexManager service using Docker Compose and then perform an RPC call to initialize the service. The initialization returns the server name and version, and it's a prerequisite for other API calls. Requires a valid RPC token. ```bash # Start service (Docker Compose method) docker compose -f docker/docker-compose.yml up --build # Initialize service RPC call curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "initialize" }' # Response example # { # "id": 1, # "result": { # "server_name": "codexmanager-service", # "version": "0.1.4" # } # } ``` -------------------------------- ### Codex Manager Environment File Example Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This is an example of an environment file (e.g., codexmanager.env) that can be placed in the same directory as the executable. It's used to configure service addresses, upstream URLs, polling intervals, and other runtime settings. Changes to this file require a restart of the corresponding process. ```dotenv # codexmanager.env / CodexManager.env / .env CODEXMANAGER_SERVICE_ADDR=localhost:48760 CODEXMANAGER_WEB_ADDR=localhost:48761 CODEXMANAGER_UPSTREAM_BASE_URL=https://chatgpt.com/backend-api/codex CODEXMANAGER_USAGE_POLL_INTERVAL_SECS=600 CODEXMANAGER_GATEWAY_KEEPALIVE_INTERVAL_SECS=180 # 可选:后台任务总开关 # CODEXMANAGER_USAGE_POLLING_ENABLED=1 # CODEXMANAGER_GATEWAY_KEEPALIVE_ENABLED=1 # CODEXMANAGER_TOKEN_REFRESH_POLLING_ENABLED=1 # 可选:固定 RPC token 方便外部工具长期复用 # CODEXMANAGER_RPC_TOKEN=replace_with_your_static_token ``` -------------------------------- ### Start OAuth Login Source: https://context7.com/qxcnm/codex-manager/llms.txt Initiates the OAuth authorization flow, returning an authorization URL and a login session ID. Supports automatic browser opening or manual link copying. ```APIDOC ## POST /rpc ### Description Initiates the OAuth authorization flow, returning an authorization URL and a login session ID. Supports automatic browser opening or manual link copying. ### Method POST ### Endpoint /rpc ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **X-CodexManager-Rpc-Token** (string) - Required - Your RPC token #### Request Body - **jsonrpc** (string) - Required - `"2.0"` - **id** (integer) - Required - Request ID - **method** (string) - Required - `"account/login/start"` - **params** (object) - Required - Parameters for starting the login process - **type** (string) - Required - The type of login, e.g., `"chatgpt"` - **openBrowser** (boolean) - Optional - Whether to automatically open the browser - **note** (string) - Optional - A note for the login session - **groupName** (string) - Optional - The group name to assign the account to ### Request Example ```json { "jsonrpc": "2.0", "id": 7, "method": "account/login/start", "params": { "type": "chatgpt", "openBrowser": true, "note": "主账号", "groupName": "生产组" } } ``` ### Response #### Success Response (200) - **id** (integer) - Request ID - **result** (object) - Result of the login start operation - **authUrl** (string) - The URL for OAuth authorization - **loginId** (string) - The ID of the login session - **loginType** (string) - The type of login initiated - **issuer** (string) - The issuer of the authorization - **clientId** (string) - The client ID for the authorization - **redirectUri** (string) - The redirect URI for the authorization #### Response Example ```json { "id": 7, "result": { "authUrl": "https://auth.openai.com/authorize?client_id=app_EMoamEEZ73f0CkXaXp7hrann&...", "loginId": "login_abc123", "loginType": "chatgpt", "issuer": "https://auth.openai.com", "clientId": "app_EMoamEEZ73f0CkXaXp7hrann", "redirectUri": "http://localhost:1455/auth/callback" } } ``` ``` -------------------------------- ### Frontend Development Commands for CodexManager Source: https://github.com/qxcnm/codex-manager/blob/main/README.md These commands are used for developing and building the frontend of CodexManager. They cover installing dependencies, running the development server, executing tests (both unit and UI), and building the production version. ```bash pnpm -C apps install pnpm -C apps run dev pnpm -C apps run test pnpm -C apps run test:ui pnpm -C apps run build ``` -------------------------------- ### Start OAuth Login via RPC (Bash) Source: https://context7.com/qxcnm/codex-manager/llms.txt Initiates the OAuth authorization flow, returning an authorization URL and a login session ID. It supports automatically opening the browser or providing a link to copy. Parameters include the type of login, whether to open the browser, a note, and the group name. Requires a valid RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 7, "method": "account/login/start", "params": { "type": "chatgpt", "openBrowser": true, "note": "主账号", "groupName": "生产组" } }' # Response example # { # "id": 7, # "result": { # "authUrl": "https://auth.openai.com/authorize?client_id=app_EMoamEEZ73f0CkXaXp7hrann&...", # "loginId": "login_abc123", # "loginType": "chatgpt", # "issuer": "https://auth.openai.com", # "clientId": "app_EMoamEEZ73f0CkXaXp7hrann", # "redirectUri": "http://localhost:1455/auth/callback" # } # } ``` -------------------------------- ### Rust Development and Build Commands for CodexManager Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This section outlines the commands for developing and building the Rust components of CodexManager. It includes running workspace tests, building the service, web UI, and start components, as well as building the web UI with embedded assets for a single binary release. ```bash cargo test --workspace cargo build -p codexmanager-service --release cargo build -p codexmanager-web --release cargo build -p codexmanager-start --release # 发行物/容器:将前端静态资源打进 codexmanager-web(二进制单文件) pnpm -C apps run build cargo build -p codexmanager-web --release --features embedded-ui ``` -------------------------------- ### Get Today's Request Summary Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves a summary of today's requests, including token usage statistics and estimated costs. This endpoint does not require any parameters. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 29, "method": "requestlog/today_summary" }' ``` -------------------------------- ### Tauri Packaging Script for Windows Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This PowerShell script is used for packaging the Tauri application for Windows. It supports creating installer packages (NSIS) and portable versions. The script can also be used with the `-AllPlatforms` flag to trigger GitHub workflows for cross-platform releases. ```powershell pwsh -NoLogo -NoProfile -File scripts/rebuild.ps1 -Bundle nsis -CleanDist -Portable ``` -------------------------------- ### Docker Compose Deployment for CodexManager Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This snippet shows how to deploy CodexManager using Docker Compose, which is the recommended method. It starts both the service and the web UI. The service runs on port 48760 and the web UI on port 48761. ```bash docker compose -f docker/docker-compose.yml up --build ``` -------------------------------- ### Get or Set Background Tasks Configuration Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves or configures parameters for background tasks such as usage polling, gateway keepalive, and token refresh. Allows enabling/disabling and setting intervals for these tasks. ```bash # Get current configuration curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 26, "method": "gateway/backgroundTasks/get" }' # Set configuration curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 27, "method": "gateway/backgroundTasks/set", "params": { "usagePollingEnabled": true, "usagePollIntervalSecs": 600, "gatewayKeepaliveEnabled": true, "gatewayKeepaliveIntervalSecs": 180, "tokenRefreshPollingEnabled": true, "tokenRefreshPollIntervalSecs": 60 } }' ``` -------------------------------- ### Get or Set Gateway Route Strategy Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves or sets the account selection strategy for the gateway. Supports 'ordered' (sequential priority) and 'balanced' (round-robin) modes. The 'set' method requires the desired strategy. ```bash # Get current strategy curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 22, "method": "gateway/routeStrategy/get" }' # Set strategy to balanced curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 23, "method": "gateway/routeStrategy/set", "params": {"strategy": "balanced"} }' ``` -------------------------------- ### Create API Key (apikey/create) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Creates a new platform API key, allowing specification of the bound model, reasoning effort, and protocol type. Requires the RPC token and parameters for name, modelSlug, and protocolType. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 15, "method": "apikey/create", "params": { "name": "CLI 工具 Key", "modelSlug": "gpt-4o", "reasoningEffort": null, "protocolType": "openai" } }' ``` -------------------------------- ### List API Keys (apikey/list) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves summary information for all platform API keys, including bound models, protocol types, and status. Requires the RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 14, "method": "apikey/list" }' ``` -------------------------------- ### List Account Usage (account/usage/list) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Fetches a list of usage snapshots for all accounts, suitable for dashboard display and bulk monitoring. Requires the RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 11, "method": "account/usage/list" }' ``` -------------------------------- ### Complete OAuth Login (account/login/complete) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Manually submits OAuth callback parameters to complete the login process. This is useful for manual parsing when callbacks fail. It requires the RPC token and specific parameters like state, code, and redirectUri. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 9, "method": "account/login/complete", "params": { "state": "state_xyz789", "code": "auth_code_abc123", "redirectUri": "http://localhost:1455/auth/callback" } }' ``` -------------------------------- ### List Available Models (apikey/models) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Fetches a list of available models, intended for use in API key creation model selection dropdowns. Requires the RPC token and an optional boolean to refresh remote data. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 17, "method": "apikey/models", "params": { "refreshRemote": true } }' ``` -------------------------------- ### Import Accounts via RPC (Bash) Source: https://context7.com/qxcnm/codex-manager/llms.txt Imports accounts in bulk using JSON content. It automatically recognizes `tokens.*`, top-level token fields, and camelCase formats. This method is useful for migrating account data from other tools. Requires a valid RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 3, "method": "account/import", "params": { "contents": [ "{\"tokens\": {\"access_token\": \"eyJ...\", \"refresh_token\": \"rt_...\", \"id_token\": \"id_...\"}, \"user\": {\"id\": \"user-abc123\", \"email\": \"user@example.com\"}}" ] } }' # Response example # { # "id": 3, # "result": { # "ok": true, # "imported": 1, # "skipped": 0 # } # } ``` -------------------------------- ### Manual Docker Deployment for CodexManager Web UI Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This snippet shows the manual deployment of the CodexManager web UI using Docker. It builds the web UI image and runs it as a container, exposing port 48761. It's configured to connect to a service running on `host.docker.internal:48760` and includes an environment variable to prevent spawning a new service instance. The RPC token is also required. ```bash # web(需要能访问到 service) docker build -f docker/Dockerfile.web -t codexmanager-web . docker run --rm -p 48761:48761 \ -e CODEXMANAGER_WEB_NO_SPAWN_SERVICE=1 \ -e CODEXMANAGER_SERVICE_ADDR=host.docker.internal:48760 \ -e CODEXMANAGER_RPC_TOKEN=replace_with_your_token \ codexmanager-web ``` -------------------------------- ### Manual Docker Deployment for CodexManager Service Source: https://github.com/qxcnm/codex-manager/blob/main/README.md This snippet demonstrates the manual deployment of the CodexManager service using Docker. It builds the service image and runs it as a container, exposing port 48760 and mounting a volume for data persistence. An environment variable for the RPC token is also included. ```bash # service docker build -f docker/Dockerfile.service -t codexmanager-service . docker run --rm -p 48760:48760 -v codexmanager-data:/data \ -e CODEXMANAGER_RPC_TOKEN=replace_with_your_token \ codexmanager-service ``` -------------------------------- ### Service Initialization Source: https://context7.com/qxcnm/codex-manager/llms.txt Initializes the CodexManager service via RPC. This is a prerequisite for all other API calls. ```APIDOC ## POST /rpc ### Description Initializes the CodexManager service and returns server name and version information. ### Method POST ### Endpoint /rpc ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **X-CodexManager-Rpc-Token** (string) - Required - Your RPC token #### Request Body - **jsonrpc** (string) - Required - `"2.0"` - **id** (integer) - Required - Request ID - **method** (string) - Required - `"initialize"` ### Request Example ```json { "jsonrpc": "2.0", "id": 1, "method": "initialize" } ``` ### Response #### Success Response (200) - **id** (integer) - Request ID - **result** (object) - Result of the initialization - **server_name** (string) - The name of the server - **version** (string) - The version of the server #### Response Example ```json { "id": 1, "result": { "server_name": "codexmanager-service", "version": "0.1.4" } } ``` ``` -------------------------------- ### Query Account List via RPC (Bash) Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves a summary of all added accounts, including their IDs, labels, group names, and sort values. This is used for displaying the account pool list and in the management interface. Requires a valid RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 2, "method": "account/list" }' # Response example # { # "id": 2, # "result": { # "items": [ # { # "id": "user-abc123", # "label": "主账号", # "groupName": "生产组", # "sort": 0 # }, # { # "id": "user-def456", # "label": "备用账号", # "groupName": "测试组", # "sort": 1 # } # ] # } # } ``` -------------------------------- ### Tauri Packaging Scripts for Linux and macOS Source: https://github.com/qxcnm/codex-manager/blob/main/README.md These shell scripts are used for packaging the Tauri application for Linux and macOS. The Linux script supports AppImage, deb, and rpm bundles, while the macOS script supports DMG disk images. Both scripts include options for cleaning the distribution directory. ```bash ./scripts/rebuild-linux.sh --bundles "appimage,deb" --clean-dist ./scripts/rebuild-macos.sh --bundles "dmg" --clean-dist ``` -------------------------------- ### Today's Request Summary Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves today's token usage statistics and estimated costs. ```APIDOC ## POST /rpc (requestlog/today_summary) ### Description Retrieves today's token usage statistics and estimated costs. ### Method POST ### Endpoint /rpc ### Parameters #### Request Body - **jsonrpc** (string) - Required - JSON-RPC version, should be "2.0". - **id** (integer) - Required - A unique identifier for the request. - **method** (string) - Required - The method to call, should be "requestlog/today_summary". ### Request Example ```json { "jsonrpc": "2.0", "id": 29, "method": "requestlog/today_summary" } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the request. - **result** (object) - The result of the operation. - **inputTokens** (integer) - Total input tokens used today. - **cachedInputTokens** (integer) - Input tokens from cache today. - **outputTokens** (integer) - Total output tokens used today. - **reasoningOutputTokens** (integer) - Reasoning output tokens used today. - **todayTokens** (integer) - Total tokens (input + output) used today. - **estimatedCost** (number) - Estimated cost in USD for today. #### Response Example ```json { "id": 29, "result": { "inputTokens": 12500, "cachedInputTokens": 3200, "outputTokens": 8900, "reasoningOutputTokens": 0, "todayTokens": 21400, "estimatedCost": 0.215 } } ``` ``` -------------------------------- ### Read Account Usage (account/usage/read) - Bash Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves the latest usage snapshot for a specified or default account. It includes primary and secondary window usage percentages. Requires the RPC token and optionally an accountId. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 10, "method": "account/usage/read", "params": { "accountId": "user-abc123" } }' ``` -------------------------------- ### Account Import Source: https://context7.com/qxcnm/codex-manager/llms.txt Imports accounts in bulk via JSON content. Supports automatic recognition of `tokens.*`, top-level token fields, and camelCase formats. ```APIDOC ## POST /rpc ### Description Imports accounts in bulk using JSON content. It automatically recognizes `tokens.*`, top-level token fields, and camelCase formats. ### Method POST ### Endpoint /rpc ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **X-CodexManager-Rpc-Token** (string) - Required - Your RPC token #### Request Body - **jsonrpc** (string) - Required - `"2.0"` - **id** (integer) - Required - Request ID - **method** (string) - Required - `"account/import"` - **params** (object) - Required - Parameters for the import method - **contents** (array) - Required - An array of JSON strings, each representing an account to import ### Request Example ```json { "jsonrpc": "2.0", "id": 3, "method": "account/import", "params": { "contents": [ "{\"tokens\": {\"access_token\": \"eyJ...\", \"refresh_token\": \"rt_...\", \"id_token\": \"id_...\"}, \"user\": {\"id\": \"user-abc123\", \"email\": \"user@example.com\"}}" ] } } ``` ### Response #### Success Response (200) - **id** (integer) - Request ID - **result** (object) - Result of the import operation - **ok** (boolean) - Indicates if the operation was successful - **imported** (integer) - The number of accounts successfully imported - **skipped** (integer) - The number of accounts skipped during import #### Response Example ```json { "id": 3, "result": { "ok": true, "imported": 1, "skipped": 0 } } ``` ``` -------------------------------- ### JavaScript Frontend API Calls Source: https://context7.com/qxcnm/codex-manager/llms.txt Enables frontend interaction with the service through a unified API module. It automatically adapts to both Tauri desktop and browser web environments. The module provides functions for managing accounts, API keys, and handling login flows. ```javascript import { serviceAccountList, serviceAccountImport, serviceUsageRefresh, serviceApiKeyCreate, serviceApiKeyList, serviceLoginStart, serviceLoginStatus } from './api.js'; // 获取账号列表 async function loadAccounts() { try { const result = await serviceAccountList(); console.log('账号列表:', result.items); return result.items; } catch (err) { console.error('获取账号失败:', err.message); } } // 导入账号 async function importAccount(authJson) { try { const result = await serviceAccountImport([authJson]); console.log('导入成功:', result); } catch (err) { console.error('导入失败:', err.message); } } // 创建 API Key async function createApiKey() { try { const result = await serviceApiKeyCreate( 'CLI工具Key', 'gpt-4o', null, { protocolType: 'openai' } ); console.log('新建 Key:', result.key); } catch (err) { console.error('创建失败:', err.message); } } // OAuth 登录流程 async function startLogin() { const loginResult = await serviceLoginStart({ type: 'chatgpt', openBrowser: true, note: '新账号', groupName: '默认组' }); console.log('请在浏览器中完成授权:', loginResult.authUrl); // 轮询登录状态 const pollStatus = async () => { const status = await serviceLoginStatus(loginResult.loginId); if (status.status === 'completed') { console.log('登录成功,账号 ID:', status.accountId); return status.accountId; } else if (status.status === 'failed') { throw new Error('登录失败'); } // 继续轮询 await new Promise(r => setTimeout(r, 2000)); return pollStatus(); }; return pollStatus(); } ``` -------------------------------- ### OAuth Login Completion Source: https://context7.com/qxcnm/codex-manager/llms.txt Manually submits OAuth callback parameters to complete the login process. This is useful for manual parsing scenarios when the callback fails. ```APIDOC ## POST /rpc (account/login/complete) ### Description Manually submits OAuth callback parameters to complete the login process. This is useful for manual parsing scenarios when the callback fails. ### Method POST ### Endpoint /rpc ### Parameters #### Request Body - **jsonrpc** (string) - Required - JSON-RPC version, should be "2.0". - **id** (integer) - Required - A unique identifier for the request. - **method** (string) - Required - The method name, should be "account/login/complete". - **params** (object) - Required - Parameters for the method. - **state** (string) - Required - The state parameter received during the OAuth flow. - **code** (string) - Required - The authorization code received from the OAuth provider. - **redirectUri** (string) - Required - The redirect URI used in the OAuth flow. ### Request Example ```json { "jsonrpc": "2.0", "id": 9, "method": "account/login/complete", "params": { "state": "state_xyz789", "code": "auth_code_abc123", "redirectUri": "http://localhost:1455/auth/callback" } } ``` ### Response #### Success Response (200) - **id** (integer) - The ID of the request. - **result** (object) - The result of the operation. - **ok** (boolean) - Indicates if the operation was successful. #### Response Example ```json { "id": 9, "result": { "ok": true } } ``` ``` -------------------------------- ### List Gateway Request Logs Source: https://context7.com/qxcnm/codex-manager/llms.txt Queries gateway request logs, supporting keyword searches and limiting the number of results. Requires a query string and an optional limit. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 28, "method": "requestlog/list", "params": { "query": "gpt-4", "limit": 50 } }' ``` -------------------------------- ### Account List Query Source: https://context7.com/qxcnm/codex-manager/llms.txt Retrieves a summary of all added accounts, including ID, labels, group names, and sort values. ```APIDOC ## POST /rpc ### Description Retrieves a summary of all added accounts, including their ID, labels, group names, and sort values. ### Method POST ### Endpoint /rpc ### Parameters #### Headers - **Content-Type** (string) - Required - `application/json` - **X-CodexManager-Rpc-Token** (string) - Required - Your RPC token #### Request Body - **jsonrpc** (string) - Required - `"2.0"` - **id** (integer) - Required - Request ID - **method** (string) - Required - `"account/list"` ### Request Example ```json { "jsonrpc": "2.0", "id": 2, "method": "account/list" } ``` ### Response #### Success Response (200) - **id** (integer) - Request ID - **result** (object) - Result object containing the list of accounts - **items** (array) - Array of account objects - **id** (string) - The unique identifier for the account - **label** (string) - The label assigned to the account - **groupName** (string) - The name of the group the account belongs to - **sort** (integer) - The sort order value for the account #### Response Example ```json { "id": 2, "result": { "items": [ { "id": "user-abc123", "label": "主账号", "groupName": "生产组", "sort": 0 }, { "id": "user-def456", "label": "备用账号", "groupName": "测试组", "sort": 1 } ] } } ``` ``` -------------------------------- ### Environment Variable Configuration Source: https://context7.com/qxcnm/codex-manager/llms.txt Configures service parameters using environment variable files. Supports `codexmanager.env`, `CodexManager.env`, or `.env` files placed in the executable's directory. Includes settings for service addresses, upstream configuration, background tasks, routing strategies, and optional configurations like RPC tokens, proxy lists, and timeouts. ```dotenv # codexmanager.env - 放置在可执行文件同目录 # 服务地址配置 CODEXMANAGER_SERVICE_ADDR=localhost:48760 CODEXMANAGER_WEB_ADDR=localhost:48761 # 上游配置 CODEXMANAGER_UPSTREAM_BASE_URL=https://chatgpt.com/backend-api/codex # 后台任务配置 CODEXMANAGER_USAGE_POLL_INTERVAL_SECS=600 CODEXMANAGER_GATEWAY_KEEPALIVE_INTERVAL_SECS=180 CODEXMANAGER_TOKEN_REFRESH_POLL_INTERVAL_SECS=60 # 路由策略 CODEXMANAGER_ROUTE_STRATEGY=ordered # 可选:固定 RPC Token CODEXMANAGER_RPC_TOKEN=your_static_rpc_token # 可选:代理配置 CODEXMANAGER_PROXY_LIST=http://proxy1:8080,http://proxy2:8080 # 可选:超时配置 CODEXMANAGER_UPSTREAM_CONNECT_TIMEOUT_SECS=15 CODEXMANAGER_UPSTREAM_TOTAL_TIMEOUT_MS=120000 ``` -------------------------------- ### OpenAI Compatible Gateway Source: https://context7.com/qxcnm/codex-manager/llms.txt Provides an OpenAI-compatible API endpoint. You can use this gateway by replacing the `base_url` in your OpenAI SDK configurations. The gateway handles account routing, token refreshing, and failover automatically. ```APIDOC ## POST /v1/chat/completions ### Description An OpenAI-compatible endpoint for chat completions. Use this endpoint to send requests to the gateway as if you were using the OpenAI API. ### Method POST ### Endpoint /v1/chat/completions ### Parameters #### Query Parameters - **stream** (boolean) - Optional - Whether to stream the response. #### Request Body - **model** (string) - Required - The model to use for the chat completion (e.g., "gpt-4o"). - **messages** (array) - Required - A list of message objects representing the conversation history. - **role** (string) - Required - The role of the message sender (e.g., "system", "user", "assistant"). - **content** (string) - Required - The content of the message. - **temperature** (number) - Optional - Controls randomness. Lower values make output more focused and deterministic. - **max_tokens** (integer) - Optional - The maximum number of tokens to generate. ### Request Example (cURL) ```bash curl -X POST http://localhost:48760/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-codex-your-api-key" \ -d '{ "model": "gpt-4o", "messages": [ {"role": "system", "content": "你是一个有帮助的助手。"}, {"role": "user", "content": "你好,请介绍一下自己。"} ], "stream": true }' ``` ### Request Example (Python SDK) ```python from openai import OpenAI client = OpenAI( api_key="sk-codex-your-api-key", base_url="http://localhost:48760/v1" ) response = client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": "你是一个有帮助的助手。"}, {"role": "user", "content": "请解释什么是机器学习?"} ], stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") ``` ### Response #### Success Response (200) - The response format follows the OpenAI API standard for chat completions, including streaming chunks if requested. #### Response Example (Streaming) ``` Hello! I am a helpful assistant. ``` ``` -------------------------------- ### OpenAI Compatible Gateway Usage Source: https://context7.com/qxcnm/codex-manager/llms.txt Provides an OpenAI-compatible API endpoint for local gateway usage. It automatically handles account routing, token refresh, and failover. This allows direct replacement of OpenAI SDK's base_url. ```bash # 使用网关发送 Chat Completion 请求 curl -X POST http://localhost:48760/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer sk-codex-your-api-key" \ -d '{ "model": "gpt-4o", "messages": [ {"role": "system", "content": "你是一个有帮助的助手。"}, {"role": "user", "content": "你好,请介绍一下自己。"} ], "stream": true }' ``` ```python from openai import OpenAI client = OpenAI( api_key="sk-codex-your-api-key", base_url="http://localhost:48760/v1" ) response = client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": "你是一个有帮助的助手。"}, {"role": "user", "content": "请解释什么是机器学习?"} ], stream=True ) for chunk in response: if chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") ``` -------------------------------- ### Batch Delete Unavailable Free Accounts via RPC (Bash) Source: https://context7.com/qxcnm/codex-manager/llms.txt Removes all accounts marked as 'unavailable + free plan' with a single command. It returns statistics on scanned, skipped, and deleted accounts. Requires a valid RPC token. ```bash curl -X POST http://localhost:48760/rpc \ -H "Content-Type: application/json" \ -H "X-CodexManager-Rpc-Token: YOUR_RPC_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": 5, "method": "account/deleteUnavailableFree" }' # Response example # { # "id": 5, # "result": { # "scanned": 10, # "skipped": 7, # "deleted": 3 # } # } ```