TheDocumentation 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.
Generate class is a static facade that acts as the single entry point for all AI generation tasks in the PHP AI SDK. It holds a shared Sdk instance (or builds one lazily), and returns fluent PendingTextRequest or PendingImageRequest builders that let you configure every aspect of a request before dispatching it.
Generate static methods
text()
Start a text generation request. If $prompt is provided, it is immediately added as a user message.
An optional prompt string. When provided, it is appended as a user message on the returned
PendingTextRequest.image()
Start an image generation request. If $prompt is provided, it is immediately set on the returned builder.
An optional prompt string. When provided, it is pre-set on the returned
PendingImageRequest.model()
Set the default model used by subsequent text() and image() calls when no model is specified on the request itself.
A model instance implementing the
Model contract. Must also implement TextModelInterface or ImageModelInterface to be useful as a default.configure()
Provide a fully constructed Sdk instance to the facade. All subsequent requests will use this SDK for model resolution and container access.
A configured
Sdk value object that carries the default model and optional container.sdk()
Return the current Sdk instance. If one has not been configured explicitly, a default instance is constructed lazily.
The active
Sdk instance used for model resolution.reset()
Clear the stored Sdk instance and the internal runtime factory. Primarily useful in tests to reset state between runs.
PendingTextRequest
PendingTextRequest is a fluent builder returned by Generate::text(). It composes four traits — ConfiguresGeneration, HasMessages, HasTools, and HasProviderOptions — in addition to its own methods.
model()
Override the model for this request only.
A model instance that implements
TextModelInterface.instructions()
Set a system-level instruction string that is sent as the system prompt.
The system prompt / instructions for the model.
prompt()
Append a user message to the conversation.
The user prompt text. Each call appends an additional user
Message.messages()
Replace the full message history with an explicit array of Message objects.
An array of
Message instances. Replaces any previously set messages.tool()
Register a single tool for this request. Accepts a Tool instance, a class name string, or an invokable object.
A single tool. Can be a
Tool instance, a fully-qualified class name, or an invokable object resolved via ToolResolver.tools()
Register multiple tools at once. Accepts variadic arguments or a single array.
One or more tools, or a single array of tools. Each tool must have a unique name.
toolChoice()
Control how the model selects tools for this request.
A
ToolChoice instance or one of the string constants 'auto', 'none', 'required', or a specific tool name.output()
Request structured output. The model will be instructed to return a JSON object matching the given schema.
An
Output instance or a Schema. A bare Schema is automatically wrapped in Output::schema().maxTokens()
Limit the number of tokens in the model’s response.
Maximum token count for the completion. Defaults to
1024 if not set.temperature()
Control the randomness of the model’s output.
Sampling temperature. Defaults to
1.0. Lower values produce more deterministic output.topP()
Nucleus sampling parameter. Only tokens comprising the top $topP probability mass are considered.
Nucleus sampling threshold, between
0.0 and 1.0.maxSteps()
Allow multi-step agentic loops. Each step may produce tool calls; the loop continues until no tool calls remain or the step limit is reached.
Maximum number of generation steps. Minimum effective value is
1.reasoning()
Enable extended reasoning / chain-of-thought for models that support it.
A
Reasoning instance or an effort-level string such as 'low', 'medium', or 'high'.providerOptions()
Pass provider-specific options that are forwarded verbatim to the underlying model driver.
The provider key, e.g.
'openai' or 'anthropic'.An associative array of provider-specific key-value pairs. Merged recursively with any previously set options for this provider.
providerOption()
Set a single provider-specific key-value option.
The provider key, e.g.
'openai' or 'anthropic'.The option key to set for the given provider.
The option value. Stored under
$provider[$key] and merged with any previously set options.run()
Execute the request synchronously and return a TextResult.
The completed generation result, including
text, output, toolCalls, toolResults, finishReason, usage, reasoning, rawResponse, and providerMetadata.stream()
Execute the request and return a Stream for incremental consumption.
A
Stream object that yields text chunks as they arrive from the model. Requires the resolved model to support Capability::Streaming.PendingImageRequest
PendingImageRequest is the fluent builder returned by Generate::image(). All methods return self for chaining.
model()
Override the image model for this request.
An image model instance implementing
ImageModelInterface.prompt()
Set the generation prompt.
The textual description of the image to generate. Required before calling
run().count()
Request multiple images in a single call.
Number of images to generate. Must be at least
1. Defaults to 1.size()
Specify the pixel dimensions of the generated image.
Image dimensions in
{width}x{height} format, e.g. '1024x1024' or '1792x1024'.aspectRatio()
Specify an aspect ratio instead of exact pixel dimensions.
Aspect ratio in
{width}:{height} format, e.g. '16:9' or '1:1'.seed()
Set a reproducibility seed so the same prompt produces consistent results.
An integer seed value. Provider support varies.
providerOptions() (image)
Pass provider-specific options to the image model driver.
The provider key, e.g.
'openai'.An associative array of provider-specific key-value pairs.
run() (image)
Execute the image request and return an ImageResult.
Contains
output (the first ImageData), images (all generated images), usage, rawResponse, and providerMetadata.