Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/phpaisdk/core/llms.txt

Use this file to discover all available pages before exploring further.

aisdk/core is distributed through Packagist and installed with Composer. The core package contains no HTTP transport — you always pair it with at least one provider package that handles the actual API calls. This page walks you through a complete installation from scratch.

Installation Steps

1

Install the core package

Add aisdk/core to your project using Composer:
composer require aisdk/core
This pulls in the contracts, fluent generation API, value objects, and all PSR dependencies listed below.
2

Install a provider package

Install the provider for whichever AI service you want to use. The OpenAI provider is shown here as the primary example:
composer require aisdk/openai
If you prefer Anthropic:
composer require aisdk/anthropic
You can install multiple providers in the same project and switch between them per request by passing a different model instance to ->model().
3

HTTP client auto-discovery

No additional HTTP client setup is required. aisdk/core depends on guzzlehttp/guzzle and uses php-http/discovery to automatically locate a PSR-18-compatible HTTP client at runtime. Because Guzzle is already a required dependency, Psr18ClientDiscovery::find() resolves it without any manual wiring.If you want to supply your own PSR-18 client — for example to add middleware or use a mock in tests — see the Custom HTTP Client section below.

Requirements

RequirementVersion
PHP^8.3
guzzlehttp/guzzle^7.8
php-http/discovery^1.19
psr/container^2.0
psr/http-client^1.0
psr/http-factory^1.1
psr/http-message^2.0
psr/log^3.0
psr/simple-cache^3.0

Framework Integration

aisdk/core has no opinion about your application framework. It works in any PHP environment:

Laravel

Register Generate::model(...) in a service provider’s boot() method. No additional service container binding is required.

Symfony

Call Generate::model(...) in a kernel event listener or compiler pass. The SDK’s SdkFactory accepts a PSR-11 ContainerInterface if you want tighter integration.

Plain PHP

Call Generate::model(...) anywhere before your first generation call — in index.php, a bootstrap file, or a CLI entry point.

Custom HTTP Client

By default the SDK auto-discovers Guzzle via php-http/discovery. To override this — for example to inject a logger, add retry middleware, or use a test double — build a custom Sdk instance with SdkFactory and pass it to Generate::configure():
use AiSdk\Generate;
use AiSdk\Support\SdkFactory;

$sdk = (new SdkFactory())
    ->withHttpClient($yourPsr18Client)
    ->withRequestFactory($yourRequestFactory)
    ->withStreamFactory($yourStreamFactory)
    ->withLogger($yourPsrLogger)
    ->withDefaultModel(OpenAI::model('gpt-4o'))
    ->make();

Generate::configure($sdk);
SdkFactory is fully fluent — every with*() method returns the same instance, so you can chain as many or as few options as you need. Any collaborator you omit is auto-discovered from your installed PSR packages.

Build docs developers (and LLMs) love