Generate image
Code Mode: praxis.media.images.generate
HTTP: POST /media/v1/libraries/{library_id}/images/generations
Generate images into a library from a prompt, optionally guided by existing pictures. {library_id} also accepts default, the organization’s default library. prompt is required; n (1 to 10), size, background, output_format, output, references, seed, model, asset_folder and understanding are optional. Name size, not an aspect ratio. Set output to sticker for a cut-out with a transparent background. references attach pictures of the same library with a role: subject keeps a person, product or scene consistent (several subjects put several characters in one picture), edit_target is the picture to change, style is the look to follow, structure the composition. Only a model whose modes in GET /media/v1/generation/capabilities include image takes references; any other answers INVALID_PARAMS naming the models that do, and a role a model cannot honour answers REFERENCE_TYPE_MISMATCH, both before anything is charged. A reference may be an element id (a character, product, scene or brand from the materials endpoints), which expands into its pictures and appends its description to the prompt. To draw several candidates of one key frame, send n and keep the ones you want; delete the rest. Charges are per image at the model API prices and appear in the Job’s usage; a refused or failed image costs nothing. The response is 202 with a queued Job; poll GET /media/v1/libraries/{library_id}/jobs/{job_id} for each output’s asset and viewer_url, give viewer_url to the person and tell them usage. Send Idempotency-Key, or idempotency_key in the body, to retry without generating and charging twice.
Signature
praxis.media.images.generate(args:{path:{library_id:string};headers?:{"Idempotency-Key"?:string};body:{/** Text prompt describing the image to generate; the image model receives it unchanged. e.g. "A red kite above a calm sea at sunrise" */ prompt:string;/** What the image must not contain. */ negative_prompt?:string;/** Name the produced pictures carry in the library; when n is above 1 the second and later get " 2", " 3" and so on. e.g. "Lighthouse shot 7" */ display_name?:string;/** Images to generate in one job, from 1 to 10; defaults to 1. */ n?:number;/** Requested pixel size written as width x height. e.g. "1024x1024" */ size?:"1024x1024"|"1024x1536"|"1536x1024";/** Background handling; defaults to auto. e.g. "transparent" */ background?:"transparent"|"opaque"|"auto";/** Encoding of the stored image; defaults to png. e.g. "png" */ output_format?:"png"|"jpeg"|"webp";/** How the result is stored: image for a normal picture, or sticker for a cut-out committed with material_type sticker; defaults to image. e.g. "sticker" */ output?:"image"|"sticker";/** Existing assets the model may use, each with the role it plays. */ references?:Array<{asset_id:string;role:"edit_target"|"style"|"structure"|"subject"|"video"|"voice";/** How strongly the reference asset influenced the result, from 0 to 1 on the Stability scale. */ strength?:number;/** Video generation, mode reference only: the voice this picture’s subject speaks with. */ voice_asset_id?:string}>;/** Seed for reproducible sampling; omit it to let the model choose one. */ seed?:number;/** Model with image-generation capability; omit it to use the library default image model. e.g. "gpt-image-2" */ model?:string;tier?:"economy"|"balanced"|"quality";/** Folder the produced asset is filed under; when omitted it is 生成/YYYY-MM-DD, the UTC date the job was created. */ asset_folder?:string;/** Understanding behavior for the produced asset; defaults to auto. e.g. "auto" */ understanding?:"auto"|"skip";/** Stable key so a retried request reuses the same job instead of generating and charging again; reusing it with different content is rejected. e.g. "kite-sunrise-1" */ idempotency_key?:string}}):Promise<{/** Job identifier: job_ followed by 32 lowercase hexadecimal characters. pattern: ^job_[0-9a-f]{32}$ e.g. "job_b562f087623c4756b43813e3dce670ba" */ id:string;/** Identifier of the library the job runs in; the produced assets land here. */ library_id:string;/** Batch operation: tag adds labels, untag removes labels, set_context replaces custom metadata, move changes asset_folder, and delete removes selected assets. */ action:"tag"|"untag"|"set_context"|"move"|"delete"|"reprocess"|"generate";/** Where the job is. */ status:"queued"|"in_progress"|"running"|"completed"|"completed_with_errors"|"failed"|"cancelled"|"canceled";/** Category of media this job produces. */ type?:"image"|"video"|"speech"|"music"|"sound_effect"|"voice";/** The operation this job performs: generate for a plain text-to-image or text-to-video job, or the edit operation an image edit applied to its source asset. */ operation?:"generate"|"clone"|"tag"|"untag"|"set_context"|"move"|"delete"|"reprocess"|"variations"|"upscale"|"outpaint"|"inpaint"|"erase"|"replace_object"|"recolor"|"remove_background"|"replace_background"|"to_video"|"extend"|"edit"|"lip_sync"|"frame"|"to_gif"|"voice_change"|"resynthesize";/** Asset this job edits, present on an image edit job and omitted on generation jobs. */ source_asset_id?:string;/** Fraction of this job already processed, from 0 to 1. */ progress?:number;/** Why a queued generation job has not started yet. */ queue_reason?:"concurrency"|"provider_throttled"|"provider_queue";/** Present while the job waits for a slot (queue_reason concurrency): its place in line among the waiting jobs of its type in this library, 1 for the next to start */ queue_position?:number;/** Generation job: number of outputs requested (images or videos; text segments for speech). */ total:number;/** Number of outputs or items successfully processed; failed ones are counted separately. */ done:number;/** Number of outputs or items that could not be produced or processed. */ failed:number;/** Always present, including an empty array before any item failure or when all items succeed. */ failures:Array<{/** Identifier supplied for the failed item; it may identify a missing asset. */ asset_id?:string;/** Zero-based output index for a failed video-generation item. */ index?:number;/** Domain error code explaining the individual item failure. */ code:"LIBRARY_NOT_FOUND"|"ASSET_NOT_FOUND"|"WORK_NOT_FOUND"|"REVISION_CONFLICT"|"JOB_NOT_FOUND"|"UNDERSTANDING_NOT_FOUND"|"ASSET_VERSION_CHANGED"|"LIBRARY_INVALID_STATE"|"INVALID_PARAMS"|"INVALID_EXPRESSION"|"UNSUPPORTED"|"NOT_IMPLEMENTED"|"FILE_TOO_LARGE"|"FILE_EMPTY"|"FILE_NOT_READY"|"UNSUPPORTED_MEDIA"|"FETCH_FAILED"|"LIMIT_EXCEEDED"|"CHUNK_INVALID"|"RATE_LIMITED"|"CAPACITY"|"UPSTREAM_FAILED"|"CONTENT_REJECTED"|"GENERATION_FAILED"|"BINDING_READ_ONLY"|"OPERATION_NOT_SUPPORTED"|"MODEL_PENDING"|"REFERENCE_TYPE_MISMATCH"|"CONSENT_REQUIRED"|"LIBRARY_IS_DEFAULT"|"JOB_INVALID_STATE"|"VOICE_TRAINING"|"INSUFFICIENT_BALANCE";/** The upstream model service’s finer reason for this failure, such as MODEL_PROTOCOL_LINE_UNAVAILABLE or VOICE_SAMPLE_REJECTED. */ detail_code?:string;/** Request id of the model call that failed, the same id shown in the model request log, so the failure can be traced there. */ model_request_id?:string;/** The model service’s own words for this failure, for a person to read, for example why moderation refused an input. */ message?:string}>;/** Generation intent recorded on the earliest video jobs; newer generation jobs describe themselves with type and operation instead. */ intent?:string;/** Model that produced the outputs of a generation job; omitted for batch jobs. */ model?:string;/** The performance tier that actually served this job’s model, present only when the request named a tier instead of a model. */ tier?:"economy"|"balanced"|"quality";/** Per-output results of a generation job, in index order: one entry per requested image or video, and one per text segment for speech. */ outputs?:Array<{/** Zero-based position of this output in the requested count. */ index:number;/** State of this requested output. */ status:"pending"|"succeeded"|"failed";/** Short-lived signed URL for previewing this output; read the Job again to obtain a fresh URL. */ preview_url?:string;/** Seed for this output, when the model returned one; it may be absent. */ seed?:number|null;/** Present only on a job written before ADR-094 §2, when outputs were candidates with a retention window. */ expires_at?:string;/** Library asset identifier for this output once the library has stored it. */ asset_id?:string;/** Console page that shows this output in the media library, present once asset_id is. */ viewer_url?:string}>;/** What this job has been charged, as US dollars in a decimal string with six decimals, for example 0.042300. */ usage?:{/** US dollars as a decimal string with six decimals, for example 0.042300; never a floating-point number. */ amount:string;/** Currency code for amount; USD. */ currency:string};/** Time the job was created, in UTC. */ created_at:string;/** Time the job reached a terminal status, or null while queued or running. */ finished_at:string|null;/** Automation run (its root run) that started this job. */ pipeline_run_id?:string;/** Generation jobs only: the elements the job’s request expanded, each with the version read when the job was created; absent when none were. */ elements?:Array<{/** Element asset the generation expanded, in the same library as the output. */ asset_id:string;/** Element version read when the job was created. */ version:number;/** Kind of element. */ material_type:"character"|"product"|"scene"|"brand"}>;/** Present on a completed align job: how the two recordings line up, with offset_seconds and confidence. */ result?:{/** How many seconds later the reference asset starts, relative to the source asset the route named; positive means the reference comes later, so a caller holding b */ offset_seconds:number;/** How sure the alignment is, from 0 to 1; a low value means the two recordings share little to correlate. */ confidence:number}}>;Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| library_id | path | string | yes | Library ID returned by creation. |
| Idempotency-Key | header | string | no | Stable key for retrying the same request without creating or charging for another job; reusing it with different request content is rejected. Send it here or as idempotency_key in the body, never both with different values. |
Request body
| Required | Content types | Description |
|---|---|---|
| yes | application/json |
Responses
| Status | Content types | Description |
|---|---|---|
| 202 | application/json | The job is queued. Poll GET /media/v1/libraries/{library_id}/jobs/{job_id} until its status is completed or failed; the produced assets are stored in the library as they finish. |
| 400 | application/json | INVALID_PARAMS: prompt is missing or a size, n or other field is out of range; REFERENCE_TYPE_MISMATCH: the chosen model cannot honour a reference role, or a referenced asset is not an image. Correct the reported field, or choose a supported model or reference role. Note that aspect_ratio is not accepted for images; name size instead. |
| 402 | application/json | INSUFFICIENT_BALANCE: the organization balance cannot cover the estimated cost of this generation or edit; top up and resubmit. Nothing was generated and nothing was charged for this request. |
| 403 | application/json | This credential has read-only access to the library; use a write-capable binding for mutations. |
| 404 | application/json | ASSET_NOT_FOUND: the edited asset is missing, deleted or belongs to another library, or the addressed library was not found; verify the identifiers with libraries and assets. A reference asset that cannot be reached answers the same way, never as a hint that it exists elsewhere. |
| 409 | application/json | MODEL_PENDING or JOB_INVALID_STATE: the chosen model is not ready for this library, or the job cannot start from its current state; wait for the model to become available, or start a new job rather than resuming this one. |
| 413 | application/json | The file exceeds an input limit; provide a smaller source file. |
| 415 | application/json | This media format is unsupported; provide a supported format. |
| 422 | application/json | CONTENT_REJECTED: the provider refused the prompt or the source image under its content policy; change the prompt or the source before retrying. Nothing was generated and nothing was charged. |
| 429 | application/json | RATE_LIMITED: this library already has its maximum number of running jobs of this type and 50 more waiting, or the provider is throttling requests; Retry-After gives the seconds to wait before retrying. Below that a job past the running limit is accepted and waits (queue_reason concurrency) instead of being refused. |
| 501 | application/json | The requested operation is unsupported; choose a supported method. |
| 502 | application/json | Request failed; see the error code reference. |
| 503 | application/json | Historical projections are still being initialized, or library storage is temporarily unavailable; retry shortly and check failureSummary counts_complete. |