feat(anthropic-payload): add build_batches_request_params (v0.40.1 → v0.41.0) (L334)#85
Merged
Merged
Conversation
…v0.41.0) (L334)
Adds `build_batches_request_params` — a Batches-API-shaped sibling of
`build_messages_payload`. Returns `{custom_id, params}` ready to splat
into `messages.batches.create(requests=[...])`. The embedded `params`
dict runs through `validate_payload`, so the server-tool ⊥ assistant-
prefill invariant covers Batches consumers too — a future judge call
that mixes `web_search` with a prefill won't reach HTTP 400.
Differs from `build_messages_payload` along three axes the judge-batch
path requires:
1. **Optional system prompt.** Synchronous callers nearly always have a
static system; judge batches inline the rubric into user content and
have no system block. `system_prompt=None` default emits no system.
2. **No cache_control by default.** Batches API discounts 50% before
prompt caching applies — marginal cache value is small enough that
the existing judge path opts out. `cache_system=False` default;
opt-in for large repeated system prompts.
3. **Explicit tool_choice.** Forced tool calls (`{"type": "tool",
"name": ...}`) are the dominant Batches use case (structured output
via a known schema). Pass `tool_choice` directly rather than
smuggling through `extra`.
Lib version: v0.40.1 → v0.41.0 (minor bump — additive new function).
Tests: 6 new in `test_anthropic_payload.py`:
- `test_build_batches_request_params_judge_shape` (replicates ae-research
evals/judge.py::build_judge_batch_request shape)
- `test_build_batches_request_params_with_system_prompt_no_cache_default`
- `test_build_batches_request_params_with_system_prompt_cache_opt_in`
- `test_build_batches_request_params_validates_server_tool_prefill_invariant`
- `test_build_batches_request_params_no_system_no_tools_minimal`
- `test_build_batches_request_params_extra_merges_into_params`
ROADMAP: **L334** part 1/2 — lib substrate. Part 2 = alpha-engine-research
PR migrating `evals/judge.py::build_judge_batch_request` to use the new
helper + bumping the lib pin.
Suite: 899 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
build_batches_request_params— a Batches-API-shaped sibling ofbuild_messages_payload. Returns{custom_id, params}ready to splat intomessages.batches.create(requests=[...]). The embeddedparamsdict runs throughvalidate_payload, so the server-tool ⊥ assistant-prefill invariant covers Batches consumers too.Differs from build_messages_payload
Why
ROADMAP L334 —
alpha-engine-researchis the second consumer ofanthropic_payload, but its actual raw-SDK call surface is Batches (messages.batches.create), not synchronousmessages.create. Existing chokepoint didn't fit; this PR extends the substrate to cover both API shapes from one validated chokepoint.Part 1 of 2. Part 2 = ae-research PR migrating
evals/judge.py::build_judge_batch_request+ lib pin bump.Test plan
🤖 Generated with Claude Code