Skip to content

Batch results are not converted to individual response objects #30

Description

@yuniorsk

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions