> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instructorphp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Batch inference partial results

## Overview

xAI can publish results while a job is still running. This deterministic
example models two reads; the same key appears again, so a consumer should
upsert by its caller key.

## Example

```php theme={null}
<?php
require 'examples/boot.php';
require __DIR__.'/../Support/DemoBatch.php';

use Cognesy\Polyglot\BatchInference\Enums\BatchResultsAvailability;
use Examples\BatchInference\Support\DemoBatch;

$batches = DemoBatch::client(partial: true);
$reference = $batches->submit(DemoBatch::items())->reference();
$first = $batches->results($reference);
$firstKeys = array_map(static fn ($item): string => $item->key(), iterator_to_array($first->items()));
$later = $batches->results($reference);
$laterKeys = array_map(static fn ($item): string => $item->key(), iterator_to_array($later->items()));

if ($first->availability() !== BatchResultsAvailability::Partial
    || $firstKeys !== ['row-1'] || $laterKeys !== ['row-1']) {
    throw new RuntimeException('Partial result reread behaved unexpectedly.');
}
echo "Partial result key row-1 appeared in both snapshots\n";
?>
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.