Skip to content

jialeuuz/api_proxy

Repository files navigation

Local Browser API Proxy

This is a local-first container for browser-driven API wrappers. It does not use official vendor APIs. The current providers are Google Flow, Doubao, and Dyks, all driven through Playwright, so selector drift and login state can break them at any time.

It now also supports an Ubuntu server deployment with:

  • api-proxy-backend.service on 127.0.0.1:8011
  • api-proxy-desktop.service running Xvfb + openbox + x11vnc + noVNC/websockify
  • api-proxy-session-check.timer running a daily Flow + Doubao session/check refresh
  • protected Nginx routes at /ui/, /providers/, /docs, and /desktop/

Current providers

  • flow Google Flow image / video generation wrapper for Banana and Veo 3.1 models
  • doubao Doubao chat / video-generation wrapper for Seedance 2.0 video tasks
  • dyks Dyks goods / purchase-page automation wrapper with password login, goods catalog extraction, form-schema extraction, and pre-submit purchase-page filling

Preferred provider-scoped routes:

  • GET /providers/flow/health
  • GET /providers/flow/ui
  • GET /providers/flow/accounts
  • POST /providers/flow/accounts
  • GET /providers/flow/accounts/{account_id}/session/check
  • POST /providers/flow/accounts/{account_id}/session/init
  • GET /providers/flow/usage/summary
  • GET /providers/flow/session/check
  • POST /providers/flow/session/init
  • POST /providers/flow/v1/images/generations
  • POST /providers/flow/v1/videos/generations
  • GET /providers/flow/v1/files/{run_id}/{filename}
  • GET /providers/doubao/health
  • GET /providers/doubao/ui
  • GET /providers/doubao/accounts
  • POST /providers/doubao/accounts
  • GET /providers/doubao/accounts/{account_id}/session/check
  • POST /providers/doubao/accounts/{account_id}/session/init
  • GET /providers/doubao/usage/summary
  • GET /providers/doubao/session/check
  • POST /providers/doubao/session/init
  • POST /providers/doubao/video-jobs
  • GET /providers/doubao/video-jobs/{job_id}
  • POST /providers/doubao/v1/videos/generations
  • GET /providers/doubao/v1/files/{run_id}/{filename}
  • GET /providers/dyks/health
  • GET /providers/dyks/ui
  • GET /providers/dyks/accounts
  • POST /providers/dyks/accounts
  • GET /providers/dyks/accounts/{account_id}/session/check
  • POST /providers/dyks/accounts/{account_id}/session/init
  • GET /providers/dyks/session/check
  • POST /providers/dyks/session/init
  • POST /providers/dyks/v1/topups
  • POST /providers/dyks/v1/goods/list
  • POST /providers/dyks/v1/goods/schema
  • POST /providers/dyks/v1/purchases/open
  • POST /providers/dyks/v1/purchases/prepare

Legacy Flow-only aliases are still kept for compatibility:

  • /health
  • /session/check
  • /session/init
  • /v1/images/generations
  • /v1/videos/generations
  • /v1/files/{run_id}/{filename}

What it does now

  • Reuses a persistent browser profile
  • Supports multiple named Flow browser caches, each with its own persistent profile
  • Supports multiple named Doubao browser caches, each with its own persistent profile
  • Supports multiple named Dyks browser caches, each with its own persistent profile
  • Opens Flow in a real browser context
  • Opens Doubao chat / create-video pages in a real browser context
  • Opens Dyks login, account, and goods purchase pages in a real browser context
  • Enters a project workspace from the Flow project list when needed
  • Fills the bottom prompt textbox
  • Exposes OpenAI-style image and video generation endpoints for Banana and Veo 3.1
  • Exposes an OpenAI-style video generation endpoint for Doubao Seedance 2.0
  • Exposes Dyks password-login session init, account/topup-page opening, goods catalog listing, goods form-schema extraction, purchase-page opening, and purchase-page prefill endpoints
  • Exposes management-UI-only background video job endpoints for Doubao so the local page can submit once and poll for status later
  • Opens the bottom settings panel and can control Banana image settings plus Veo 3.1 frames / ingredients, aspect ratio, tile count, and model choice
  • Supports Banana image generation with prompt-only or prompt + reference images selected from the current Flow project or local files chosen in the React management UI
  • Uploads local / remote reference images into the current Flow project and selects them through the asset picker for Banana and Veo 3.1
  • Tracks generated media counts per Flow browser cache + project and clears project history before the next call once the count reaches 100
  • Captures per-poll generation progress percentages from the Flow UI
  • Captures per-poll queue / acknowledgement / completion messages from the Doubao chat UI and records daily quota fields when visible; Doubao startup no longer opens browser windows just to refresh quota, and cross-day rollover only resets the local quota cache until the next real video call updates it
  • Lets the React management page submit Doubao video generation as a background job and poll /providers/doubao/video-jobs/{job_id} instead of pinning the page to one long HTTP request
  • Returns local HTTP file URLs or b64_json, depending on response_format
  • Can return per-slot error values when some generated media fail
  • Waits for the expected number of new media items, with no remaining % progress markers, before exporting
  • Serves provider-scoped management URLs for Flow, Doubao, and Dyks; when web/dist/ exists they all redirect into the shared React page at /ui/?tab=<provider>

