Skip to content

[SCR-383] Auto-Mode (--mode auto / --max-cost) support#26

Open
kostas-jakeliunas-sb wants to merge 1 commit into
mainfrom
SCR-383/auto-mode
Open

[SCR-383] Auto-Mode (--mode auto / --max-cost) support#26
kostas-jakeliunas-sb wants to merge 1 commit into
mainfrom
SCR-383/auto-mode

Conversation

@kostas-jakeliunas-sb

@kostas-jakeliunas-sb kostas-jakeliunas-sb commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Merge order: part of the [SCR-383] Auto-Mode client rollout — merge once the server PR ScrapingBee/scrapingbee-API#1242 is merged + the flag is enabled.

tl;dr

Adds Auto-Mode to the scrapingbee scrape command: --mode auto lets the API pick the cheapest scraping config that succeeds and charges only for the winning config; --max-cost N caps the credits a request may spend. Threaded through all four layers (command → cli_utils → client → tests), mirroring the SCR-426 --tag pattern. Versioned 1.4.5. Server feature is beta + flag-gated — do not merge until it ships.

Summary

  • src/scrapingbee_cli/commands/scrape.py — new --mode (click.Choice(["auto"])) and --max-cost (int) options in the option group; added to scrape_cmd signature; passed into build_scrape_kwargs(...). Three validation guards in the try: block (matching existing guard style):
    • --mode auto + any of --render-js / --premium-proxy / --stealth-proxy / --transparent-status-code (presence, even false) → error + exit 1 (Auto-Mode picks these itself; the server 400s the combo).
    • --max-cost without --mode auto → error + exit 1.
    • --max-cost < 1 → error via the existing _validate_range pattern.
  • src/scrapingbee_cli/cli_utils.pybuild_scrape_kwargs() gains mode / max_cost (signature + returned dict; scrape_kwargs_to_api_params auto-passes through). write_output() verbose block now surfaces the Spb-auto-cost response header as Auto Credit Cost, alongside Spb-cost.
  • src/scrapingbee_cli/client.pyClient.scrape() gains mode / max_cost; added to the params list. _clean_params() drops None, so an omitted --max-cost = uncapped for free.
  • tests/unit/test_client.pyTestModeParam + TestMaxCostParam (sent-when-set / omitted-when-unset), mirroring TestTagParam via patched client._get.
  • tests/unit/test_cli.pyTestModeAutoGuards: command-level guard tests (CliRunner + patched get_api_key) for all conflicting-option combos, --max-cost requiring --mode auto, --max-cost < 1, and the valid pass-through cases.
  • Docsskills/scrapingbee-cli/reference/scrape/options.md gains a dedicated Auto-Mode section + --mode / --max-cost rows; README.md key-features bullet; CHANGELOG.md [1.4.5] entry. Propagated to all mirror dirs via ./sync-skills.sh.
  • Version — bumped 1.4.4 → 1.4.5 across all version-bearing files (pyproject.toml, __init__.py ×2, plugin.json, AGENTS.md upgrade line, canonical + guard SKILL.md frontmatter, synced mirrors).

Test plan

  • pytest -m "not integration"760 passed, 9 deselected.
  • ruff check src tests → clean. ruff format --check src tests → clean (after format).
  • check-version consistency: pyproject.toml == __init__.py == 1.4.5.
  • scrapingbee --version1.4.5; scrape --help shows --mode [auto] and --max-cost INTEGER.
  • End-to-end guard smoke (real CLI binary): all three guards exit 1 with the exact messages.
  • Live request against the server once Auto-Mode ships on prod (verify Spb-auto-cost header rendering + actual cheapest-config charging).

Versioning note

Versioned 1.4.5 off main v1.4.4. The open REPL PR #19 (not a draft, no CI) self-bumped to 1.5.0. If #19 merges first, rebase and re-bump (likely 1.5.1 or 1.6.0) to keep the check-version job green and avoid a duplicate/back-numbered tag — version/CHANGELOG may need amending depending on merge order.

Cross-link: #19

🤖 Generated with Claude Code

Add Auto-Mode to the `scrape` command, mirroring the server-side beta feature.
The API picks the cheapest scraping config that succeeds (cheap -> expensive,
stops at first success) and charges only for the winning config.

- scrape.py: `--mode` (Choice[auto]) + `--max-cost` (int) options; signature;
  pass-through to build_scrape_kwargs; validation guards (mode-auto vs
  render_js/premium_proxy/stealth_proxy/transparent_status_code incompatibility,
  max_cost requires mode=auto, max_cost >= 1 via _validate_range).
- cli_utils.py: build_scrape_kwargs mode/max_cost; surface Spb-auto-cost header
  ("Auto Credit Cost") in write_output verbose block.
- client.py: Client.scrape() mode/max_cost params (omitted when None).
- Tests: TestModeParam + TestMaxCostParam (test_client.py) and
  TestModeAutoGuards command-level guard tests (test_cli.py).
- Docs: SKILL.md reference/scrape/options.md (Auto-Mode section), README,
  CHANGELOG [1.4.5]; synced via sync-skills.sh.
- Version bumped 1.4.4 -> 1.4.5 across all version-bearing files.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kostas-jakeliunas-sb kostas-jakeliunas-sb marked this pull request as ready for review June 30, 2026 12:57
@kostas-jakeliunas-sb kostas-jakeliunas-sb changed the title [DRAFT — DO NOT MERGE] [SCR-383] Auto-Mode (--mode auto / --max-cost) support [SCR-383] Auto-Mode (--mode auto / --max-cost) support Jun 30, 2026
@kostas-jakeliunas-sb kostas-jakeliunas-sb self-assigned this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants