### Get All Tokens Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response detailing a token's properties, including its ID, session and access tokens, expiration, user information, and usage counts. ```json [ { "id": 1, "st": "session_token_value", "at": "access_token_value", "at_expires": "2025-01-15T04:46:04.000Z", "email": "user@example.com", "name": "User Name", "remark": "主账号", "is_active": true, "credits": 920, "current_project_id": "uuid-project-id", "current_project_name": "My Project", "image_enabled": true, "video_enabled": true, "image_concurrency": -1, "video_concurrency": -1, "image_count": 150, "video_count": 30, "error_count": 2 } ] ``` -------------------------------- ### Admin Login Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response after a successful administrator login, containing a session token. ```json { "success": true, "token": "admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456", "username": "admin" } ``` -------------------------------- ### Add New Token Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response upon successfully adding a new token, confirming success and providing basic details of the added token. ```json { "success": true, "message": "Token添加成功", "token": { "id": 2, "email": "newuser@example.com", "credits": 1000, "project_id": "new-project-uuid", "project_name": "我的项目" } } ``` -------------------------------- ### Refresh Token Balance Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response after successfully refreshing a token's balance, showing the new credit amount. ```json { "success": true, "message": "余额刷新成功", "credits": 850 } ``` -------------------------------- ### ST to AT Conversion Tool Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response from the ST to AT conversion tool, showing success, the converted access token, and its expiration. ```json { "success": true, "message": "ST converted to AT successfully", "access_token": "ya29.a0ARrdaM...", "email": "user@example.com", "expires": "2025-01-15T04:46:04.000Z" } ``` -------------------------------- ### Deploy Locally Source: https://github.com/xiaomo-123/flow2api/blob/main/README.md Steps to set up a local Python environment and start the service manually. ```bash # 克隆项目 git clone https://github.com/TheSmallHanCat/flow2api.git cd sora2api # 创建虚拟环境 python -m venv venv # 激活虚拟环境 # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate # 安装依赖 pip install -r requirements.txt # 启动服务 python main.py ``` -------------------------------- ### Batch Import Tokens Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response after a batch token import, indicating success and summarizing the number of tokens added and updated. ```json { "success": true, "message": "导入完成", "added": 2, "updated": 0, "errors": [] } ``` -------------------------------- ### Refresh Access Token Response Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example JSON response after successfully refreshing an Access Token, confirming the action and providing the new expiration time. ```json { "success": true, "message": "AT刷新成功", "token": { "id": 1, "email": "user@example.com", "at_expires": "2025-01-16T04:46:04.000Z" } } ``` -------------------------------- ### Deploy with Docker Source: https://github.com/xiaomo-123/flow2api/blob/main/README.md Commands to start the service using Docker Compose, either in standard mode or with a WARP proxy. ```bash # 克隆项目 git clone https://github.com/TheSmallHanCat/flow2api.git cd flow2api # 启动服务 docker-compose up -d # 查看日志 docker-compose logs -f ``` ```bash # 使用 WARP 代理启动 docker-compose -f docker-compose.warp.yml up -d # 查看日志 docker-compose -f docker-compose.warp.yml logs -f ``` -------------------------------- ### Docker Compose File Example Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example docker-compose.yml configuration for Flow2API. This defines the service, build context, port mappings, volume mounts, environment variables, and restart policy. ```yaml version: '3.8' services: flow2api: build: . ports: - "8000:8000" volumes: - ./config:/app/config - ./data:/app/data environment: - TZ=Asia/Shanghai restart: unless-stopped ``` -------------------------------- ### GET /v1/models Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve a list of all supported image and video generation models. ```APIDOC ## GET /v1/models ### Description Retrieves all supported image and video generation models in OpenAI format. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **object** (string) - The type of the object, which is 'list'. - **data** (array) - List of model objects. #### Response Example { "object": "list", "data": [ { "id": "gemini-2.5-flash-image-landscape", "object": "model", "owned_by": "flow2api", "description": "Image generation - GEM_PIX" } ] } ``` -------------------------------- ### Setting.toml Configuration File Source: https://context7.com/xiaomo-123/flow2api/llms.txt Example configuration for the setting.toml file. This file contains global settings, API keys, server configurations, proxy settings, generation timeouts, cache settings, and token refresh intervals. ```toml [global] api_key = "your_api_key" # 外部调用API使用的密钥 admin_username = "admin" # 管理后台用户名 admin_password = "your_password" # 管理后台密码 [flow] labs_base_url = "https://labs.google/fx/api" api_base_url = "https://aisandbox-pa.googleapis.com/v1" timeout = 120 # 请求超时时间(秒) poll_interval = 3.0 # 视频状态轮询间隔(秒) max_poll_attempts = 200 # 最大轮询次数 [server] host = "0.0.0.0" port = 8000 [proxy] proxy_enabled = false # 是否启用代理 proxy_url = "socks5://127.0.0.1:1080" # 代理地址 [generation] image_timeout = 300 # 图片生成超时(秒) video_timeout = 1500 # 视频生成超时(秒) [admin] error_ban_threshold = 3 # 连续错误N次后自动禁用Token [cache] enabled = false # 是否启用缓存 timeout = 7200 # 缓存超时(秒) base_url = "" # 缓存文件访问URL [token_refresh] interval = 3600 # Token自动刷新间隔(秒) ``` -------------------------------- ### Get Available Models List Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve a list of all supported image and video generation models in OpenAI format. Requires authentication. ```bash curl -X GET "http://localhost:8000/v1/models" \ -H "Authorization: Bearer han1234" ``` -------------------------------- ### Get Generation Timeout Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve the configured timeouts for image and video generation. ```bash curl -X GET "http://localhost:8000/api/config/generation" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Generate Video from Start and End Frames Source: https://github.com/xiaomo-123/flow2api/blob/main/README.md API request to generate a video transition between two provided images. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "veo_3_1_i2v_s_fast_fl_landscape", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "从第一张图过渡到第二张图" }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,<首帧base64>" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,<尾帧base64>" } } ] } ], "stream": true }' ``` -------------------------------- ### Get Proxy Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Use this endpoint to retrieve the current proxy configuration settings. ```bash curl -X GET "http://localhost:8000/api/proxy/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Docker Compose Standard Deployment Source: https://context7.com/xiaomo-123/flow2api/llms.txt Instructions for deploying Flow2API using Docker Compose in standard mode without a proxy. Includes cloning the repository, starting the service, viewing logs, and stopping the service. ```bash # 克隆项目 git clone https://github.com/TheSmallHanCat/flow2api.git cd flow2api # 启动服务 docker-compose up -d # 查看日志 docker-compose logs -f # 停止服务 docker-compose down ``` -------------------------------- ### Get All Tokens API Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve detailed information for all tokens in the system, including balance and usage statistics. Requires an Authorization header with the admin token. ```bash curl -X GET "http://localhost:8000/api/tokens" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### GET /api/tokens Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieves a list of all tokens in the system along with their usage statistics and configuration. ```APIDOC ## GET /api/tokens ### Description Fetches detailed information for all tokens, including credits and concurrency limits. ### Method GET ### Endpoint http://localhost:8000/api/tokens ``` -------------------------------- ### Get System Statistics Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve overall system statistics, including token counts, generation statistics, and error counts. ```bash curl -X GET "http://localhost:8000/api/stats" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Proxy Configuration API Source: https://context7.com/xiaomo-123/flow2api/llms.txt APIs to get and update the proxy configuration for the service. ```APIDOC ## GET /api/proxy/config ### Description Retrieves the current proxy configuration. ### Method GET ### Endpoint /api/proxy/config ### Request Example ```bash curl -X GET "http://localhost:8000/api/proxy/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` ### Response #### Success Response (200) - **proxy_enabled** (boolean) - Indicates if the proxy is enabled. - **proxy_url** (string) - The URL of the proxy server. #### Response Example ```json { "proxy_enabled": true, "proxy_url": "socks5://127.0.0.1:1080" } ``` ## POST /api/proxy/config ### Description Updates the proxy configuration. ### Method POST ### Endpoint /api/proxy/config ### Request Body - **proxy_enabled** (boolean) - Required - Whether to enable the proxy. - **proxy_url** (string) - Required - The URL of the proxy server. ### Request Example ```json { "proxy_enabled": true, "proxy_url": "socks5://127.0.0.1:1080" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Proxy configuration updated successfully." } ``` ``` -------------------------------- ### Get Token Refresh Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve the configuration for the automatic Access Token refresh feature. ```bash curl -X GET "http://localhost:8000/api/token-refresh/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Get Cache Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve the current configuration for the local cache, including its enabled status, timeout, and base URL. ```bash curl -X GET "http://localhost:8000/api/cache/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Cache Configuration API Source: https://context7.com/xiaomo-123/flow2api/llms.txt APIs to get and update the cache configuration for generation results. ```APIDOC ## GET /api/cache/config ### Description Retrieves the current cache configuration. ### Method GET ### Endpoint /api/cache/config ### Request Example ```bash curl -X GET "http://localhost:8000/api/cache/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` ### Response #### Success Response (200) - **enabled** (boolean) - Whether cache is enabled. - **timeout** (integer) - Cache timeout in seconds. - **base_url** (string) - The base URL for accessing cached files. #### Response Example ```json { "enabled": true, "timeout": 7200, "base_url": "https://your-domain.com" } ``` ## POST /api/cache/config ### Description Updates the cache configuration. ### Method POST ### Endpoint /api/cache/config ### Request Body - **enabled** (boolean) - Required - Whether to enable cache. - **timeout** (integer) - Required - Cache timeout in seconds. - **base_url** (string) - Required - The base URL for accessing cached files. ### Request Example ```json { "enabled": true, "timeout": 7200, "base_url": "https://your-domain.com" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Cache configuration updated successfully." } ``` ``` -------------------------------- ### Generation Timeout Configuration API Source: https://context7.com/xiaomo-123/flow2api/llms.txt APIs to get and update the image and video generation timeout settings. ```APIDOC ## GET /api/config/generation ### Description Retrieves the current generation timeout configuration for images and videos. ### Method GET ### Endpoint /api/config/generation ### Request Example ```bash curl -X GET "http://localhost:8000/api/config/generation" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` ### Response #### Success Response (200) - **image_timeout** (integer) - Timeout for image generation in seconds. - **video_timeout** (integer) - Timeout for video generation in seconds. #### Response Example ```json { "image_timeout": 300, "video_timeout": 1500 } ``` ## POST /api/config/generation ### Description Updates the image and video generation timeout settings. ### Method POST ### Endpoint /api/config/generation ### Request Body - **image_timeout** (integer) - Required - Timeout for image generation in seconds. - **video_timeout** (integer) - Required - Timeout for video generation in seconds. ### Request Example ```json { "image_timeout": 300, "video_timeout": 1500 } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Generation timeout configuration updated successfully." } ``` ``` -------------------------------- ### Token Refresh Configuration API Source: https://context7.com/xiaomo-123/flow2api/llms.txt APIs to get and update the Access Token auto-refresh configuration. ```APIDOC ## GET /api/token-refresh/config ### Description Retrieves the current Access Token auto-refresh configuration. ### Method GET ### Endpoint /api/token-refresh/config ### Request Example ```bash curl -X GET "http://localhost:8000/api/token-refresh/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` ### Response #### Success Response (200) - **interval** (integer) - The interval in seconds for token refresh. #### Response Example ```json { "interval": 3600 } ``` ## POST /api/token-refresh/enabled ### Description Enables or disables the Access Token auto-refresh feature. ### Method POST ### Endpoint /api/token-refresh/enabled ### Request Body - **enabled** (boolean) - Required - Whether to enable or disable auto-refresh. ### Request Example ```json { "enabled": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Token refresh enabled successfully." } ``` ``` -------------------------------- ### Configuration File Explanation Source: https://context7.com/xiaomo-123/flow2api/llms.txt Explanation of the `setting.toml` configuration file. ```APIDOC ## Configuration File Explanation ### `setting.toml` Configuration This is the main configuration file, containing API keys, server settings, and proxy configurations. ```toml [global] api_key = "your_api_key" # API key for external calls admin_username = "admin" # Admin backend username admin_password = "your_password" # Admin backend password [flow] labs_base_url = "https://labs.google/fx/api" api_base_url = "https://aisandbox-pa.googleapis.com/v1" timeout = 120 # Request timeout in seconds poll_interval = 3.0 # Video status polling interval in seconds max_poll_attempts = 200 # Maximum polling attempts [server] host = "0.0.0.0" port = 8000 [proxy] proxy_enabled = false # Whether to enable proxy proxy_url = "socks5://127.0.0.1:1080" # Proxy address [generation] image_timeout = 300 # Image generation timeout in seconds video_timeout = 1500 # Video generation timeout in seconds [admin] error_ban_threshold = 3 # Auto-ban token after N consecutive errors [cache] enabled = false # Whether to enable cache timeout = 7200 # Cache timeout in seconds base_url = "" # URL for accessing cached files [token_refresh] interval = 3600 # Token auto-refresh interval in seconds ``` ``` -------------------------------- ### Generate Video from Reference Images Source: https://context7.com/xiaomo-123/flow2api/llms.txt Use this endpoint to create a video from multiple reference images. Supports an unlimited number of images. Ensure images are base64 encoded. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "veo_3_0_r2v_fast_landscape", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "将这些产品图片制作成一个展示视频" }, { "type": "image_url", "image_url": {"url": "data:image/jpeg;base64,<图片1>"} }, { "type": "image_url", "image_url": {"url": "data:image/jpeg;base64,<图片2>"} }, { "type": "image_url", "image_url": {"url": "data:image/jpeg;base64,<图片3>"} } ] } ], "stream": true }' ``` -------------------------------- ### Image-to-Video Generation (First/Last Frame) Source: https://context7.com/xiaomo-123/flow2api/llms.txt Generate a transitional video using 1-2 images as the first and last frames. Supports streaming output. Ensure the correct model ID is used for landscape or portrait orientation. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "veo_3_1_i2v_s_fast_fl_landscape", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "从第一张图平滑过渡到第二张图,展现日出到日落的变化" }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,<首帧图片base64>" } }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,<尾帧图片base64>" } } ] } ], "stream": true }' ``` -------------------------------- ### Docker Deployment Source: https://context7.com/xiaomo-123/flow2api/llms.txt Instructions for deploying Flow2API using Docker. ```APIDOC ## Docker Deployment ### Standard Mode Deployment This describes the standard Docker deployment without a proxy. ```bash # Clone the project git clone https://github.com/TheSmallHanCat/flow2api.git cd flow2api # Start the service docker-compose up -d # View logs docker-compose logs -f # Stop the service docker-compose down ``` **docker-compose.yml Configuration:** ```yaml version: '3.8' services: flow2api: build: . ports: - "8000:8000" volumes: - ./config:/app/config - ./data:/app/data environment: - TZ=Asia/Shanghai restart: unless-stopped ``` ### WARP Proxy Mode Deployment This describes deployment using Cloudflare WARP proxy. ```bash # Start with WARP proxy docker-compose -f docker-compose.warp.yml up -d # View logs docker-compose -f docker-compose.warp.yml logs -f ``` ``` -------------------------------- ### POST /api/tokens/import Source: https://context7.com/xiaomo-123/flow2api/llms.txt Bulk imports multiple tokens into the system. ```APIDOC ## POST /api/tokens/import ### Description Imports a list of tokens, automatically handling creation or updates. ### Method POST ### Endpoint http://localhost:8000/api/tokens/import ### Request Body - **tokens** (array) - Required - List of token objects to import ``` -------------------------------- ### POST /v1/chat/completions Source: https://context7.com/xiaomo-123/flow2api/llms.txt Generates a video from multiple reference images by sending a request to the chat completions endpoint. ```APIDOC ## POST /v1/chat/completions ### Description Uploads multiple reference images to generate a video based on the provided prompt. ### Method POST ### Endpoint http://localhost:8000/v1/chat/completions ### Request Body - **model** (string) - Required - The model identifier (e.g., "veo_3_0_r2v_fast_landscape") - **messages** (array) - Required - List of message objects containing text and image_url content - **stream** (boolean) - Optional - Whether to stream the response ``` -------------------------------- ### Open Token Import Modal Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Opens the modal for importing tokens, clearing the file input. ```javascript openImportModal=()=>{$('importModal').classList.remove('hidden');$('importFile').value=''} ``` -------------------------------- ### POST /v1/chat/completions Source: https://context7.com/xiaomo-123/flow2api/llms.txt Unified endpoint for text-to-image, image-to-image, text-to-video, and image-to-video generation tasks. ```APIDOC ## POST /v1/chat/completions ### Description Generates content based on the specified model and input messages. Supports text-to-image, image-to-image, text-to-video, and image-to-video generation. ### Method POST ### Endpoint /v1/chat/completions ### Request Body - **model** (string) - Required - The ID of the model to use. - **messages** (array) - Required - The input messages containing text or image_url content. - **stream** (boolean) - Optional - Whether to stream the response. ### Request Example { "model": "gemini-2.5-flash-image-landscape", "messages": [ { "role": "user", "content": "一只可爱的猫咪在花园里玩耍" } ], "stream": true } ``` -------------------------------- ### Get Request Logs Source: https://context7.com/xiaomo-123/flow2api/llms.txt Retrieve recent API request logs for debugging and monitoring purposes. You can specify a limit for the number of logs returned. ```bash curl -X GET "http://localhost:8000/api/logs?limit=50" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Generate Video from Text Source: https://github.com/xiaomo-123/flow2api/blob/main/README.md API request to generate a video from a text prompt. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "veo_3_1_t2v_fast_landscape", "messages": [ { "role": "user", "content": "一只小猫在草地上追逐蝴蝶" } ], "stream": true }' ``` -------------------------------- ### POST /api/tokens Source: https://context7.com/xiaomo-123/flow2api/llms.txt Adds a new session token to the system and initializes its associated account information. ```APIDOC ## POST /api/tokens ### Description Registers a new session token and converts it to an access token. ### Method POST ### Endpoint http://localhost:8000/api/tokens ### Request Body - **st** (string) - Required - Session token string - **project_name** (string) - Required - Name of the project - **remark** (string) - Optional - Description of the token - **image_enabled** (boolean) - Optional - Enable image generation - **video_enabled** (boolean) - Optional - Enable video generation - **image_concurrency** (integer) - Optional - Image concurrency limit - **video_concurrency** (integer) - Optional - Video concurrency limit ``` -------------------------------- ### Batch Import Tokens API Source: https://context7.com/xiaomo-123/flow2api/llms.txt Import multiple tokens in bulk. The system will automatically handle new additions and updates. Requires admin authorization. ```bash curl -X POST "http://localhost:8000/api/tokens/import" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" \ -H "Content-Type: application/json" \ -d '{ "tokens": [ { "session_token": "st_token_1", "project_name": "项目1", "remark": "账号1", "image_enabled": true, "video_enabled": true }, { "session_token": "st_token_2", "project_name": "项目2", "remark": "账号2", "image_enabled": true, "video_enabled": false } ] }' ``` -------------------------------- ### Token Data Formatting Utilities Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Helper functions to format token expiry, plan types, and account status for display in the UI. ```javascript formatExpiry=exp=>{if(!exp)return'-';const d=new Date(exp),now=new Date(),diff=d-now;const dateStr=d.toLocaleDateString('zh-CN',{year:'numeric',month:'2-digit',day:'2-digit'}).replace(/\//g,'-');const timeStr=d.toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit',hour12:false});const hours=Math.floor(diff/36e5);if(diff<0)return`已过期`;if(hours<1)return`${Math.floor(diff/6e4)}分钟`;if(hours<24)return`${hours}小时`;const days=Math.floor(diff/864e5);if(days<7)return`${days}天`;return`${days}天`}, formatPlanType=type=>{if(!type)return'-';const typeMap={'chatgpt_team':'Team','chatgpt_plus':'Plus','chatgpt_pro':'Pro','chatgpt_free':'Free'};return typeMap[type]||type}, formatSora2=(t)=>{if(t.sora2_supported===true){const remaining=t.sora2_total_count-t.sora2_redeemed_count;const tooltipText=`邀请码: ${t.sora2_invite_code||'无'}\n可用次数: ${remaining}/${t.sora2_total_count}\n已用次数: ${t.sora2_redeemed_count}`;return`
支持${remaining}/${t.sora2_total_count}
`}else if(t.sora2_supported===false){return`不支持`}else{return'-'}}, formatPlanTypeWithTooltip=(t)=>{const tooltipText=t.subscription_end?`套餐到期: ${new Date(t.subscription_end).toLocaleDateString('zh-CN',{year:'numeric',month:'2-digit',day:'2-digit'}).replace(/\//g,'-')} ${new Date(t.subscription_end).toLocaleTimeString('zh-CN',{hour:'2-digit',minute:'2-digit',hour12:false})}`:'';return`${formatPlanType(t.plan_type)}`}, formatSora2Remaining=(t)=>{if(t.sora2_supported===true){const remaining=t.sora2_remaining_count||0;return`${remaining}`}else{return'-'}}, formatAccountType=(tier)=>{if(tier==='PAYGATE_TIER_NOT_PAID'){return`普通`}else{return`会员`}} ``` -------------------------------- ### Update Generation Timeout Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Update the timeout settings for image and video generation. Specify timeouts in seconds. ```bash curl -X POST "http://localhost:8000/api/config/generation" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" \ -H "Content-Type: application/json" \ -d '{ "image_timeout": 300, "video_timeout": 1500 }' ``` -------------------------------- ### Load System Logs Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Fetches the most recent system logs from the API. ```javascript loadLogs=async()=>{try{const r=await apiRequest('/api/logs?limit=100');if(!r)return;const logs ``` -------------------------------- ### Image-to-Image Transformation Source: https://context7.com/xiaomo-123/flow2api/llms.txt Transform an input image based on a text prompt using Imagen models. The image can be provided as a base64 encoded string. Supports streaming output. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "imagen-4.0-generate-preview-landscape", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "将这张图片变成水彩画风格" }, { "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..." } } ] } ], "stream": true }' ``` -------------------------------- ### POST /api/admin/login Source: https://context7.com/xiaomo-123/flow2api/llms.txt Authenticates an administrator and returns a session token for subsequent API requests. ```APIDOC ## POST /api/admin/login ### Description Logs in the administrator to obtain a session token. ### Method POST ### Endpoint http://localhost:8000/api/admin/login ### Request Body - **username** (string) - Required - Admin username - **password** (string) - Required - Admin password ### Response #### Success Response (200) - **success** (boolean) - Status of the login - **token** (string) - Authentication token - **username** (string) - Authenticated username ``` -------------------------------- ### Text-to-Video Generation Source: https://context7.com/xiaomo-123/flow2api/llms.txt Generate video from text prompts using Veo models. Does not support image uploads. Supports streaming output. Ensure the correct model ID is used for landscape or portrait orientation. ```bash curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Authorization: Bearer han1234" \ -H "Content-Type: application/json" \ -d '{ "model": "veo_3_1_t2v_fast_landscape", "messages": [ { "role": "user", "content": "一只小猫在草地上追逐蝴蝶,阳光明媚" } ], "stream": true }' ``` -------------------------------- ### Admin Login API Source: https://context7.com/xiaomo-123/flow2api/llms.txt Log in to the admin backend to obtain a session token for subsequent management operations. Requires username and password. ```bash curl -X POST "http://localhost:8000/api/admin/login" \ -H "Content-Type: application/json" \ -d '{ "username": "admin", "password": "admin" }' ``` -------------------------------- ### Update Proxy Configuration Source: https://context7.com/xiaomo-123/flow2api/llms.txt Use this endpoint to update the proxy configuration, enabling or disabling the proxy and setting its URL. ```bash curl -X POST "http://localhost:8000/api/proxy/config" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" \ -H "Content-Type: application/json" \ -d '{ "proxy_enabled": true, "proxy_url": "socks5://127.0.0.1:1080" }' ``` -------------------------------- ### Manage Token Refresh Configuration Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Functions to toggle and load the automatic token refresh status. ```javascript toggleATAutoRefresh=async()=>{try{const enabled=$('atAutoRefreshToggle').checked;console.log("自动刷新"); const r=await apiRequest('/api/token-refresh/enabled',{method:'POST',body:JSON.stringify({enabled:enabled})});if(!r){$('atAutoRefreshToggle').checked=!enabled;return}const d=await r.json();if(d.success){showToast(enabled?'AT自动刷新已启用':'AT自动刷新已禁用','success')}else{showToast('操作失败: '+(d.detail||'未知错误'),'error');$('atAutoRefreshToggle').checked=!enabled}}catch(e){showToast('操作失败: '+e.message,'error');$('atAutoRefreshToggle').checked=!enabled}} ``` ```javascript loadATAutoRefreshConfig=async()=>{try{const r=await apiRequest('/api/token-refresh/config');if(!r)return;const d=await r.json();if(d.success&&d.config){$('atAutoRefreshToggle').checked=d.config.at\_auto\_refresh\_enabled||false}else{console.error('AT自动刷新配置数据格式错误:',d)}}catch(e){console.error('加载AT自动刷新配置失败:',e)}} ``` -------------------------------- ### Add New Token API Source: https://context7.com/xiaomo-123/flow2api/llms.txt Add a new Session Token to the system. It will be automatically converted to an Access Token, and account information will be retrieved. Requires admin authorization. ```bash curl -X POST "http://localhost:8000/api/tokens" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" \ -H "Content-Type: application/json" \ -d '{ "st": "__Secure-next-auth.session-token=eyJhbGciOiJkaXIi...", "project_name": "我的项目", "remark": "测试账号", "image_enabled": true, "video_enabled": true, "image_concurrency": 3, "video_concurrency": 1 }' ``` -------------------------------- ### Token Management and API Utilities Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Core functions for handling authentication, API requests, and loading system statistics and token data. ```javascript let allTokens=[]; const $=(id)=>document.getElementById(id), checkAuth=()=>{const t=localStorage.getItem('adminToken');return t||(location.href='/login',null),t}, apiRequest=async(url,opts={})=>{const t=checkAuth();if(!t)return null;const r=await fetch(url,{...opts,headers:{...opts.headers,Authorization:`Bearer ${t}`,'Content-Type':'application/json'}});return r.status===401?(localStorage.removeItem('adminToken'),location.href='/login',null):r}, loadStats=async()=>{try{const r=await apiRequest('/api/stats');if(!r)return;const d=await r.json();$('statTotal').textContent=d.total_tokens||0;$('statActive').textContent=d.active_tokens||0;$('statImages').textContent=(d.today_images||0)+'/'+(d.total_images||0);$('statVideos').textContent=(d.today_videos||0)+'/'+(d.total_videos||0);$('statErrors').textContent=(d.today_errors||0)+'/'+(d.total_errors||0)}catch(e){console.error('加载统计失败:',e)}}, loadTokens=async()=>{try{const r=await apiRequest('/api/tokens');if(!r)return;allTokens=await r.json();renderTokens()}catch(e){console.error('加载Token失败:',e)}} ``` -------------------------------- ### Proxy and Debug Configuration Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Functions to toggle debug mode and manage proxy settings. ```javascript toggleDebugMode=async()=>{const enabled=$('cfgDebugEnabled').checked;try{const r=await apiRequest('/api/admin/debug',{method:'POST',body:JSON.stringify({enabled:enabled})});if(!r)return;const d=await r.json();if(d.success){showToast(enabled?'调试模式已开启':'调试模式已关闭','success')}else{showToast('操作失败: '+(d.detail||'未知错误'),'error');$('cfgDebugEnabled').checked=!enabled}}catch(e){showToast('操作失败: '+e.message,'error');$('cfgDebugEnabled').checked=!enabled}} ``` ```javascript loadProxyConfig=async()=>{try{const r=await apiRequest('/api/proxy/config');if(!r)return;const d=await r.json();$('cfgProxyEnabled').checked=d.proxy_enabled||false;$('cfgProxyUrl').value=d.proxy_url||''}catch(e){console.error('加载代理配置失败:',e)}} ``` ```javascript saveProxyConfig=async()=>{try{const r=await apiRequest('/api/proxy/config',{method:'POST',body:JSON.stringify({proxy_enabled:$('cfgProxyEnabled').checked,proxy_url:$('cfgProxyUrl').value.trim()})});if(!r)return;const d=await r.json();d.success?showToast('代理配置保存成功','success'):showToast('保存失败','error')}catch(e){showToast('保存失败: '+e.message,'error')}} ``` -------------------------------- ### Batch Token Management Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Functions for refreshing multiple tokens and managing UI selection states. ```javascript refreshTokens=async()=>{ // 打印选中的Token ID const selectedCheckboxes = document.querySelectorAll('.token-checkbox:checked'); const selectedIds = Array.from(selectedCheckboxes).map(cb => cb.value); if (selectedIds.length > 0) { console.log("选中的Token ID:", selectedIds.join(", ")); await batchRefreshTokens(selectedIds); } // 原有的刷新功能 console.log("刷新"); loadTokens(); await loadStats(); }, // 批量刷新Token的AT batchRefreshTokens=async(tokenIds)=>{ showToast(`正在刷新 ${tokenIds.length} 个Token的AT...`, 'info'); let successCount = 0; let failCount = 0; for (const id of tokenIds) { try { const r = await apiRequest(`/api/tokens/${id}/refresh-at`, {method: 'POST'}); if (!r) { failCount++; continue; } const d = await r.json(); if (d.success) { successCount++; console.log(`Token ${id} AT刷新成功`); } else { failCount++; console.error(`Token ${id} AT刷新失败:`, d.detail || '未知错误'); } } catch (e) { failCount++; console.error(`Token ${id} AT刷新异常:`, e.message); } } if (successCount > 0) { showToast(`AT刷新完成: 成功 ${successCount} 个, 失败 ${failCount} 个`, 'success'); } else { showToast(`AT刷新失败: 所有 ${failCount} 个Token刷新失败`, 'error'); } }, // 全选/取消全选功能 toggleSelectAll=()=>{ const selectAllCheckbox = $('selectAllTokens'); const tokenCheckboxes = document.querySelectorAll('.token-checkbox'); tokenCheckboxes.forEach(checkbox => { checkbox.checked = selectAllCheckbox.checked; }); }, // 更新全选框状态 updateSelectAllStatus=()=>{ const selectAllCheckbox = $('selectAllTokens'); const tokenCheckboxes = document.querySelectorAll('.token-checkbox'); const checkedCheckboxes = document.querySelectorAll('.token-checkbox:checked'); // 如果没有Token,不更新全选框状态 if (tokenCheckboxes.length === 0) { return; } // 如果所有Token都被选中,则全选框也选中 // 如果有Token未被选中,则全选框不选中 selectAllCheckbox.checked = tokenCheckboxes.length === checkedCheckboxes.length; }, openAddModal=()=>$('addModal').classList.remove('hidden'), closeAddModal=()=>{$('addModal').classList.add('hidden')} ``` -------------------------------- ### Refresh Token Balance API Source: https://context7.com/xiaomo-123/flow2api/llms.txt Manually refresh the VideoFX Credits balance for a specific token. Requires admin authorization and the token ID. ```bash curl -X POST "http://localhost:8000/api/tokens/1/refresh-credits" \ -H "Authorization: Bearer admin-aBcDeFgHiJkLmNoPqRsTuVwXyZ123456" ``` -------------------------------- ### Export All Tokens Source: https://github.com/xiaomo-123/flow2api/blob/main/static/manage.html Exports all current tokens to a JSON file. The export includes token details like email, access token, session token, and various flags and concurrency settings. ```javascript exportTokens=()=>{if(allTokens.length===0){showToast('没有Token可导出','error');return}const exportData=allTokens.map(t=>({email:t.email,access_token:t.token,session_token:t.st||null,is_active:t.is_active,image_enabled:t.image_enabled!==false,video_enabled:t.video_enabled!==false,image_concurrency:t.image_concurrency||(-1),video_concurrency:t.video_concurrency||(-1)}));const dataStr=JSON.stringify(exportData,null,2);const dataBlob=new Blob([dataStr],{type:'application/json'});const url=URL.createObjectURL(dataBlob);const link=document.createElement('a');link.href=url;link.download=`tokens_${new Date().toISOString().split('T')[0]}.json`;document.body.appendChild(link);link.click();document.body.removeChild(link);URL.revokeObjectURL(url);showToast(`已导出 ${allTokens.length} 个Token`,'success')} ```