PHPackages                             tacman/ai-batch-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. tacman/ai-batch-bundle

ActiveSymfony-bundle[Queues &amp; Workers](/categories/queues)

tacman/ai-batch-bundle
======================

Async batch AI processing for Symfony. Implements OpenAI Batch API and Anthropic Message Batches with Symfony Scheduler polling. Proposed for symfony/ai.

0.3(1mo ago)19↑2566.7%MITPHPPHP ^8.4

Since Mar 16Pushed 1mo agoCompare

[ Source](https://github.com/tacman/ai-batch-bundle)[ Packagist](https://packagist.org/packages/tacman/ai-batch-bundle)[ RSS](/packages/tacman-ai-batch-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (4)Used By (0)

tacman/ai-batch-bundle
======================

[](#tacmanai-batch-bundle)

Async batch AI processing for Symfony. Implements the **OpenAI Batch API** and **Anthropic Message Batches API** with a Symfony Scheduler poller.

**Proposed for inclusion in [symfony/ai](https://github.com/symfony/ai)** as `BatchCapablePlatformInterface` — a 5-method extension of `PlatformInterface`.

---

Why batch?
----------

[](#why-batch)

SynchronousBatch APICost$0.0008 / image (gpt-4o-mini)**$0.0004 / image (50% off)**Rate limitsStandard pool**Separate, much higher pool**Timeout riskYes (large sets)**None — 24h window**ResultsImmediate~10 min (up to 24h)Best forInteractive, ≤100 items**Enrichment pipelines, ≥1000 items**---

Quick demo
----------

[](#quick-demo)

The `demo/` directory shows the full pattern with a fun example: generate programmer-targeted advertising copy for products from [dummyjson.com](https://dummyjson.com), using product images (vision) + descriptions.

```
cd demo
composer install
# Add your OPENAI_API_KEY to .env.local

# Synchronous — 2 products, results immediately
bin/console app:ads --limit=2

# Batch — all 194 products, 50% cheaper
bin/console app:ads --batch

#  ✅ 194 products submitted to OpenAI Batch API (50% cost discount applies!)
#  ┌──────────────────┬────────────────────────────┐
#  │ Local batch ID   │ 1                          │
#  │ Provider batch   │ batch_6789abc...            │
#  │ Status           │ submitted                  │
#  │ Requests         │ 194                        │
#  │ Est. cost        │ $0.0776                    │
#  │ vs sync cost     │ $0.1552 (you save $0.0776) │
#  └──────────────────┴────────────────────────────┘
#
#  Results will be ready in ~10 minutes.
#    bin/console app:fetch-batch 1

# Check status and display results
bin/console app:fetch-batch 1

#  > ⏳ Still processing (47 / 194)

bin/console app:fetch-batch 1

#  > ✅ completed
#
#  Product #1 — Essence Mascara Lash Princess ($9.99)
#    Like git blame for your lashes — it shows exactly who's responsible
#    for those dramatic, volumizing commits. Cruelty-free, just like your
#    code reviews should be.
#
#  Product #2 — Fingertip Skateboard ($29.99)
#    Finally, something you can debug with your fingers. Ships in 3-5 days,
#    which is faster than your CI pipeline.

# Watch mode — polls every 30s until done
bin/console app:fetch-batch 1 --watch
```

---

Installation
------------

[](#installation)

```
composer require tacman/ai-batch-bundle
```

Add to `config/bundles.php`:

```
Tacman\AiBatch\TacmanAiBatchBundle::class => ['all' => true],
```

Add to `.env`:

```
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...  # optional

```

Run the schema update:

```
bin/console doctrine:schema:update --force
```

---

Usage
-----

[](#usage)

### Build and submit a batch

[](#build-and-submit-a-batch)

```
use Tacman\AiBatch\Model\BatchRequest;
use Tacman\AiBatch\Service\AiBatchBuilder;

$batch = $batchBuilder->build(
    datasetKey:     'my-collection',
    task:           'image_enrichment',
    records:        $normalizedRecords,         // iterable
    requestFactory: fn(array $row) => new BatchRequest(
        customId:     $row['id'],
        systemPrompt: 'You are a museum cataloguer...',
        userPrompt:   'Describe this image and extract keywords.',
        model:        'gpt-4o-mini',
        imageUrl:     $row['thumbnail_url'],    // image_url, not base64
    ),
);

$batch = $batchBuilder->submit($batch);
$entityManager->persist($batch);
$entityManager->flush();

echo "Batch #{$batch->id} submitted: {$batch->providerBatchId}";
```

### Check and apply results

[](#check-and-apply-results)

```
$job = $batchClient->checkBatch($batch->providerBatchId);

if ($job->isComplete()) {
    foreach ($batchClient->fetchResults($job) as $result) {
        // $result->customId maps back to your record id
        // $result->content is the parsed JSON response
        $enrichment = MediaEnrichment::fromNormalized($records[$result->customId]);
        $enrichment->applyAiEnrichment($result->content);
        // push to zm, update DB, etc.
    }
}
```

### Automatic polling with Symfony Scheduler

[](#automatic-polling-with-symfony-scheduler)

The bundle registers a `PollBatchesTask` that fires every 2 minutes. It dispatches `PollBatchesMessage` which your handler processes:

```
// In your app — implement a handler that calls checkBatch() on all
// AiBatch entities with status='processing'
```

---

Proposed symfony/ai interface
-----------------------------

[](#proposed-symfonyai-interface)

This bundle implements `BatchCapablePlatformInterface` — proposed for `symfony/ai` as a 5-method extension of `PlatformInterface`:

```
interface BatchCapablePlatformInterface
{
    public function supportsBatch(): bool;
    public function submitBatch(array $requests, array $options = []): BatchJob;
    public function checkBatch(string $batchId): BatchJob;
    public function fetchResults(BatchJob $job): iterable;  // yields BatchResult
    public function cancelBatch(string $batchId): BatchJob;
}
```

Implementations:

- ✅ `OpenAiBatchClient` — OpenAI `/v1/batches`
- ✅ `AnthropicBatchClient` — Anthropic `/v1/messages/batches`
- ❌ Mistral — no batch API yet
- 📋 Google Vertex AI batch prediction — planned

---

License
-------

[](#license)

MIT — contributions welcome.

###  Health Score

40

—

FairBetter than 87% of packages

Maintenance97

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/21b39551f92ed4143772c622f9e571589c5a72c96ab3c53fe67489ce0d83e806?d=identicon)[tacman1123](/maintainers/tacman1123)

---

Top Contributors

[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (7 commits)")

---

Tags

asyncsymfonyaiopenaibatchanthropic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tacman-ai-batch-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tacman-ai-batch-bundle/health.svg)](https://phpackages.com/packages/tacman-ai-batch-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M646](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1022.4k](/packages/rcsofttech-audit-trail-bundle)[forumify/forumify-platform

121.8k11](/packages/forumify-forumify-platform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
