PHPackages                             survos/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. survos/ai-batch-bundle

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

survos/ai-batch-bundle
======================

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

2.0.170(2d ago)017↑76.5%MITPHPPHP ^8.4

Since Mar 20Pushed yesterdayCompare

[ Source](https://github.com/survos/ai-batch-bundle)[ Packagist](https://packagist.org/packages/survos/ai-batch-bundle)[ GitHub Sponsors](https://github.com/kbond)[ RSS](/packages/survos-ai-batch-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (8)Used By (0)

survos/ai-batch-bundle
======================

[](#survosai-batch-bundle)

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

Include Entity for storage

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

Moved from tacman to add data-bundle and other survos-specific tooling

---

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

45

—

FairBetter than 93% of packages

Maintenance100

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

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 ~0 days

Total

7

Last Release

2d 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 (2 commits)")

---

Tags

asyncsymfonyaiopenaibatchanthropic

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[toin0u/geotools-laravel

Geo-related tools PHP library for Laravel 4 &amp; 5

250387.6k1](/packages/toin0u-geotools-laravel)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46554.9k5](/packages/deepseek-php-deepseek-php-client)[toin0u/geotools

Geo-related tools PHP 7.3+ library

1.4k1.2k](/packages/toin0u-geotools)[modelflow-ai/symfony-bundle

An integration of modelflow-ai via a bundle into the Symfony Framework.

1517.1k](/packages/modelflow-ai-symfony-bundle)

PHPackages © 2026

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