Layout

  • app.py FastAPI container entrypoint
  • core/ Shared runtime settings and generic API error helpers
  • providers/flow/ Flow-specific router, settings, request models, and Playwright automation
  • providers/doubao/ Doubao-specific router, settings, request models, and Playwright automation
  • providers/dyks/ Dyks-specific router, settings, request models, and Playwright automation
  • api_doc/flow/ Flow provider API docs
  • api_doc/doubao/ Doubao provider API docs
  • api_doc/dyks/ Dyks provider API docs

Limits

  • Google login still has to exist in the browser profile
  • Doubao login still has to exist in the browser profile
  • Dyks can initialize login with username/password, but the downstream site can still break if its DOM or auth flow changes
  • Flow UI changes may require selector updates
  • Doubao UI changes may require selector or status-text updates
  • Concurrency is serialized on purpose because one persistent Flow profile is shared
  • Concurrency is also serialized per Doubao browser cache because one persistent profile is shared
  • Supported public model ids are currently banana-2, banana-pro, veo-3.1-fast, and veo-3.1-quality
  • Supported Doubao public model id is currently seedance-2.0
  • The default Flow generation timeout is 1800 seconds
  • The default Doubao video watchdog is 3600 seconds; it protects submission and page-health monitoring, not the final generation wait while the page remains healthy
  • Image aspect_ratio must be one of 16:9, 4:3, 1:1, 3:4, 9:16; video aspect_ratio currently supports 16:9 and 9:16
  • Image resolution supports original and 2k; 4k is still a Flow upgrade option and is not exposed by this API
  • n is required and must be 1 to 4, matching the Flow UI tile count selector
  • Doubao n is currently fixed to 1
  • This is meant for local personal use, not a stable multi-user service

Ubuntu server deployment

Install and build once:

bash /home/ubuntu/projects/api_proxy/deploy/install_ubuntu.sh

The deployment scripts are fixed-parameter entrypoints:

  • deploy/install_ubuntu.sh Installs Ubuntu dependencies, creates .venv, installs Python dependencies, installs Playwright Chromium and its Linux runtime libraries, then builds web/dist
  • deploy/start_backend.sh Loads .env, pins Playwright browser binaries to data/shared/pw-browsers, exports DISPLAY=:99, and starts uvicorn app:app --host 127.0.0.1 --port 8011
  • deploy/start_remote_desktop.sh Starts Xvfb, openbox, autocutsel, x11vnc, and websockify on fixed local ports so visible browser windows can be viewed from noVNC, and keeps the VNC cutbuffer, X11 clipboard, and PRIMARY selection in sync for more reliable Windows-to-server paste

Systemd templates live under deploy/systemd/:

  • api-proxy-backend.service
  • api-proxy-desktop.service

Current Ubuntu deployment access points:

  • https://yonderseek.com/ui/?tab=guide
  • https://yonderseek.com/ui/?tab=flow
  • https://yonderseek.com/ui/?tab=doubao
  • https://yonderseek.com/ui/?tab=dyks
  • https://yonderseek.com/desktop/

