Warning
Unsupported, experimental, pre-1.0, no guarantees. This is an early PHP client for API Butter. It has no support, and any release can change or remove anything without notice. Pin an exact version if you try it.
A small Laravel client for two of API Butter's APIs:
Butter\Atlas\Pdf: render ateylabs.pdf/v1document, HTML or Markdown to PDF (POST /v1/pdf), and validate input for free (POST /v1/pdf/validate).Butter\Atlas\Data: list countries and currencies from API Butter's CLDR snapshot (GET /v1/data/countries,GET /v1/data/currencies).
Butter\Atlas\Invoice is planned for when API Butter's hosted invoicing exists. It is not here yet.
PHP 8.4 and Laravel 13.
APIBUTTER_KEY=abk_test_...
# Optional: APIBUTTER_API_URL=https://api.butter.pub, APIBUTTER_TIMEOUT=30The Data API is free during preview and accepts abk_test_ keys only. PDF rendering is metered; test keys are never charged and add a TEST watermark.
use Butter\Atlas\Pdf;
$pdf = app(Pdf::class)->render([
'schema' => 'teylabs.pdf/v1',
'blocks' => [
['type' => 'heading', 'level' => 1, 'text' => 'Quarterly summary'],
['type' => 'table', 'rows' => [['Item', 'Count'], ['Widgets', '12']]],
],
], idempotencyKey: 'report-2026-q4');
file_put_contents('summary.pdf', $pdf->bytes);
$pdf->cost; // "0.005"
$pdf->replayed; // true when the Idempotency-Key replayed a stored result
app(Pdf::class)->html('<h1>Hello</h1>');
app(Pdf::class)->markdown('# Hello');
// Free check, no key needed: null when valid, otherwise the problem with field-pointed errors.
$problem = app(Pdf::class)->validate($document);
$problem?->errors; // ['blocks.0.level' => ['…']]use Butter\Atlas\Data;
$page = app(Data::class)->countries(['codes' => ['CA', 'US'], 'limit' => 1]);
$page->data; // [['id' => 'CA', 'name' => 'Canada', 'currencies' => ['CAD'], …]]
$page->nextCursor; // pass back as 'cursor' with the same filters
// Every match, fetching pages lazily as you iterate.
app(Data::class)->allCurrencies(['tender' => true])->each(fn (array $currency) => …);Filters are the API's query parameters. codes takes a list or a comma-separated string, and tender takes a boolean.
Any non-2xx answer throws Butter\Atlas\Exceptions\AtlasException. Its problem holds API Butter's Problem Details: branch on code (insufficient_balance, test_keys_only, too_many_requests, …) and show detail to people. Error-specific members such as top_up_url are in problem->body. Network failures stay Laravel's ConnectionException.
Pdf and Data take a Butter\Atlas\Connection (key, host, timeout). Rebind Connection in the container to change it app-wide, or build one for a different key:
use Butter\Atlas\Connection;
use Butter\Atlas\Data;
use Illuminate\Http\Client\Factory;
$data = new Data(new Connection(app(Factory::class), $otherKey));Calls go through Laravel's HTTP client, so Http::fake() covers them in your tests.
composer install
composer test # Pest
composer analyse # PHPStan level 9
composer lint # Pint