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.
Content is an immutable value object that represents a single typed part within a Message. Each message body is an array of Content parts. A part has a type — one of text, image, audio, or file — and a payload whose shape depends on how the source was resolved. The static factory methods inspect the $source argument and automatically determine the correct ContentSource variant, making it straightforward to pass URLs, file paths, base64 strings, or raw binary data.
Constants
| Constant | Value |
|---|---|
Content::TYPE_TEXT | 'text' |
Content::TYPE_IMAGE | 'image' |
Content::TYPE_AUDIO | 'audio' |
Content::TYPE_FILE | 'file' |
Factory methods
text()
Create a plain text content part.
The raw text string. Stored as a
ContentSource::Text part with source = 'text'.image()
Create an image content part. The $source argument is inspected to determine how the image data is provided — see Source resolution logic below.
The image data source. Interpreted as a URL, data URI, base64 string, file path, or raw bytes — see the resolution rules below.
MIME type such as
'image/png' or 'image/jpeg'. Required for base64 sources and for raw string sources that are not readable file paths.Optional filename hint forwarded to the provider. Auto-detected from URLs and file paths when not provided.
Pass
InputEncoding::Base64 to indicate that $source is a base64-encoded string. Requires $mimeType.audio()
Create an audio content part. Source resolution follows the same rules as image().
The audio data source.
MIME type, e.g.
'audio/mpeg' or 'audio/wav'. Required for base64 and raw string sources.Optional filename hint.
InputEncoding::Base64 when $source is a base64 string.file()
Create a file content part for PDFs, documents, or other binary files. Source resolution follows the same rules as image().
The file data source.
MIME type, e.g.
'application/pdf'. Required for base64 and raw string sources.Optional filename hint.
InputEncoding::Base64 when $source is a base64 string.Source resolution logic
Theimage(), audio(), and file() factories all delegate to the same internal resolver. The rules are applied in order:
| Condition | Resulting ContentSource | Notes |
|---|---|---|
$source starts with http:// or https:// and is a valid URL | ContentSource::Url | filename is inferred from the URL path when not provided. |
$source starts with data: | ContentSource::DataUri | The MIME type is parsed from the data URI prefix; $mimeType overrides it. |
$encoding === InputEncoding::Base64 | ContentSource::Base64 | $mimeType is required — throws InvalidArgumentException when absent. |
$source is a readable file path (is_file + is_readable) | ContentSource::Raw | File bytes are read immediately; MIME type is auto-detected via mime_content_type() when not provided. |
Any other string and $mimeType is provided | ContentSource::Raw | Raw string bytes stored directly. |
Any other string without $mimeType | — | Throws InvalidArgumentException. |
Accessor methods
textValue()
Return the text string for TYPE_TEXT parts, or null for all other types.
The text content, or
null if this is not a text part.data()
Return the raw data payload for non-URL parts.
The raw bytes (for
Raw), the base64 string (for Base64), or the full data URI string (for DataUri). null for Url and Text sources.mimeType()
Return the MIME type of the content, if known.
A MIME type string such as
'image/png' or 'audio/mpeg', or null if not set or not applicable.url()
Return the URL for ContentSource::Url parts.
The full HTTP/HTTPS URL string, or
null for non-URL parts.filename()
Return the filename hint associated with this content part.
The filename string, or
null if none was provided or inferred.source()
Return the ContentSource enum case describing how the data is stored in this part.
One of
ContentSource::Text, ContentSource::Url, ContentSource::DataUri, ContentSource::Base64, or ContentSource::Raw.base64Data()
Return a base64-encoded representation of the content data, regardless of the original source type.
- For
ContentSource::Base64: returns the stored base64 string directly. - For
ContentSource::DataUri: extracts the base64 payload from the data URI. - For
ContentSource::Raw: base64-encodes the raw bytes. nullforUrlandTextsources.
dataUri()
Return a complete data: URI string, constructing one from base64 data and MIME type if the source is not already a data URI.
A
data:{mimeType};base64,{data} string, or null if the base64 data or MIME type is unavailable.ContentSource enum
ContentSource is a string-backed enum describing how content data is stored internally.
Used exclusively by
Content::text(). The data is a plain UTF-8 string.The source is an HTTP/HTTPS URL. The provider fetches the resource directly.
The source is a
data:... URI. The full URI is stored in data().The source is a raw base64 string. Requires a MIME type.
The source is raw bytes (read from a file or passed directly as a string with a MIME type).
InputEncoding enum
InputEncoding declares supported binary-to-text encodings for binary content passed as a string.
Indicates that the
$source string passed to image(), audio(), or file() is base64-encoded binary data. A MIME type must be provided alongside it.