These Nginx routes are protected with Basic Auth. The current auth file lives at data/nginx_basic_auth.htpasswd. The shared management page now includes the remote desktop panel directly, but it no longer auto-connects on page load. The noVNC iframe is only mounted when you click session/init / “打开登录窗口” or manually press “连接桌面”. When session/init finishes with logged_in=true, the shared page automatically disconnects that embedded desktop again; if login times out or fails, it stays connected so you can keep looking at the live browser state. /desktop/ is still available when you want the remote desktop in a separate browser tab. For the Ubuntu deployment, the /providers/ reverse-proxy route is now configured with 3600s connect/send/read timeouts so visible login flows are not cut off by the old 60-second proxy default. The shared management page now also sends timeout_sec=3600 for its login-window actions, and the backend session/init request validators accept up to 3600 seconds as well. The current Ubuntu start script still keeps the shared default BROWSER_API_HEADLESS=true for the container overall, but explicitly overrides Flow to FLOW_HEADLESS=false, because Flow generation on this server is reproducibly unreliable in headless mode while headed mode works with the same persistent cache. The Ubuntu deployment now also includes a daily api-proxy-session-check.timer at 03:15 server time. It calls Flow and Doubao session/check for every enabled browser cache so the management UI reflects fresher login state without opening manual login windows.

One-click Windows start

If you just want the local API up, use:

cd D:\codes\3dxiaoren\test\browser_api_proxy
python run_local_windows.py

The script will:

  • reuse BROWSER_API_PYTHON if you set it, otherwise create or reuse .\.venv
  • auto-install requirements.txt if FastAPI / Uvicorn / Playwright are missing
  • auto-install Playwright Chromium into the module browser directory if needed
  • auto-use http://127.0.0.1:7890 as HTTP_PROXY / HTTPS_PROXY when that local proxy port is reachable and no proxy env is already set
  • start the backend in a new PowerShell window and poll /providers/flow/health until ready
  • print Shared UI, Flow UI, Doubao UI, Dyks UI, Docs, and Health URLs once the service is ready or an existing instance is reused
  • keep Doubao daily quota cache in sync locally without opening Doubao windows at startup

Optional environment variables for the launcher:

  • BROWSER_API_PYTHON Explicit Python interpreter for dependency install and backend startup
  • BROWSER_API_HOST Default 127.0.0.1
  • BROWSER_API_PORT Default 8011
  • BROWSER_API_BROWSERS_DIR or PLAYWRIGHT_BROWSERS_PATH Override the shared Playwright browser directory

If web/dist/ exists, /providers/flow/ui, /providers/doubao/ui, and /providers/dyks/ui redirect to the shared React page at /ui/?tab=<provider>. If it does not exist, the backend still serves the Flow legacy management page, while Doubao and Dyks report that the React management UI is not built.

Setup

cd D:\codes\3dxiaoren\test\browser_api_proxy
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
$env:HTTP_PROXY = 'http://127.0.0.1:7890'
$env:HTTPS_PROXY = 'http://127.0.0.1:7890'
$env:PLAYWRIGHT_BROWSERS_PATH = [System.IO.Path]::GetFullPath('.\data\shared\pw-browsers')
python -m playwright install chromium
uvicorn app:app --host 127.0.0.1 --port 8011 --reload

By default the shared Playwright browser binaries live under data/shared/pw-browsers/. If your old data/pw-browsers/ directory already exists, the service will keep using that legacy path unless you override it.

Manual setup is still useful when you want to refresh dependencies, debug startup, or run uvicorn in the current shell instead of a detached PowerShell window.

First-time session init

If the Flow profile is not logged in yet, initialize it once:

Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8011/providers/flow/session/init -ContentType application/json -Body '{"timeout_sec":3600}'

That opens a visible browser window backed by the default browser cache directory. If your old data/profile/ already exists, the service reuses that legacy path as the built-in default browser cache unless you set FLOW_PROFILE_DIR. /providers/flow/session/init now checks whether Flow is asking for sign-in before it touches workspace or onboarding buttons, and workspace preparation stops as soon as the browser reaches a Google sign-in page, so a fresh profile should stay on the real login path instead of being pushed into profile-completion or signup screens.

If you already have a dedicated Chrome or Edge profile logged into Flow, you can point the service at it with FLOW_PROFILE_DIR and skip /providers/flow/session/init.

If the Doubao profile is not logged in yet, initialize it once:

Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8011/providers/doubao/session/init -ContentType application/json -Body '{"timeout_sec":3600}'

That opens a visible browser window backed by the default Doubao browser cache directory. If your old data/profile/ already exists, the service reuses that legacy path as the built-in default browser cache unless you set DOUBAO_PROFILE_DIR.

