Skip to content

Warn when request dicts contain unrecognized keys - #138

Open
aryannpanwarr wants to merge 1 commit into
hyperbrowserai:mainfrom
aryannpanwarr:warn-unknown-request-keys
Open

aryannpanwarr wants to merge 1 commit into
hyperbrowserai:mainfrom
aryannpanwarr:warn-unknown-request-keys

Conversation

@aryannpanwarr

Copy link
Copy Markdown

Problem

If you pass an option name the SDK doesn't recognize, it's silently dropped and the default (False) is sent instead. No error, no warning.

We hit this on Oct 11 while testing the SDK (1.10.0, still present in 1.11.0) against the live API on a free-plan key:

What we passed What the SDK sent What the API did
{"use_stealth": True, "solve_captchas": True} useStealth: True, solveCaptchas: True 402: free plan doesn't support captchas ✅
{"use_stealth": True, "solve_captcha": True} (typo) useStealth: True, solveCaptchas: False session created, no error
{"useStealth": True, "solveCaptchas": True} (API/Node names) useStealth: False, solveCaptchas: False session created, no error

So a one-letter typo, or copying option names from the API docs or the Node SDK, turns the feature off and you still get (and pay for) a session. You only find out later when a site blocks you.

Fix

coerce_request (which every dict request goes through) now checks the keys against the request model and warns about the ones that would be dropped, with a suggestion:

UserWarning: CreateSessionParams ignored unrecognized params keys:
'solve_captcha' (did you mean 'solve_captchas'?). These options were not sent to the API.

UserWarning: CreateSessionParams ignored unrecognized params keys:
'useStealth' (use 'use_stealth'), 'solveCaptchas' (use 'solve_captchas'). ...
  • Checks nested models too (scrape_options.only_main → did you mean only_main_content?).
  • Skips user-owned data: JSON schemas, dict-keyed fields like mounts, custom_action, and anything typed as a dict or Any.
  • Warning, not an error, so existing code keeps running. Payloads are unchanged. Happy to switch it to raise if you'd prefer.
  • Legacy Pydantic model inputs are untouched.

Testing

  • 7 new tests in tests/test_unknown_request_keys.py.
  • Full non-E2E suite passes on Python 3.8 and 3.12 (681 tests), also with -W error::UserWarning to make sure no existing valid request triggers a false warning.
  • ruff check / ruff format clean (0.3.7).
  • Re-ran the live calls above with this branch: the warning points at the caller's line.

🤖 Generated with Claude Code

Request dictionaries are validated against pydantic models that ignore
unknown keys, so a typo such as "solve_captcha" or a wire-format name
such as "useStealth" was dropped silently and the default (False) was
sent instead. The session was created with the feature off and no error.

coerce_request now emits a UserWarning listing each unrecognized key,
including nested request models, with a suggestion ("did you mean
'solve_captchas'?" / "use 'use_stealth'"). Open mappings such as JSON
schemas, mounts and custom actions are not checked. Payloads are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant