Download the PHP package digitaldreams/local-batch-api without Composer

On this page you can find all versions of the php package digitaldreams/local-batch-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package local-batch-api

local-batch-api

Drop-in replacement for the Anthropic and OpenAI batch APIs — self-hosted, running against local Ollama or LM Studio. No API keys, no cloud costs, no rate limits.


Requirements


Installation

Step 1 — Install the package

Step 2 — Run migrations

This creates two tables: batches and batch_files.

Step 3 — Configure your inference backend

Add to your .env:

Step 4 — Start a queue worker

Batch jobs run asynchronously. The worker must be running:


Two Ways to Use This Package

This package supports two independent usage patterns:

Event-based REST API
Who calls it Your own Laravel code Any HTTP client (SDK, curl, external app)
Auth Laravel's existing auth Sanctum token (or your middleware)
Routes needed No Yes
Best for Internal pipelines, jobs, commands Replacing Anthropic/OpenAI SDK endpoints

Approach 1 — Event-based (Internal Usage)

Use this when your own Laravel application needs to submit and process batches. No HTTP routes required.

Submitting an Anthropic-format batch

Fire a SubmitAnthropicBatchEvent event. The package listener picks it up and dispatches the processing job automatically.

Submitting an OpenAI-format batch

The OpenAI flow requires a file ID. Upload first using the BatchService, then fire the event.

Listening for results

Listen to BatchCompletedEvent to act on results when processing finishes:

Register it in AppServiceProvider::boot():

All available events

Event Properties Fired when
BatchCreatedEvent $batch, $items, $provider Batch record saved, job dispatched
BatchProcessingEvent $batch Queue worker picks up the job
BatchItemStartedEvent $batch, $dto Single request about to fire
BatchItemCompletedEvent $batch, $result Single request finished
BatchCompletedEvent $batch, $results All requests done
BatchFailedEvent $batch, $exception Job threw an unrecoverable error
BatchCancelledEvent $batch Batch cancelled

Approach 2 — REST API (External HTTP Clients)

Use this when you want to point an existing Anthropic or OpenAI SDK at your local server instead of the cloud. The API surface is identical to the real APIs.

Step 1 — Register routes with authentication

Do not set BATCH_API_EXPOSE_ROUTES=true. Instead, register routes manually inside a protected middleware group so you control authentication.

Install Sanctum if you haven't already:

In your routes/api.php (or a service provider), wrap BatchApi::routes() with Sanctum middleware:

This registers all 11 endpoints, each requiring a valid Sanctum token.

Note: BatchApi::routes() also applies the api middleware internally. Wrapping it with auth:sanctum stacks both, so your routes have api + auth:sanctum.

Step 2 — Issue a token

Step 3 — Call the API

All requests need the token in the Authorization header:


Anthropic Batch API — Step by Step

1. Submit a batch

Response 202 Accepted:

2. Poll until done

Keep polling until processing_status is "ended".

3. Fetch results (NDJSON)

Returns 204 No Content if still processing. When ready, streams one JSON object per line:

Other Anthropic endpoints


OpenAI Batch API — Step by Step

1. Upload a JSONL file

Create a .jsonl file (one request per line):

Upload it:

Response 201 Created:

2. Submit the batch

Response 201 Created:

3. Poll until completed

Poll until status is "completed". Note the output_file_id in the response.

4. Download results

Returns JSONL, one result per line:

Other OpenAI endpoints


Pointing an existing SDK at this server

Python (Anthropic SDK):

Python (OpenAI SDK):


Batch Status Lifecycle

Internal Anthropic processing_status OpenAI status
pending in_progress validating
processing in_progress in_progress
completed ended completed
failed ended failed
cancelling canceling cancelling
cancelled ended cancelled

Batches expire after 24 hours.


Switching to LM Studio

  1. Open LM Studio → start the local server (default port 1234)
  2. Load a model
  3. Update .env:

No other changes needed.


Concurrency Tuning

INFERENCE_CONCURRENCY controls parallel requests per batch chunk.

Hardware Value
CPU-only 1
GPU with spare VRAM 35

Postman Collection

Import Local-Batch-API.postman_collection.json. Set the baseUrl variable to your server URL. The collection auto-saves batch IDs and file IDs between requests so you can run folders top-to-bottom without manually copying values.


Troubleshooting

Batches stay pending forever — Queue worker not running. Run php artisan queue:work.

Ollama timeout in results — Model is slow or INFERENCE_TIMEOUT too low. Raise to 300.

Routes return 404 — Routes not registered. Either set BATCH_API_EXPOSE_ROUTES=true (no auth) or call BatchApi::routes() manually in a middleware group.

401 Unauthorized on API routes — Sanctum token missing or invalid. Pass Authorization: Bearer <token> header.

cannot chdir git error in submodule — Run git submodule update --init in the parent repo.


License

MIT


All versions of local-batch-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
laravel/framework Version ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package digitaldreams/local-batch-api contains the following files

Loading the files please wait ...