Management UI

Open:

http://127.0.0.1:8011/providers/flow/ui

The page can:

  • list existing Flow browser caches
  • list existing Doubao browser caches
  • list existing Dyks browser caches
  • show a user-facing guide tab that summarizes the current deployment entry points, login workflow, common API routes, and minimal request examples
  • show the shared noVNC remote desktop directly inside the same management page
  • create a new browser cache directory
  • open a visible login window for a selected browser cache
  • check login state for a selected browser cache
  • enable or disable a browser cache for API use
  • run a direct Banana image generation test against a selected browser cache, including optional project-image references or local image files
  • run a direct Doubao Seedance background video generation test against a selected browser cache and poll for status in the page
  • run Dyks goods-catalog, goods-schema, and purchase-prefill tests against a selected browser cache
  • inspect daily / weekly / monthly API usage summaries and recent call events for each browser cache

/providers/doubao/ui and /providers/dyks/ui point to the same shared React page. Each provider-scoped UI route now appends ?tab=<provider>, so opening one of those URLs lands directly on the matching tab instead of always defaulting to Flow. The shared page also exposes a dedicated ?tab=guide usage-summary tab for non-developer users. It summarizes the current deployment entry points, login workflow, common routes, and minimal request examples, while /docs and /redoc remain the full parameter references. The shared page includes a remote desktop panel from /desktop/, but it stays disconnected until you explicitly connect it or trigger a login-window action, so opening /ui/ no longer auto-shows stale login windows.

By default the Flow browser cache registry is stored under data/providers/flow/accounts.json, cache profiles live under data/providers/flow/profiles/<account_id>/, and generated media is exported under test/results/browser_api_proxy/providers/flow/output/<run_id>/. If you still use the legacy single-profile directory data/profile/ or a custom FLOW_PROFILE_DIR, the service registers that path as the built-in default browser cache for compatibility.

The provider also stores per-project media history counters under data/providers/flow/history_counters.json. Once a browser cache accumulates 100 generated media cards inside the same Flow project, the next generation call deletes that project's existing media cards before submitting the new request.

The provider stores per-cache API usage events under data/providers/flow/usage_events.json. You can also query the aggregated monitoring data directly with GET /providers/flow/usage/summary?period=day|week|month.

Doubao stores its browser cache registry under data/providers/doubao/accounts.json, profiles under data/providers/doubao/profiles/<account_id>/, generated media under test/results/browser_api_proxy/providers/doubao/output/<run_id>/, background video job snapshots under data/providers/doubao/video_jobs.json, and usage events under data/providers/doubao/usage_events.json. The service no longer auto-reuses data/output; set FLOW_OUTPUT_DIR or DOUBAO_OUTPUT_DIR explicitly if you need a custom legacy output root. It also keeps Doubao daily quota as a local per-day cache: startup and midnight rollover only advance the local day marker and clear stale balances, and the service will not open Doubao pages just to refresh quota. The next real video call or a manual session check writes back whatever quota text was actually visible on the page. You can query its aggregated monitoring data directly with GET /providers/doubao/usage/summary?period=day|week|month.

Generate image

$body = @{
  account_id = "default"
  model = "banana-2"
  prompt = "cinematic portrait of a tiny robot sculptor in a paper workshop, volumetric lighting"
  aspect_ratio = "1:1"
  resolution = "2k"
  n = 2
  response_format = "url"
  reference_images = @(
    @{
      project_asset_name = "robot-reference.png"
    }
  )
} | ConvertTo-Json -Depth 6

Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8011/providers/flow/v1/images/generations -ContentType application/json -Body $body

See also:

  • api_doc/flow/banana.md OpenAI-style request and response details for the Flow Banana wrapper

Generate video

$body = @{
  account_id = "default"
  model = "veo-3.1-fast"
  prompt = "a small wooden boat drifting through a glowing cave, cinematic water reflections"
  mode = "ingredients"
  aspect_ratio = "16:9"
  n = 1
  response_format = "url"
  reference_images = @(
    @{
      project_asset_name = "boat-reference.png"
    }
  )
} | ConvertTo-Json -Depth 6

Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8011/providers/flow/v1/videos/generations -ContentType application/json -Body $body

See also:

  • api_doc/flow/veo31.md OpenAI-style request and response details for the Flow Veo 3.1 wrapper

