-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Hi, BatchesService::results() has incorrect return type causing PHP runtime error:
Anthropic\Core\Services\Beta\Messages\BatchesService::results(): Return value must be of type
Anthropic\Beta\Messages\Batches\MessageBatchIndividualResponse,
Generator returned in
/home/leon/public_html/vendor/anthropic-ai/sdk/src/Core/Services/Beta/Messages/BatchesService.php(272)
Declared return type: MessageBatchIndividualResponse
Actual return type: Generator<MessageBatchIndividualResponse>
Environment:
- PHP: 8.4+
- SDK version: 0.3.0 (0.4.0 not released due to failing "Create releases / release (push)" job)
declare(strict_types=1)enabled
Workaround
Use client->request() directly to bypass the buggy method:
public function retrieveBatchResult(AnthropicBatchId $batch_id): MessageBatchIndividualResponse
{
$generator = $this->client->request(
method: 'get',
path: sprintf('/v1/messages/batches/%s/results', $batch_id->value),
headers: [
'Accept' => 'application/x-jsonl',
'anthropic-beta' => 'message-batches-2024-09-24',
],
);
$complete_content = implode('', iterator_to_array($generator));
$decoded = json_decode($complete_content, true, 512, JSON_THROW_ON_ERROR);
return Conversion::coerce(MessageBatchIndividualResponse::class, value: $decoded);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels