Generate images from a text prompt through the attested TEE gateway. This endpoint returns a
buffered JSON response with inline base64 image data and an x-receipt-id header for verification.
POST https://api.redpill.ai/v1/images/generations
Request body
string
required
Image model id from GET /v1/models, for example black-forest-labs/flux.2-klein-4b.
string
required
Text describing the image. Maximum 32,000 Unicode characters.
integer
Request up to n images, from 1 through 10 (default 1). Providers may return fewer images;
image charges use the returned count. Non-integers, null, and integers outside this range return
400 with type: invalid_request_error, code: invalid_parameter, and param: n.
string
Image dimensions, for example 512x512, or auto if the model supports it.
string
Model-specific quality setting.
string
Model-specific background setting.
string
Image encoding option, for example png. For black-forest-labs/flux.2-klein-4b, the NEAR
provider does not honor this option; returned bytes may be JPEG. Inspect the decoded bytes
before choosing a file extension.
integer
Compression setting from 0 through 100, if supported by the model and output format.
string
Model-specific moderation setting.
string
Omit this field or set it to b64_json. The gateway always requests inline base64 output.
url is not supported.
string
Accepted for SDK compatibility but removed before forwarding upstream.
object
The same routing constraints as Chat completions,
including zdr, aci_verified, and aci_session_ids.
The gateway checks the types of the string options; supported values and defaults depend on the
model and are validated upstream. user and style are accepted as strings but removed before
forwarding. Other fields, including seed, return 400 unknown_parameter. Omit stream and
partial_images entirely, including stream: false: streaming is not supported. ACI E2EE is not
supported on this endpoint.
Example
Both examples save the first image as image.bin without assuming an encoding. The cURL example
also saves response headers to image-headers.txt, including the receipt id.
curl --fail-with-body --silent --show-error \ https://api.redpill.ai/v1/images/generations \ -H "Authorization: Bearer $REDPILL_AI_API_KEY" \ -H "Content-Type: application/json" \ -D image-headers.txt -o image-response.json \ -d '{ "model": "black-forest-labs/flux.2-klein-4b", "prompt": "A blue circle on a white background." }' && \python3 - <<'PY'import base64import jsonfrom pathlib import Pathresponse = json.loads(Path("image-response.json").read_text())image = base64.b64decode(response["data"][0]["b64_json"], validate=True)Path("image.bin").write_bytes(image)PY
import base64import osfrom pathlib import Pathfrom openai import OpenAIclient = OpenAI( api_key=os.environ["REDPILL_AI_API_KEY"], base_url="https://api.redpill.ai/v1",)response = client.images.generate( model="black-forest-labs/flux.2-klein-4b", prompt="A blue circle on a white background.",)if not response.data or not response.data[0].b64_json: raise ValueError("The response did not contain an inline image")image = base64.b64decode(response.data[0].b64_json, validate=True)Path("image.bin").write_bytes(image)
Response
The image data below is shortened and the cost is illustrative, not a model price.
created is a Unix timestamp in seconds, supplied by the upstream or filled in by the gateway.
data is a non-empty array of images. Each item contains b64_json and may contain
revised_prompt as a string or null. Image URLs are never returned. Optional top-level fields
are size, quality, output_format, and background; current
black-forest-labs/flux.2-klein-4b responses omit size and output_format.When present, usage always includes integer input_tokens, output_tokens, total_tokens, and
input_tokens_details.text_tokens and .image_tokens. Missing token counts are filled with 0,
including when the provider reports no token usage. output_tokens_details may also be present.
When pricing is available, the gateway adds usage.cost in USD: the returned image count times the
applicable per-image price, plus token charges when token usage and rates are available. Zero token
counts do not imply free image generation.Read x-receipt-id from the response headers and fetch
GET /v1/aci/receipts/{id} using the same bearer token as the generation request. Image receipts
have chat_id: null, so use the receipt id rather than a chat id. See
Get receipt for the response format and
Verify a response for verification.
Errors
Errors use a JSON error object. Parameter validation errors have error.type: invalid_request_error
and include error.code and error.param where applicable.
Status
Error field
Condition
400
code: unknown_parameter
Unrecognized field, such as seed; param names the field.
400
code: invalid_parameter, param: n
n is a non-integer, null, or an integer outside 1 through 10.
400
code: invalid_parameter
response_format: "url", any stream or partial_images field, missing required strings, invalid types for other parameters, prompt over 32,000 characters, or output_compression outside 0–100.
400
type: invalid_request_error, code: null
Invalid JSON or a malformed provider constraint.
400
type: e2ee_unsupported_endpoint
E2EE headers are present; refusal is decided before parsing or admission, and the gateway may then drain the remaining upload within bounded limits.
404
type: model_not_found
No eligible route supports image generation for the requested model.
429
type: rate_limit_error, code: rate_limit_exceeded
Image generation capacity is full, or a rate limit is reached. Capacity requests are rejected without queueing; respect Retry-After when present.
502
type: upstream_error
Upstream failure, buffered response over 64 MiB, or malformed success response, including empty data, more images than requested, or an item without a string b64_json.
Authentication, budget, and routing constraint errors follow the shared
error handling reference.
Related
Models
Find available model ids and capabilities.
Get receipt
Retrieve the signed receipt using x-receipt-id.
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"RedPill AI","colors":{"primary":"#c96442","light":"#d97757","dark":"#b0512f"},"logo":{"light":"https://mintcdn.com/phala-47f19b07/5vRaVvmX8pi5Nukr/logo/light.svg?fit=max\u0026auto=format\u0026n=5vRaVvmX8pi5Nukr\u0026q=85\u0026s=03f8dbe12d0f593a956cccba7b18115f","dark":"https://mintcdn.com/phala-47f19b07/5vRaVvmX8pi5Nukr/logo/dark.svg?fit=max\u0026auto=format\u0026n=5vRaVvmX8pi5Nukr\u0026q=85\u0026s=dd49c6b52615b7312317e2fc353ac289"},"favicon":"https://mintcdn.com/phala-47f19b07/jUpTfTWRxXYc1F5K/favicon.svg?fit=max\u0026auto=format\u0026n=jUpTfTWRxXYc1F5K\u0026q=85\u0026s=1ac7304fa03ccc515bee40d9694e75e2","api":{"mdx":{"auth":{"method":"bearer"},"server":"https://api.redpill.ai/v1"}},"navbar":{"links":[{"href":"https://www.redpill.ai/dashboard","label":"Dashboard"}],"primary":{"type":"button","label":"Start building","href":"https://redpill.ai/start-building"}},"footer":{"socials":{"twitter":"https://twitter.com/redpill_ai","github":"https://github.com/redpill-ai","discord":"https://discord.gg/P2ukR4Z5ps"}},"fonts":{"heading":{"family":"Poppins","weight":600},"body":{"family":"Inter","weight":400}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"metadata":{"timestamp":false},"styling":{"latex":false},"navigation":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/P2ukR4Z5ps"},{"anchor":"GitHub","icon":"github","href":"https://github.com/redpill-ai"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"phala-47f19b07","hasAudioNarration":false,"actualSubdomain":"phala-47f19b07","customDomains":["docs.redpill.ai"],"gitSource":{"type":"github","owner":"redpill-ai","repo":"redpill-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true,"agentFeedback":true},"entitlements":{},"buildId":"6afff3edceccfd47eed42282","clientVersion":"0.0.4227","searchFilterCounts":[{"language":"default","tag":"Documentation","count":49},{"language":"default","tag":"API Reference","count":13},{"language":"default","tag":"Endpoints","count":10},{"language":"default","tag":"Use in agents","count":9},{"language":"default","tag":"Build with the API","count":8},{"language":"default","tag":"Get started","count":7},{"language":"default","tag":"Features","count":7},{"language":"default","tag":"How it works","count":6},{"language":"default","tag":"Verify and control","count":6},{"language":"default","tag":"Providers and trust","count":4}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"treatment","enabled":true,"payload":{"type":"string","value":"treatment"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[{"filePath":"styles.css","content":"h1,h2,h3,h4,h5,h6{font-family:\"Poppins\", sans-serif}"}]}
{"page":{"pagePath":"api-reference/images","slug":"/api-reference/images","pageMetadata":{"title":"Image generation","description":"Generate images and decode inline base64 output.","api":"POST /images/generations","href":"/api-reference/images"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Generate images and decode inline base64 output.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{Card,CardGroup,CodeBlock,CodeGroup,Heading,ParamField,Table}=_components;if(!Card)_missingMdxReference(`Card`,true);if(!CardGroup)_missingMdxReference(`CardGroup`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!ParamField)_missingMdxReference(`ParamField`,true);if(!Table)_missingMdxReference(`Table`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Generate images from a text prompt through the attested TEE gateway. This endpoint returns a\nbuffered JSON response with inline base64 image data and an `,_jsx(_components.code,{children:`x-receipt-id`}),` header for verification.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`POST`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://api.redpill.ai/v1/images/generations`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`request-body`,children:`Request body`}),`\n`,_jsx(ParamField,{body:`model`,type:`string`,required:true,id:`param-model`,children:_jsxs(_components.p,{children:[`Image model id from `,_jsx(_components.code,{children:`GET /v1/models`}),`, for example `,_jsx(_components.code,{children:`black-forest-labs/flux.2-klein-4b`}),`.`]})}),`\n`,_jsx(ParamField,{body:`prompt`,type:`string`,required:true,id:`param-prompt`,children:_jsx(_components.p,{children:`Text describing the image. Maximum 32,000 Unicode characters.`})}),`\n`,_jsx(ParamField,{body:`n`,type:`integer`,id:`param-n`,children:_jsxs(_components.p,{children:[`Request up to `,_jsx(_components.code,{children:`n`}),` images, from `,_jsx(_components.code,{children:`1`}),` through `,_jsx(_components.code,{children:`10`}),` (default `,_jsx(_components.code,{children:`1`}),`). Providers may return fewer images;\nimage charges use the returned count. Non-integers, `,_jsx(_components.code,{children:`null`}),`, and integers outside this range return\n`,_jsx(_components.code,{children:`400`}),` with `,_jsx(_components.code,{children:`type: invalid_request_error`}),`, `,_jsx(_components.code,{children:`code: invalid_parameter`}),`, and `,_jsx(_components.code,{children:`param: n`}),`.`]})}),`\n`,_jsx(ParamField,{body:`size`,type:`string`,id:`param-size`,children:_jsxs(_components.p,{children:[`Image dimensions, for example `,_jsx(_components.code,{children:`512x512`}),`, or `,_jsx(_components.code,{children:`auto`}),` if the model supports it.`]})}),`\n`,_jsx(ParamField,{body:`quality`,type:`string`,id:`param-quality`,children:_jsx(_components.p,{children:`Model-specific quality setting.`})}),`\n`,_jsx(ParamField,{body:`background`,type:`string`,id:`param-background`,children:_jsx(_components.p,{children:`Model-specific background setting.`})}),`\n`,_jsx(ParamField,{body:`output_format`,type:`string`,id:`param-output-format`,children:_jsxs(_components.p,{children:[`Image encoding option, for example `,_jsx(_components.code,{children:`png`}),`. For `,_jsx(_components.code,{children:`black-forest-labs/flux.2-klein-4b`}),`, the NEAR\nprovider does not honor this option; returned bytes may be JPEG. Inspect the decoded bytes\nbefore choosing a file extension.`]})}),`\n`,_jsx(ParamField,{body:`output_compression`,type:`integer`,id:`param-output-compression`,children:_jsx(_components.p,{children:`Compression setting from 0 through 100, if supported by the model and output format.`})}),`\n`,_jsx(ParamField,{body:`moderation`,type:`string`,id:`param-moderation`,children:_jsx(_components.p,{children:`Model-specific moderation setting.`})}),`\n`,_jsx(ParamField,{body:`response_format`,type:`string`,id:`param-response-format`,children:_jsxs(_components.p,{children:[`Omit this field or set it to `,_jsx(_components.code,{children:`b64_json`}),`. The gateway always requests inline base64 output.\n`,_jsx(_components.code,{children:`url`}),` is not supported.`]})}),`\n`,_jsx(ParamField,{body:`safety_identifier`,type:`string`,id:`param-safety-identifier`,children:_jsx(_components.p,{children:`Accepted for SDK compatibility but removed before forwarding upstream.`})}),`\n`,_jsx(ParamField,{body:`provider`,type:`object`,id:`param-provider`,children:_jsxs(_components.p,{children:[`The same routing constraints as `,_jsx(_components.a,{href:`/api-reference/chat-completions#body-provider`,children:`Chat completions`}),`,\nincluding `,_jsx(_components.code,{children:`zdr`}),`, `,_jsx(_components.code,{children:`aci_verified`}),`, and `,_jsx(_components.code,{children:`aci_session_ids`}),`.`]})}),`\n`,_jsxs(_components.p,{children:[`The gateway checks the types of the string options; supported values and defaults depend on the\nmodel and are validated upstream. `,_jsx(_components.code,{children:`user`}),` and `,_jsx(_components.code,{children:`style`}),` are accepted as strings but removed before\nforwarding. Other fields, including `,_jsx(_components.code,{children:`seed`}),`, return `,_jsx(_components.code,{children:`400 unknown_parameter`}),`. Omit `,_jsx(_components.code,{children:`stream`}),` and\n`,_jsx(_components.code,{children:`partial_images`}),` entirely, including `,_jsx(_components.code,{children:`stream: false`}),`: streaming is not supported. ACI E2EE is not\nsupported on this endpoint.`]}),`\n`,_jsx(Heading,{level:`2`,id:`example`,children:`Example`}),`\n`,_jsxs(_components.p,{children:[`Both examples save the first image as `,_jsx(_components.code,{children:`image.bin`}),` without assuming an encoding. The cURL example\nalso saves response headers to `,_jsx(_components.code,{children:`image-headers.txt`}),`, including the receipt id.`]}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`cURL`,numberOfLines:`18`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --fail-with-body`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --silent`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --show-error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` https://api.redpill.ai/v1/images/generations`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Authorization: Bearer `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$REDPILL_AI_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Content-Type: application/json\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -D`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` image-headers.txt`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -o`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` image-response.json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -d`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` '{`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"model\": \"black-forest-labs/flux.2-klein-4b\",`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"prompt\": \"A blue circle on a white background.\"`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` }'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` \u0026\u0026 `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:`\\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`python3`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` -`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` \u003c\u003c`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`'PY'`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`import base64`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`import json`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`from pathlib import Path`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`response = json.loads(Path(\"image-response.json\").read_text())`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`image = base64.b64decode(response[\"data\"][0][\"b64_json\"], validate=True)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`Path(\"image.bin\").write_bytes(image)`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`PY`})}),`\n`]})})}),_jsx(CodeBlock,{filename:`Python`,numberOfLines:`18`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` base64`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` os`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` pathlib `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Path`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` openai `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`client `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` OpenAI(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` api_key`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`os.environ[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"REDPILL_AI_API_KEY\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`],`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` base_url`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"https://api.redpill.ai/v1\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`response `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` client.images.generate(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` model`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"black-forest-labs/flux.2-klein-4b\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:` prompt`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"A blue circle on a white background.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.data `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`or`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` response.data[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].b64_json:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` raise`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` ValueError`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"The response did not contain an inline image\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`image `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` base64.b64decode(response.data[`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`].b64_json, `}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`validate`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`True`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`Path(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"image.bin\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).write_bytes(image)`})]}),`\n`]})})})]}),`\n`,_jsx(Heading,{level:`2`,id:`response`,children:`Response`}),`\n`,_jsx(_components.p,{children:`The image data below is shortened and the cost is illustrative, not a model price.`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`json`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`json`,children:_jsxs(_components.code,{language:`json`,numberOfLines:`13`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`{`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"created\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`1793059200`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"data\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` { `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"b64_json\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"/9j/...\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` ],`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"usage\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"input_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"output_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"total_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"input_tokens_details\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: { `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"text_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:`\"image_tokens\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` },`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#9CDCFE`},children:` \"cost\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:`0.01`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`created`}),` is a Unix timestamp in seconds, supplied by the upstream or filled in by the gateway.\n`,_jsx(_components.code,{children:`data`}),` is a non-empty array of images. Each item contains `,_jsx(_components.code,{children:`b64_json`}),` and may contain\n`,_jsx(_components.code,{children:`revised_prompt`}),` as a string or `,_jsx(_components.code,{children:`null`}),`. Image URLs are never returned. Optional top-level fields\nare `,_jsx(_components.code,{children:`size`}),`, `,_jsx(_components.code,{children:`quality`}),`, `,_jsx(_components.code,{children:`output_format`}),`, and `,_jsx(_components.code,{children:`background`}),`; current\n`,_jsx(_components.code,{children:`black-forest-labs/flux.2-klein-4b`}),` responses omit `,_jsx(_components.code,{children:`size`}),` and `,_jsx(_components.code,{children:`output_format`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`When present, `,_jsx(_components.code,{children:`usage`}),` always includes integer `,_jsx(_components.code,{children:`input_tokens`}),`, `,_jsx(_components.code,{children:`output_tokens`}),`, `,_jsx(_components.code,{children:`total_tokens`}),`, and\n`,_jsx(_components.code,{children:`input_tokens_details.text_tokens`}),` and `,_jsx(_components.code,{children:`.image_tokens`}),`. Missing token counts are filled with `,_jsx(_components.code,{children:`0`}),`,\nincluding when the provider reports no token usage. `,_jsx(_components.code,{children:`output_tokens_details`}),` may also be present.\nWhen pricing is available, the gateway adds `,_jsx(_components.code,{children:`usage.cost`}),` in USD: the returned image count times the\napplicable per-image price, plus token charges when token usage and rates are available. Zero token\ncounts do not imply free image generation.`]}),`\n`,_jsxs(_components.p,{children:[`Read `,_jsx(_components.code,{children:`x-receipt-id`}),` from the response headers and fetch\n`,_jsx(_components.code,{children:`GET /v1/aci/receipts/{id}`}),` using the same bearer token as the generation request. Image receipts\nhave `,_jsx(_components.code,{children:`chat_id: null`}),`, so use the receipt id rather than a chat id. See\n`,_jsx(_components.a,{href:`/api-reference/receipts`,children:`Get receipt`}),` for the response format and\n`,_jsx(_components.a,{href:`/guides/verify-a-response`,children:`Verify a response`}),` for verification.`]}),`\n`,_jsx(Heading,{level:`2`,id:`errors`,children:`Errors`}),`\n`,_jsxs(_components.p,{children:[`Errors use a JSON `,_jsx(_components.code,{children:`error`}),` object. Parameter validation errors have `,_jsx(_components.code,{children:`error.type: invalid_request_error`}),`\nand include `,_jsx(_components.code,{children:`error.code`}),` and `,_jsx(_components.code,{children:`error.param`}),` where applicable.`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Status`}),_jsx(_components.th,{children:`Error field`}),_jsx(_components.th,{children:`Condition`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`code: unknown_parameter`})}),_jsxs(_components.td,{children:[`Unrecognized field, such as `,_jsx(_components.code,{children:`seed`}),`; `,_jsx(_components.code,{children:`param`}),` names the field.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`code: invalid_parameter`}),`, `,_jsx(_components.code,{children:`param: n`})]}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`n`}),` is a non-integer, `,_jsx(_components.code,{children:`null`}),`, or an integer outside `,_jsx(_components.code,{children:`1`}),` through `,_jsx(_components.code,{children:`10`}),`.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`code: invalid_parameter`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`response_format: \"url\"`}),`, any `,_jsx(_components.code,{children:`stream`}),` or `,_jsx(_components.code,{children:`partial_images`}),` field, missing required strings, invalid types for other parameters, prompt over 32,000 characters, or `,_jsx(_components.code,{children:`output_compression`}),` outside 0–100.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`type: invalid_request_error`}),`, `,_jsx(_components.code,{children:`code: null`})]}),_jsx(_components.td,{children:`Invalid JSON or a malformed provider constraint.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`400`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`type: e2ee_unsupported_endpoint`})}),_jsx(_components.td,{children:`E2EE headers are present; refusal is decided before parsing or admission, and the gateway may then drain the remaining upload within bounded limits.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`404`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`type: model_not_found`})}),_jsx(_components.td,{children:`No eligible route supports image generation for the requested model.`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`429`}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`type: rate_limit_error`}),`, `,_jsx(_components.code,{children:`code: rate_limit_exceeded`})]}),_jsxs(_components.td,{children:[`Image generation capacity is full, or a rate limit is reached. Capacity requests are rejected without queueing; respect `,_jsx(_components.code,{children:`Retry-After`}),` when present.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{\"data-numeric\":`true`,children:`502`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`type: upstream_error`})}),_jsxs(_components.td,{children:[`Upstream failure, buffered response over 64 MiB, or malformed success response, including empty `,_jsx(_components.code,{children:`data`}),`, more images than requested, or an item without a string `,_jsx(_components.code,{children:`b64_json`}),`.`]})]})]})]}),`\n`,_jsxs(_components.p,{children:[`Authentication, budget, and routing constraint errors follow the shared\n`,_jsx(_components.a,{href:`/guides/error-handling`,children:`error handling reference`}),`.`]}),`\n`,_jsx(Heading,{level:`2`,id:`related`,children:`Related`}),`\n`,_jsxs(CardGroup,{cols:2,children:[_jsx(Card,{title:`Models`,icon:`list`,href:`/api-reference/models`,children:_jsx(_components.p,{children:`Find available model ids and capabilities.`})}),_jsx(Card,{title:`Get receipt`,icon:`receipt`,href:`/api-reference/receipts`,children:_jsx(_components.p,{children:`Retrieve the signed receipt using x-receipt-id.`})})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Image generation","description":"Generate images and decode inline base64 output.","api":"POST /images/generations","href":"/api-reference/images"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Request body","slug":"request-body","depth":2,"children":[]},{"title":"Example","slug":"example","depth":2,"children":[]},{"title":"Response","slug":"response","depth":2,"children":[]},{"title":"Errors","slug":"errors","depth":2,"children":[]},{"title":"Related","slug":"related","depth":2,"children":[]}],"codeExamples":{},"endpoint":{"title":"Image generation","path":"/images/generations","servers":[{"url":"https://api.redpill.ai/v1"}],"method":"post","request":{"security":[{"title":"Bearer Auth","parameters":{"header":{"Authorization":{"type":"http","scheme":"bearer","description":"Bearer authentication header of the form `Bearer \u003ctoken>`, where `\u003ctoken>` is your auth token."}},"query":{},"cookie":{}}}],"parameters":{"query":{},"header":{},"cookie":{},"path":{}},"body":{"application/json":{"schemaArray":[{"type":"object","properties":{"model":[{"type":"string","description":"Image model id from `GET /v1/models` , for example `black-forest-labs/flux.2-klein-4b` .","required":true}],"prompt":[{"type":"string","description":"Text describing the image. Maximum 32,000 Unicode characters.","required":true}],"n":[{"type":"integer","description":"Request up to `n` images, from `1` through `10` (default `1` ). Providers may return fewer images; image charges use the returned count. Non-integers, `null` , and integers outside this range return `400` with `type: invalid_request_error` , `code: invalid_parameter` , and `param: n` ."}],"size":[{"type":"string","description":"Image dimensions, for example `512x512` , or `auto` if the model supports it."}],"quality":[{"type":"string","description":"Model-specific quality setting."}],"background":[{"type":"string","description":"Model-specific background setting."}],"output_format":[{"type":"string","description":"Image encoding option, for example `png` . For `black-forest-labs/flux.2-klein-4b` , the NEAR provider does not honor this option; returned bytes may be JPEG. Inspect the decoded bytes before choosing a file extension."}],"output_compression":[{"type":"integer","description":"Compression setting from 0 through 100, if supported by the model and output format."}],"moderation":[{"type":"string","description":"Model-specific moderation setting."}],"response_format":[{"type":"string","description":"Omit this field or set it to `b64_json` . The gateway always requests inline base64 output. `url` is not supported."}],"safety_identifier":[{"type":"string","description":"Accepted for SDK compatibility but removed before forwarding upstream."}],"provider":[{"type":"object","properties":{},"description":"The same routing constraints as Chat completions , including `zdr` , `aci_verified` , and `aci_session_ids` ."}]}}],"examples":{"example":{"value":{"model":"\u003cstring>","prompt":"\u003cstring>","n":123,"size":"\u003cstring>","quality":"\u003cstring>","background":"\u003cstring>","output_format":"\u003cstring>","output_compression":123,"moderation":"\u003cstring>","response_format":"\u003cstring>","safety_identifier":"\u003cstring>","provider":{}}}}}}},"response":{},"deprecated":false}},"jsLinks":[],"subdomain":"phala-47f19b07","siteName":"RedPill AI","title":"Image generation - RedPill AI","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-17T16:16:57.762Z","originalFileLocation":"api-reference/images.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Generate images and decode inline base64 output.\">\u003cmeta data-mint-head name=\"application-name\" content=\"RedPill AI\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Image generation - RedPill AI\">\u003cmeta data-mint-head property=\"og:description\" content=\"Generate images and decode inline base64 output.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"RedPill AI\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.redpill.ai/api-reference/images\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://phala-47f19b07.mintlify.site/_mintlify/api/og/v2?division=Endpoints\u0026amp;title=Image+generation\u0026amp;description=Generate+images+and+decode+inline+base64+output.\u0026amp;theme=96a53a94fb39586c2c87277f\u0026amp;signature=d657656ac2f386ca1b4e0fef711959b72239056d923e75b9608f437e07afe058\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Image generation - RedPill AI\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Generate images and decode inline base64 output.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://phala-47f19b07.mintlify.site/_mintlify/api/og/v2?division=Endpoints\u0026amp;title=Image+generation\u0026amp;description=Generate+images+and+decode+inline+base64+output.\u0026amp;theme=96a53a94fb39586c2c87277f\u0026amp;signature=d657656ac2f386ca1b4e0fef711959b72239056d923e75b9608f437e07afe058\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/phala-47f19b07/Y9aC6lrEn-iBCXi1/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"RedPill AI\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#c96442\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.redpill.ai/api-reference/images\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/images.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.redpill.ai/#organization\",\"name\":\"RedPill AI\",\"url\":\"https://docs.redpill.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/phala-47f19b07/5vRaVvmX8pi5Nukr/logo/light.svg?fit=max\u0026auto=format\u0026n=5vRaVvmX8pi5Nukr\u0026q=85\u0026s=03f8dbe12d0f593a956cccba7b18115f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.redpill.ai#website\",\"name\":\"RedPill AI\",\"url\":\"https://docs.redpill.ai\",\"publisher\":{\"@id\":\"https://docs.redpill.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.redpill.ai/api-reference/images#webpage\",\"url\":\"https://docs.redpill.ai/api-reference/images\",\"name\":\"Image generation\",\"description\":\"Generate images and decode inline base64 output.\",\"dateModified\":\"2026-11-17T16:16:57.762Z\",\"isPartOf\":{\"@id\":\"https://docs.redpill.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.redpill.ai/api-reference/images#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.redpill.ai/api-reference/images#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Endpoints\",\"item\":\"https://docs.redpill.ai/api-reference/overview\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Image generation\",\"item\":\"https://docs.redpill.ai/api-reference/images\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.redpill.ai/api-reference/images#apireference\",\"headline\":\"Image generation\",\"name\":\"Image generation\",\"description\":\"Generate images and decode inline base64 output.\",\"url\":\"https://docs.redpill.ai/api-reference/images\",\"mainEntityOfPage\":{\"@id\":\"https://docs.redpill.ai/api-reference/images#webpage\"},\"dateModified\":\"2026-11-17T16:16:57.762Z\",\"publisher\":{\"@id\":\"https://docs.redpill.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.redpill.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"RedPill AI\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"RedPill AI\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/images.md","siteName":"RedPill AI","nav":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/P2ukR4Z5ps"},{"anchor":"GitHub","icon":"github","href":"https://github.com/redpill-ai"}]},"tabs":[{"tab":"Documentation","pages":[{"title":"Documentation","href":"/get-started/introduction"}]},{"tab":"API Reference","groups":[{"group":"Endpoints","pages":[{"title":"Overview","href":"/api-reference/overview"},{"title":"Chat completions","api":"POST /chat/completions","href":"/api-reference/chat-completions"},{"title":"Responses","api":"POST /responses","href":"/api-reference/responses"},{"title":"Messages","api":"POST /messages","href":"/api-reference/messages"},{"title":"Embeddings","description":"Create text embeddings.","api":"POST /embeddings","href":"/api-reference/embeddings"},{"title":"Image generation","api":"POST /images/generations","href":"/api-reference/images"},{"title":"Audio transcription","description":"Transcribe audio with multipart uploads and duration-based billing.","api":"POST /audio/transcriptions","playground":"simple","href":"/api-reference/audio"},{"title":"System One","api":"POST /systemone","href":"/api-reference/systemone"},{"title":"Models","api":"GET /models","href":"/api-reference/models"},{"title":"Completions (legacy)","api":"POST /completions","href":"/api-reference/completions"}]},{"group":"Verification","pages":[{"title":"Attestation report","api":"GET https://tee.redpill.ai/v1/aci/attestation","href":"/api-reference/attestation"},{"title":"Receipt","api":"GET https://tee.redpill.ai/v1/aci/receipts/{id}","href":"/api-reference/receipts"},{"title":"Session","api":"GET https://tee.redpill.ai/v1/aci/sessions/{session_id}","href":"/api-reference/sessions"}]}]},{"tab":"Changelog","pages":[{"title":"Changelog","href":"/changelog"}]}]},"basePath":"","title":"Image generation - RedPill AI","deploymentId":"dpl_vSEmv961Ncyvz1psVwgUnTXQMSYk","buildId":"dpl_vSEmv961Ncyvz1psVwgUnTXQMSYk","dynamics":["c2aa737661","2b790eda92","b0f84f53ff"],"chunks":["OpenApiReferenceProvider-CrDfRf61.js","snippetPresets-Dv-cOUrx.js","utils-BUTreAgv.js","style-to-object-BY3JEAdk.js","utils-wsznt9RM.js","v4-DIgz8zy6.js","addUniqueKeysToSchema-DEsMlaPy.js","conditional-requirements-CFM0id0Q.js","cloneDeep-DontW4xJ.js","_Uint8Array-pP7X6_RM.js","isObject-FP1Yky1u.js","ApiExamples-CU_aGGP0.js","usePlaygroundInputsStore-7dNmUIbS.js","shallow-fTtruD8x.js","isEqual-BRfNFpSD.js","CodeSnippets-52884wUJ.js","CodeSnippet-eoRjC4Le.js","getApiPlaygroundDisplay-CZyAPlR2.js","Page-Cr9IwkK7.js","DynamicMarkdown-NFqqduU7.js","SectionHeading-DQ-mJoAt.js","icon-DXTBUt6s.js","MethodPill-2v-b3js5.js","getPastedJson-v_8Y1_4v.js","DuplicateIcon-DXIkhZIo.js","createIcon-DRpYuPZs.js","axios-CsQoIw0U.js"]}