Generate Doubao video

$body = @{
  account_id = "default"
  model = "seedance-2.0"
  prompt = "a small wooden figure stands beside a sea cliff lighthouse, strong ocean wind, cinematic realism"
  n = 1
  response_format = "url"
  timeout_sec = 3600
} | ConvertTo-Json

Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8011/providers/doubao/v1/videos/generations -ContentType application/json -Body $body

For this synchronous OpenAI-style endpoint, timeout_sec no longer acts as a hard final-result deadline. It is treated as the submission / page-health watchdog window. If the Doubao page stays healthy and keeps exposing the task state, the wrapper will continue waiting past that wall-clock duration until Doubao eventually succeeds or explicitly fails.

See also:

  • api_doc/doubao/video.md OpenAI-style request and response details for the Doubao Seedance wrapper

Environment variables

Shared runtime:

  • BROWSER_API_BROWSERS_DIR Shared Playwright browser directory
  • BROWSER_API_HEADLESS Default headless mode for browser-driven providers
  • BROWSER_API_NAVIGATION_TIMEOUT_MS Shared Playwright navigation timeout
  • BROWSER_API_POLL_INTERVAL_MS Shared polling interval
  • BROWSER_API_BROWSER_PROXY Shared browser proxy override

Flow provider:

  • FLOW_URL Default: https://labs.google/fx/tools/flow
  • FLOW_HEADLESS Flow-specific default headless mode; checked before falling back to BROWSER_API_HEADLESS
  • FLOW_PROFILE_DIR Legacy default Flow browser profile directory; still mapped to the built-in default browser cache
  • FLOW_OUTPUT_DIR Flow output root for saved media; default test/results/browser_api_proxy/providers/flow/output/
  • FLOW_GENERATION_TIMEOUT_SEC Flow generation timeout; default 1800
  • FLOW_HISTORY_COUNTER_PATH Persistent counter file for per-project media history cleanup
  • FLOW_USAGE_LOG_PATH Persistent event log for the cache usage monitoring dashboard
  • FLOW_HISTORY_CLEANUP_THRESHOLD Number of generated media cards to accumulate before the next call clears the current project history; default 100
  • FLOW_PROMPT_SELECTORS Override prompt selectors, split multiple selectors with ||
  • FLOW_GENERATE_BUTTON_PATTERNS Override generate button text patterns, split with ||
  • FLOW_DOWNLOAD_BUTTON_PATTERNS Override download button text patterns, split with ||
  • FLOW_HISTORY_MORE_BUTTON_PATTERNS Override media card menu button text patterns used by history cleanup, split with ||
  • FLOW_HISTORY_DELETE_BUTTON_PATTERNS Override delete action text patterns used by history cleanup, split with ||
  • FLOW_HISTORY_CONFIRM_BUTTON_PATTERNS Override delete-confirm action text patterns used by history cleanup, split with ||

Legacy FLOW_HEADLESS, FLOW_NAVIGATION_TIMEOUT_MS, FLOW_POLL_INTERVAL_MS, FLOW_BROWSER_PROXY, and related settings are still accepted as fallbacks for existing local setups.

Doubao provider:

  • DOUBAO_CHAT_URL Default: https://www.doubao.com/chat
  • DOUBAO_VIDEO_URL Default: https://www.doubao.com/chat/create-video
  • DOUBAO_PROFILE_DIR Legacy default Doubao browser profile directory; still mapped to the built-in default browser cache
  • DOUBAO_OUTPUT_DIR Doubao output root for saved media; default test/results/browser_api_proxy/providers/doubao/output/
  • DOUBAO_USAGE_LOG_PATH Persistent event log for the Doubao usage monitoring dashboard
  • DOUBAO_VIDEO_JOBS_PATH Persistent registry for management-page Doubao background video jobs
  • DOUBAO_GENERATION_TIMEOUT_SEC Doubao video watchdog window; default 3600
  • DOUBAO_PROMPT_SELECTORS Override prompt selectors, split multiple selectors with ||
  • DOUBAO_SEND_BUTTON_SELECTORS Override send-button selectors, split multiple selectors with ||
  • DOUBAO_LOGIN_BUTTON_PATTERNS Override login-button text patterns, split with ||
  • DOUBAO_DOWNLOAD_BUTTON_PATTERNS Override download-button text patterns, split with ||

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages