Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openai-compatible/llms.txt
Use this file to discover all available pages before exploring further.
ImageResponseParser is a static utility called by provider adapters after
receiving a raw HTTP response from an OpenAI-compatible /images/generations
endpoint. It normalizes the JSON payload — regardless of minor per-provider
shape differences — into a typed ImageResponse that contains an array of
ImageData objects, a Usage token count, the unmodified raw payload, and
a providerMetadata map keyed by provider name. This normalization layer
means consuming code never has to inspect raw arrays or account for field
name variations between providers.
Namespace
Method
parse()
/images/generations response payload into
a structured ImageResponse.
Parameters
The decoded JSON body returned by the provider. The parser reads the
following top-level keys:
data— array of image objects (each may containb64_json,mime_type,media_type,width,height, andurl).usage— token count object (may use OpenAI-style or Anthropic-style key names; see Usage normalization below).id,created,model,size,quality,output_format— optional metadata keys captured inproviderMetadata.
The canonical provider name, e.g.
"openai" or "openai-compatible". Used
as the key under which provider-specific metadata is stored inside
ImageResponse::$providerMetadata.Return Type
parse() returns an ImageResponse with the following fields.
Array of parsed image objects, one per item in
payload['data']. Items that
are not arrays are silently skipped.Token usage for the generation request, normalized from
payload['usage'].
See Usage normalization for details on how
provider-specific key names are handled.The original
$payload array, stored unmodified. Useful for logging,
debugging, or accessing provider-specific fields that the parser does not
extract into typed properties.A map keyed by
Fields that are absent from the payload, or whose values are not the
expected type, are filtered out with
$providerName. The inner array is built from the following
top-level payload fields and contains only non-null values:| Key | Source | Type |
|---|---|---|
id | payload['id'] | string |
created | payload['created'] | int |
model | payload['model'] | string |
size | payload['size'] | string |
quality | payload['quality'] | string |
output_format | payload['output_format'] | string |
array_filter.Usage Normalization
Different OpenAI-compatible providers use different key names for token counts.ImageResponseParser handles both variants transparently:
Usage property | Primary key | Fallback key | Default when absent |
|---|---|---|---|
inputTokens | input_tokens | prompt_tokens | 0 |
outputTokens | output_tokens | completion_tokens | 0 |
totalTokens | total_tokens | (none) | null |
inputTokens and outputTokens default to 0 rather than null so that
arithmetic on Usage objects is always safe without null-checks. Only
totalTokens can be null, reflecting that some providers omit it entirely.Example
The following example mirrors the'parses an image generation response'
integration test. It shows a complete payload with all commonly populated
fields and demonstrates accessing the parsed result.