Skip to content

refactor: remove _build_headers() side effect in Anthropic client#163

Merged
Kamilbenkirane merged 1 commit intomainfrom
refactor/anthropic-build-headers-side-effect
Feb 22, 2026
Merged

refactor: remove _build_headers() side effect in Anthropic client#163
Kamilbenkirane merged 1 commit intomainfrom
refactor/anthropic-build-headers-side-effect

Conversation

@Kamilbenkirane
Copy link
Member

Closes #159

Summary

  • _build_headers() no longer accepts request_body — it is now a pure function with signature _build_headers(beta_features: list[str] | None = None)
  • The request_body.pop("_beta_features", []) is moved to the two call sites (_make_request, _make_stream_request), making the mutation visible where it happens
  • _build_headers() now calls self._json_headers() (from APIMixin, added in refactor: add _json_headers() helper to APIMixin #162) as its base instead of duplicating the auth + Content-Type header construction inline
  • Removes the now-unused ApplicationMimeType import

Test plan

  • All pre-commit hooks pass (ruff, mypy, bandit, pytest) ✅
  • Behaviour is identical — _beta_features is still stripped from the request body before the HTTP call and translated into the anthropic-beta header

Move request_body.pop("_beta_features") to the two call sites
(_make_request, _make_stream_request) so _build_headers() becomes a
pure function. Also switches _build_headers() to use _json_headers()
from APIMixin as its base, removing the duplicated auth + Content-Type
header construction and the ApplicationMimeType import.
@claude
Copy link

claude bot commented Feb 22, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Kamilbenkirane Kamilbenkirane merged commit d96d115 into main Feb 22, 2026
11 checks passed
@Kamilbenkirane Kamilbenkirane mentioned this pull request Feb 24, 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.

refactor: clean up Anthropic _build_headers() side effect

1 participant