Class: ReveAI::ImageResponse
- Defined in:
- lib/reve_ai/response.rb
Overview
Response wrapper for image generation API responses.
Provides convenient accessors for image data, version info, content policy status, and credit usage. All accessors work for both JSON responses (values from the parsed body) and binary responses (values from the X-Reve-* headers).
Instance Attribute Summary
Attributes inherited from Response
Instance Method Summary collapse
-
#base64 ⇒ String?
Alias for #image.
-
#content_violation? ⇒ Boolean
Checks if the generated image violates content policy.
-
#credits_remaining ⇒ Integer?
Returns the number of credits remaining after this request.
-
#credits_used ⇒ Integer?
Returns the number of credits used for this request.
-
#image ⇒ String?
Returns the image data.
-
#layout ⇒ Hash?
Returns the layout object for this generation.
-
#version ⇒ String?
Returns the model version used for generation.
Methods inherited from Response
#binary?, #initialize, #request_id, #success?
Constructor Details
This class inherits a constructor from ReveAI::Response
Instance Method Details
#base64 ⇒ String?
Despite the name, binary responses (Accept: image/*) return raw image bytes here, not base64 data.
Alias for #image.
123 124 125 |
# File 'lib/reve_ai/response.rb', line 123 def base64 image end |
#content_violation? ⇒ Boolean
Checks if the generated image violates content policy.
156 157 158 159 |
# File 'lib/reve_ai/response.rb', line 156 def content_violation? body_value(:content_violation) == true || headers["x-reve-content-violation"] == "true" end |
#credits_remaining ⇒ Integer?
Returns the number of credits remaining after this request.
179 180 181 |
# File 'lib/reve_ai/response.rb', line 179 def credits_remaining body_value(:credits_remaining) || headers["x-reve-credits-remaining"]&.to_i end |
#credits_used ⇒ Integer?
Returns the number of credits used for this request.
167 168 169 |
# File 'lib/reve_ai/response.rb', line 167 def credits_used body_value(:credits_used) || headers["x-reve-credits-used"]&.to_i end |
#image ⇒ String?
Returns the image data.
For JSON responses this is the base64 encoded image; for binary responses (Accept: image/*) it is the raw image bytes in the negotiated format, ready to write to disk without decoding.
111 112 113 |
# File 'lib/reve_ai/response.rb', line 111 def image binary? ? body : body[:image] end |
#layout ⇒ Hash?
Returns the layout object for this generation.
Present on v2 create/render JSON responses; nil on v1 responses and on binary (Accept: image/*) responses.
134 135 136 |
# File 'lib/reve_ai/response.rb', line 134 def layout body_value(:layout) end |
#version ⇒ String?
Returns the model version used for generation.
144 145 146 |
# File 'lib/reve_ai/response.rb', line 144 def version body_value(:version) || headers["x-reve-version"] end |