> ## 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 cancel

## Overview

Cancellation returns an acknowledgement, not proof of a cancelled final
state. Completion can win the race and its outcomes remain readable.

## Example

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

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

$batches = DemoBatch::client();
$reference = $batches->submit(DemoBatch::items())->reference();
$receipt = $batches->cancel($reference);
$later = $batches->retrieve($reference);
$outcomes = iterator_to_array($batches->results($reference)->items());

if (!$receipt->acknowledged() || $receipt->alreadyTerminal()
    || $later->status() !== BatchStatus::Completed || count($outcomes) !== 2) {
    throw new RuntimeException('Cancellation race was not represented faithfully.');
}
echo "Cancellation acknowledged; later state completed with retained outcomes\n";
?>
```


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