Core AI abstraction layer for Laravel. Provides shared contracts, abstract managers, retry logic, cost tracking, conversation builders, token estimation, and CLI scaffolding for building AI provider packages on top of.
This package is the foundation shared by:
ubxty/bedrock-ai— AWS Bedrockubxty/azure-ai— Azure OpenAI
- PHP 8.2+
- Laravel 11 or 12
composer require ubxty/core-aiThe service provider is auto-discovered via Laravel's package discovery.
AiManagerContract— Interface all AI manager implementations must satisfy (invoke, converse, stream, syncModels, etc.)
AbstractAiManager— Base class handling cost limit checks, cost tracking, event dispatching, invocation logging, and retry orchestration. Extend this to build a provider-specific manager.
AbstractCredentialManager— Base class for multi-key credential rotation.HasRetryLogic— Trait providing retry loops, backoff, and error classification.ModelAliasResolver— Resolves friendly model aliases (e.g.claude-3.5) to full model IDs.
ConversationBuilder— Fluent builder for multi-turn conversations with multimodal support (text, images, documents).
ModelSpecResolver— Resolves context window and max token limits for known model IDs across all major providers.
TokenEstimator— Estimates token counts and cost for text, image, and document inputs.InvocationLogger— Structured invocation logging.
AbstractChatCommand— Base for interactiveartisan chatcommands.AbstractConfigureCommand— Base for provider configuration wizards.AbstractModelsCommand— Base for model listing commands.AbstractTestCommand— Base for provider test commands.AbstractDefaultModelCommand— Base for default model selection commands.WritesEnvFile— Trait for writing key=value pairs to.env.
AiInvoked,AiKeyRotated,AiRateLimited
AiException,ConfigurationException,CostLimitExceededException,RateLimitException
HealthCheckController— Base health check endpoint for AI connectivity probes.
To build a new AI provider package:
- Require
ubxty/core-aias a dependency. - Extend
AbstractAiManagerand implement the abstractperformInvoke(),performConverse(),performConverseStream()methods. - Extend
AbstractCredentialManagerfor your credential rotation logic. - Use
HasRetryLogicin your client classes. - Extend the abstract command classes for consistent CLI UX.
See ubxty/bedrock-ai and ubxty/azure-ai for reference implementations.
See CHANGELOG.md.
MIT — see LICENSE.