fix: BatchesService::results() crashes — missing stream parameter#15
Open
clowerweb wants to merge 1 commit intoanthropics:mainfrom
Open
fix: BatchesService::results() crashes — missing stream parameter#15clowerweb wants to merge 1 commit intoanthropics:mainfrom
clowerweb wants to merge 1 commit intoanthropics:mainfrom
Conversation
The `/v1/messages/batches/{id}/results` endpoint returns
`application/x-jsonl` (multiple JSON objects). The `results()` method
in both `BatchesRawService` (Messages and Beta\Messages) was missing
the `stream: JsonLStream::class` parameter in the `$this->client->request()`
call, while the sibling `resultsStream()` method correctly included it.
Without this parameter, `RawResponse::parse()` attempts to coerce a
Generator into a single `MessageBatchIndividualResponse` model, causing
a runtime crash.
This also updates return types from `MessageBatchIndividualResponse` to
`BaseStream` across contracts and services to match the actual streamed
response shape.
Fixes anthropics#8
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Yes |
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
Fixes #8
BatchesRawService::results()was missingstream: JsonLStream::classin its$this->client->request()call, causingRawResponse::parse()to try to coerce a Generator into a singleMessageBatchIndividualResponsemodel (runtime crash)MessageBatchIndividualResponsetoBaseStreamacross contracts and services to match the actual JSONL streamed response shapeMessages) and beta (Beta\Messages) namespacesRoot Cause
The
/v1/messages/batches/{id}/resultsendpoint returnsapplication/x-jsonl(multiple JSON objects, one per line). The siblingresultsStream()method correctly passesstream: JsonLStream::classto$this->client->request(), but theresults()method was missing this parameter.This appears to be a Stainless codegen template bug: the JSONL endpoint handler generates the
stream:parameter for the*Stream()variant but omits it for the non-streamresults()variant. Both methods hit the same JSONL endpoint and need the stream class to parse correctly. This should be fixed in the codegen templates upstream so it doesn't regress on the next generation pass.Note: PR #13 (v0.6.0) does not fix this issue.
Files Changed (8)
src/Services/Messages/BatchesRawService.phpstream: JsonLStream::classtoresults()src/Services/Messages/BatchesService.phpBaseStream, added@returnphpdocsrc/ServiceContracts/Messages/BatchesContract.phpBaseStream, added@returnphpdocsrc/ServiceContracts/Messages/BatchesRawContract.php@returnphpdoc toBaseResponse<BaseStream<…>>src/Services/Beta/Messages/BatchesRawService.phpstream: JsonLStream::classtoresults()src/Services/Beta/Messages/BatchesService.phpBaseStream, added@returnphpdocsrc/ServiceContracts/Beta/Messages/BatchesContract.phpBaseStream, added@returnphpdocsrc/ServiceContracts/Beta/Messages/BatchesRawContract.php@returnphpdoc toBaseResponse<BaseStream<…>>Test Plan
composer run test— existing tests passcomposer run lint(PHPStan) — no type errorsresults()now returns aBaseStreamthat can be iterated forMessageBatchIndividualResponseobjects, matchingresultsStream()behavior🤖 Generated with Claude Code