Hi, I am having trouble with retrieving batch results. Results are streamed back but they are not converted to individual response objects. I've tried to identify the problem and find that this snippet might be causing it. Content type header in the API response is empty and therefore this code is not executed. Once I hard-coded the required header value and this condition was met, everything worked as expected.
Does anyone else run into this issue? Thanks for help
|
if (preg_match(self::JSONL_CONTENT_TYPE, subject: $content_type)) { |
|
$it = self::streamIterator($body); |
|
$lines = self::decodeLines($it); |
|
|
|
return (function () use ($lines) { |
|
foreach ($lines as $line) { |
|
yield static::decodeJson($line); |
|
} |
|
})(); |
|
} |
Here's my code
<?php
use Anthropic\Client;
$client = new Client(
apiKey: getenv('ANTHROPIC_API_KEY') ?: 'my-anthropic-api-key'
);
$stream = $client->messages->batches->resultsStream('my-batch-id');
foreach ($stream as $result) {
var_dump($result); // result is a simple string containing just a part of the whole response
}
Hi, I am having trouble with retrieving batch results. Results are streamed back but they are not converted to individual response objects. I've tried to identify the problem and find that this snippet might be causing it. Content type header in the API response is empty and therefore this code is not executed. Once I hard-coded the required header value and this condition was met, everything worked as expected.
Does anyone else run into this issue? Thanks for help
anthropic-sdk-php/src/Core/Util.php
Lines 413 to 422 in 049b01e
Here's my code