PHPackages                             ubxty/core-ai - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ubxty/core-ai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ubxty/core-ai
=============

Core AI abstraction layer for Laravel. Provides shared contracts, managers, retry logic, cost tracking, and CLI tools for building AI provider packages.

1.0.0(1mo ago)091MITPHPPHP ^8.2

Since Apr 18Pushed 1mo agoCompare

[ Source](https://github.com/ubxty/ubxty-core-ai)[ Packagist](https://packagist.org/packages/ubxty/core-ai)[ RSS](/packages/ubxty-core-ai/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (1)

ubxty/core-ai
=============

[](#ubxtycore-ai)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b253752bdd1dc6ba7015e79e2af5f9d99765c90d93c2359a1e79a20ed16eb27d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f75627874792f636f72652d61692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ubxty/core-ai)[![License](https://camo.githubusercontent.com/b3b526685568c2e0ecfae333a49aa85402e841e0e788af9077a2dbf32fce9101/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f75627874792f636f72652d61692e7376673f7374796c653d666c61742d737175617265)](LICENSE)

**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`](https://packagist.org/packages/ubxty/bedrock-ai) — AWS Bedrock
- [`ubxty/azure-ai`](https://packagist.org/packages/ubxty/azure-ai) — Azure OpenAI

---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12

---

Installation
------------

[](#installation)

```
composer require ubxty/core-ai
```

The service provider is auto-discovered via Laravel's package discovery.

---

What's Included
---------------

[](#whats-included)

### Contracts

[](#contracts)

- `AiManagerContract` — Interface all AI manager implementations must satisfy (invoke, converse, stream, syncModels, etc.)

### Abstract Manager

[](#abstract-manager)

- `AbstractAiManager` — Base class handling cost limit checks, cost tracking, event dispatching, invocation logging, and retry orchestration. Extend this to build a provider-specific manager.

### Client Helpers

[](#client-helpers)

- `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.

### Conversation

[](#conversation)

- `ConversationBuilder` — Fluent builder for multi-turn conversations with multimodal support (text, images, documents).

### Models

[](#models)

- `ModelSpecResolver` — Resolves context window and max token limits for known model IDs across all major providers.

### Support

[](#support)

- `TokenEstimator` — Estimates token counts and cost for text, image, and document inputs.
- `InvocationLogger` — Structured invocation logging.

### Commands (Abstract)

[](#commands-abstract)

- `AbstractChatCommand` — Base for interactive `artisan chat` commands.
- `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`.

### Events

[](#events)

- `AiInvoked`, `AiKeyRotated`, `AiRateLimited`

### Exceptions

[](#exceptions)

- `AiException`, `ConfigurationException`, `CostLimitExceededException`, `RateLimitException`

### HTTP

[](#http)

- `HealthCheckController` — Base health check endpoint for AI connectivity probes.

---

Extending core-ai
-----------------

[](#extending-core-ai)

To build a new AI provider package:

1. Require `ubxty/core-ai` as a dependency.
2. Extend `AbstractAiManager` and implement the abstract `performInvoke()`, `performConverse()`, `performConverseStream()` methods.
3. Extend `AbstractCredentialManager` for your credential rotation logic.
4. Use `HasRetryLogic` in your client classes.
5. Extend the abstract command classes for consistent CLI UX.

See `ubxty/bedrock-ai` and `ubxty/azure-ai` for reference implementations.

---

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md).

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

52d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2de529037b10593205d6c41aa1d5331ef027e398489b74355b6d222ac10f2f1?d=identicon)[ubxty](/maintainers/ubxty)

---

Top Contributors

[![ravdeepsingh22](https://avatars.githubusercontent.com/u/13014642?v=4)](https://github.com/ravdeepsingh22 "ravdeepsingh22 (1 commits)")

---

Tags

laravelabstractionaicorechatbotllm

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ubxty-core-ai/health.svg)

```
[![Health](https://phpackages.com/badges/ubxty-core-ai/health.svg)](https://phpackages.com/packages/ubxty-core-ai)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[spatie/laravel-export

Create a static site bundle from a Laravel app

670139.5k6](/packages/spatie-laravel-export)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

954.0k](/packages/zidbih-laravel-deadlock)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

19253.0k3](/packages/interaction-design-foundation-laravel-geoip)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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