Skip to content

AI facade

Fomvasss\AiTasks\Facades\AI, alias AI. Resolves Fomvasss\AiTasks\Core\AI.

MethodReturnsDescription
send(AiTask $task, array|string $drivers = [])AiResponseSync call, see Running tasks
stream(AiTask $task, callable $onChunk, array|string $drivers = [])AiResponseSync call with chunks to $onChunk(string $chunk)
queue(AiTask $task, array|string $drivers = [], DateTimeInterface|DateInterval|int|null $delay = null)stringQueue the task, returns the ai_runs id, see Queued tasks
prompt(string $prompt, ?string $system = null, array|string $drivers = [], string $name = 'prompt')AiResponseOne-off call without a task class
models(string $driver, ?string $filter = null)arrayModels from the provider’s API, see below
fake(string|array|null $responses = null)FakeAISwap for a fake, see Testing

$drivers overrides the routing chain: a driver name or a list.

ExceptionWhen
Fomvasss\AiTasks\Exceptions\AiDriverExceptionNo configured driver, every driver failed, the provider rejected the request, or a stream broke off
Fomvasss\AiTasks\Exceptions\BudgetExceededExceptionTenant’s monthly budget exceeded, see Budgets
LogicExceptionqueue() for a task that can’t be rebuilt on the worker
$models = AI::models('openai', filter: 'gpt');
// [['id' => 'gpt-5.6-luna', 'display_name' => null, 'owner' => 'system', 'created' => '2026-06-23', ...], ...]

Credentials are taken from config/ai.php. Throws:

  • AiDriverException — the driver has no API key
  • ModelListingUnavailableException — the provider has no listing endpoint
  • ModelListingException — connection or API error

With credentials at hand, skip the config lookup and use ModelLister directly:

use Fomvasss\AiTasks\Support\ModelLister;
$models = app(ModelLister::class)->forDriver('openai', ['api_key' => $key], filter: 'gpt');

The CLI equivalent is ai:models.