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 the heart of the PHP AI SDK ecosystem — a framework-agnostic library that defines a clean set of contracts, a fluent generation API, value objects, and PSR integrations. It deliberately contains no HTTP calls itself: all provider-specific communication lives in separate packages such as aisdk/openai and aisdk/anthropic. This separation means you can swap providers without touching your application code, and it keeps the core dependency footprint small and stable.

Why aisdk/core?

PHP applications deserve the same ergonomic AI tooling available in other ecosystems. aisdk/core gives you a single, consistent interface for text generation, streaming, tool calling, structured output, and image generation — regardless of which AI provider you choose to use underneath. Because it ships PSR-compatible abstractions and relies on php-http/discovery for HTTP client auto-discovery, it works equally well in Laravel, Symfony, or plain PHP scripts without any framework glue.

Key Features

Text Generation

Generate text completions with a fluent Generate::text() API. Pass a prompt, optional system instructions, and call ->run() to get a TextResult.

Streaming

Stream responses token-by-token using ->stream(). Iterate over $stream->chunks() or attach onChunk, onFinish, and onError hooks.

Tool Calling

Define tools with Tool::make() or extend the Tool class. Attach them to any generation request with ->tool($weather) and let the model invoke them automatically.

Structured Output

Describe the shape of the response with Schema::object() and access typed data directly from $result->output. No manual JSON parsing required.

Image Generation

Generate images with Generate::image(), control size, aspect ratio, and count, then save results directly to disk with $result->output->save().

Reasoning

Access model reasoning traces via $result->reasoning when the underlying provider and model support extended thinking.

Requirements

  • PHP 8.3 or higher — the SDK uses readonly properties, enums, and other modern PHP features that require PHP 8.3+.
  • Composer — the recommended way to install both the core package and any provider packages.

Provider Packages

aisdk/core ships no HTTP transport of its own. You must install at least one provider package alongside it:
ProviderRepositoryInstall
OpenAIphpaisdk/openaicomposer require aisdk/openai
Anthropicphpaisdk/anthropiccomposer require aisdk/anthropic
The provider package registers its own HTTP client adapters and model definitions. After installation, all Generate:: calls automatically route through the correct provider based on the model you pass.

Supported Capabilities

Every capability listed below is available today in aisdk/core:
  • Text generation (Generate::text())
  • Streaming text generation (->stream())
  • Image generation (Generate::image())
  • Tool calling (->tool(...))
  • Structured output (->output(...))
  • Provider options passthrough (->providerOptions(...))
  • Custom model registration (::registerModel(...))
  • Normalized provider errors

Build docs developers (and LLMs) love