Edit asset
Code Mode: praxis.media.assets.edit
HTTP: POST /media/v1/libraries/{library_id}/assets/{asset_id}/edits
Change an existing asset and store the result as a new asset; the source is never overwritten. {library_id} also accepts default, the organization’s default library. The body is operation (its type selects the edit and carries that edit’s own fields) plus optional model, asset_folder, understanding and idempotency_key. Edits by material: on an image, variations (near copies of a take you like), inpaint (mask, a PNG File id beginning with file-, whose transparent area is replaced by what prompt describes), erase, replace_object, recolor, replace_background, remove_background, upscale and talking_avatar (the portrait speaks a recording of the same library); on a video, upscale, reframe, redact, trim, mute, crop, extract_audio (pulls the sound out of a video as its own audio asset), erase (removes burned-in subtitles, captions and corner watermarks, found automatically or inside the boxes given), replace_person (puts the person of an image of the same library in place of the video’s person), lip_sync (re-syncs the lips to a recording of the same library), animate_person (an image of the same library performs the video’s motion), edit_video (the video changed by a one-line instruction, optionally guided by one image of the same library) and remove_background; on a recording or a video’s audio, enhance_voice; and to_video, frame and resynthesize on the material each takes. Any other type answers OPERATION_NOT_SUPPORTED, and an edit that does not fit the source’s material answers REFERENCE_TYPE_MISMATCH. Video and audio edits take their model from the platform catalogue (override with operation.model; extract_audio takes no model, it has exactly one function); an edit whose catalogue is empty answers OPERATION_NOT_SUPPORTED, 尚未上架. remove_background on a video makes a portrait matte: output mask is a small black-and-white video to use as a Cut track mask (the choice for compositing), output alpha (the default) a transparent ProRes 4444 file of about 870 MB per 15 s of 1080p, for when the transparent file itself is the deliverable; pick model from types.matting.models of the generation capabilities. output and model on an image source answer INVALID_PARAMS. The new asset records the source in derived_from; assets.lineage reads the whole edit chain. Charges are at the model API prices (video and audio edits per second of input) and appear in the Job’s usage; repeating the same edit of the same source answers the asset already made instead of paying again. The response is 202 with a queued Job whose source_asset_id is the edited asset; poll GET /media/v1/libraries/{library_id}/jobs/{job_id}, give the output’s viewer_url to the person and tell them usage.
签名
praxis.media.assets.edit(args:{path:{library_id:string;asset_id:string};headers?:{"Idempotency-Key"?:string};body:{/** The edit to apply; type selects the operation and its fields. */ operation:{/** Edit operation discriminator; variations selects the variations branch of this union. */ type:"variations";/** Number of variations to produce; omit it to use the model default. */ n?:number;/** How far the variation may move from the source: subtle or strong. */ strength?:"subtle"|"strong";/** Seed for reproducible variations. */ seed?:number}|{/** Edit operation discriminator; upscale selects the upscale branch of this union. */ type:"upscale";/** Target height in pixels: 720, 1080, 1440 or 2160; omit it to use 1080. */ height?:720|1080|1440|2160;/** Processing model that performs the upscale, from the models the generation capabilities publish for this operation; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; outpaint selects the outpaint branch of this union. */ type:"outpaint";/** Target aspect ratio to extend towards. */ aspect_ratio?:string;/** Pixels to extend on the left edge. */ left?:number;/** Pixels to extend on the right edge. */ right?:number;/** Pixels to extend above. */ up?:number;/** Pixels to extend below. */ down?:number;/** Content that should appear in the extended area. */ prompt?:string}|{/** Edit operation discriminator; inpaint selects the inpaint branch of this union. */ type:"inpaint";/** PNG file identifier (file-…) whose transparent area marks the region to replace. */ mask:string;/** Content that should replace the masked region. */ prompt:string;/** Pixels to grow the mask by before applying the edit. */ grow_mask?:number;/** Swap the meaning of the mask so the opaque area is the edit region. */ invert?:boolean}|{/** Edit operation discriminator; erase selects the erase branch of this union. */ type:"erase";/** Image only: PNG file identifier (file-…) whose transparent area marks the object to remove. */ mask?:string;/** Image only: name of the object to remove, used when no mask is supplied. */ target_prompt?:string;/** Video only: auto (the default) erases the text the function detects and tracks frame by frame; boxes erases the rectangles in boxes. */ region?:"auto"|"boxes";/** Video only, with region boxes: 1 to 50 rectangles {x, y, w, h, start_seconds?, end_seconds?}; x, y, w and h are fractions (0–1) of the frame, and a box without */ boxes?:Array<{/** Left edge of the rectangle as a fraction (0–1) of the frame width. */ x:number;/** Top edge of the rectangle as a fraction (0–1) of the frame height. */ y:number;/** Width of the rectangle as a fraction (0–1) of the frame width; x + w stays at most 1. */ w:number;/** Height of the rectangle as a fraction (0–1) of the frame height; y + h stays at most 1. */ h:number;/** Seconds into the video where this rectangle starts to be erased; omitted means from the start. */ start_seconds?:number;/** Seconds into the video where this rectangle stops being erased, after start_seconds; omitted means to the end. */ end_seconds?:number}>;/** Video only: true drops the audio; by default the source’s audio is kept. */ mute?:boolean;/** Video only: processing model that performs the erase, from the models the generation capabilities publish for this operation; omit it to use the first available */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; replace_object selects the replace_object branch of this union. */ type:"replace_object";/** Name of the object to replace. */ target_prompt:string;/** Content that should replace it. */ prompt:string}|{/** Edit operation discriminator; recolor selects the recolor branch of this union. */ type:"recolor";/** Name of the object to recolour. */ target_prompt:string;/** Colour or description the object should take. */ prompt:string}|{/** Edit operation discriminator; remove_background selects the remove_background branch of this union. */ type:"remove_background";/** Shape the video matte takes: alpha is the person cut out on a transparent background (the default, and the one output the current matting line produces); mask i */ output?:"mask"|"alpha";/** Video model that performs the matting, from the types.matting.models list of the generation capabilities; omit it to use the first available matting model. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; replace_background selects the replace_background branch of this union. */ type:"replace_background";/** Background that should appear behind the subject. */ prompt:string;/** Existing assets the model may use for the new background, 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}>}|({/** Edit operation discriminator; to_video selects the to_video branch of this union. */ type:"to_video"})&({/** Text prompt describing the motion the video should show. */ prompt?:string;/** What the video must not contain. */ negative_prompt?:string;/** Name the produced video carries in the library; omit it and the video is named from the picture it was made from. */ display_name?:string;/** Asset used as the final frame of the generated video. */ last_frame?:string;source?:string;/** 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}>;/** Requested video length in seconds, validated against the model’s supported durations. */ duration_seconds?:number;/** Requested output resolution: 480p, 720p, 1080p or 4k. */ resolution?:"480p"|"720p"|"1080p"|"4k";/** Requested output aspect ratio, validated against model support. */ aspect_ratio?:string;/** True to generate an audio track with the video. */ generate_audio?:boolean;/** Container of the produced video: mp4 or gif. */ output?:"mp4"|"gif";/** Videos to generate in one job. */ n?:number;/** Seed for reproducible sampling; omit it to let the model choose one. */ seed?:number})|{/** Edit operation discriminator; extend selects the extend branch of this union. */ type:"extend";/** Seconds to lengthen the video by. */ duration_seconds:number;/** Content that should appear in the extension. */ prompt?:string}|{/** Edit operation discriminator; edit selects the edit branch of this union. */ type:"edit";/** Change to apply to the video. */ prompt:string}|{/** Edit operation discriminator; lip_sync selects the lip_sync branch of this union. */ type:"lip_sync";/** Audio or voice asset in the same library whose speech the lips should follow. */ audio_asset_id?:string;/** Not carried out yet: synthesize the recording first with POST /media/v1/libraries/{library_id}/speech and name it in audio_asset_id. */ speech?:{/** Text to synthesize; long text is synthesized paragraph by paragraph. */ input:string;/** Name the recording carries in the library. */ display_name?:string;/** Voice to synthesize with. */ voice?:string;/** Emotion and style guidance for the synthesized speech. */ instructions?:string;/** Speaking-rate multiplier; 1 is the model default. */ speed?:number;/** Audio encoding of the synthesized speech. e.g. "mp3" */ response_format?:"mp3"|"wav"|"opus"|"aac"|"flac"|"pcm";/** Language of the text, when the voice supports several. */ language?:string;/** Speech model that synthesises the recording; omit it to use the library’s speech model (models.speech). */ model?:string;/** Performance tier to run this request in, an alternative to naming a model: economy is the cheapest and fastest, balanced the best value, quality puts the result */ tier?:"economy"|"balanced"|"quality"};/** Lip-sync model, from the models the generation capabilities publish for the lip_sync capability; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; frame selects the frame branch of this union. */ type:"frame";/** Time in the video, in seconds, to take the frame from. */ at_seconds:number}|{/** Edit operation discriminator; to_gif selects the to_gif branch of this union. */ type:"to_gif"}|{/** Edit operation discriminator; enhance_voice selects the enhance_voice branch of this union. */ type:"enhance_voice";/** Processing model that performs the enhancement, from the models the generation capabilities publish for this operation; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; reframe selects the reframe branch of this union. */ type:"reframe";/** Target aspect ratio: 9:16, 1:1 or 16:9. */ aspect:"9:16"|"1:1"|"16:9";/** Processing model that performs the re-framing, from the models the generation capabilities publish for this operation; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; redact selects the redact branch of this union. */ type:"redact";/** What to cover: face, qr or text, one or more, in the order given; an empty, unknown or repeated target is refused with INVALID_PARAMS. */ targets:Array<"face"|"qr"|"text">;/** Processing model that performs the redaction, from the models the generation capabilities publish for this operation; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; trim selects the trim branch of this union. */ type:"trim";/** Seconds into the source where the clip starts, 0 or more. */ start_seconds:number;/** Seconds into the source where the clip ends, after start_seconds; omit it to keep to the source’s end. */ end_seconds?:number;/** Processing model that performs the edit, from the models the generation capabilities publish for the clip capability; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; mute selects the mute branch of this union. */ type:"mute";/** Processing model that performs the edit, from the models the generation capabilities publish for the clip capability; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; crop selects the crop branch of this union. */ type:"crop";/** Fraction (0–0.95) of the source’s height at the top to remove; 0 or omitted keeps that side. */ top?:number;/** Fraction (0–0.95) of the source’s width at the right to remove; 0 or omitted keeps that side. */ right?:number;/** Fraction (0–0.95) of the source’s height at the bottom to remove; 0 or omitted keeps that side. */ bottom?:number;/** Fraction (0–0.95) of the source’s width at the left to remove; 0 or omitted keeps that side. */ left?:number;/** Processing model that performs the edit, from the models the generation capabilities publish for the clip capability; omit it to use the first available. */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; extract_audio selects the extract_audio branch of this union. */ type:"extract_audio";/** Seconds into the source video where the audio starts, 0 or more; omit it to begin at the start. */ start_seconds?:number;/** Seconds into the source video where the audio ends, after start_seconds; omit it to keep to the source’s end. */ end_seconds?:number}|{/** Edit operation discriminator; replace_person selects the replace_person branch of this union. */ type:"replace_person";/** Image asset in the same library showing the person to put into the video. */ person_asset_id:string;/** Processing model that performs the replacement, which is also the tier: video-replace-person-flash (faster and cheaper) or video-replace-person-pro (smoother de */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; animate_person selects the animate_person branch of this union. */ type:"animate_person";/** Image asset in the same library showing the person or character to animate. */ person_asset_id:string;/** Which tier: video-animate-person-flash or video-animate-person-pro, as the generation capabilities publish them for animate_person with their prices; omit it to */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; talking_avatar selects the talking_avatar branch of this union. */ type:"talking_avatar";/** Audio or voice asset in the same library with the speech or song, at most 20 seconds. */ audio_asset_id:string;/** Which tier: video-talking-avatar-flash (480P) or video-talking-avatar-pro (720P), as the generation capabilities publish them for talking_avatar with their pric */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; edit_video selects the edit_video branch of this union. */ type:"edit_video";/** One instruction describing the change to make, up to 5000 characters; the video keeps its own length and aspect ratio. */ prompt:string;/** What the edit should avoid, up to 500 characters. */ negative_prompt?:string;/** Optional image asset in the same library to guide the edit. */ reference_asset_id?:string;/** Which tier: the Flash model (720P) or the Pro model (1080P), as the generation capabilities publish them for the video_edit capability with their prices; omit i */ model?:string;tier?:"economy"|"balanced"|"quality"}|{/** Edit operation discriminator; voice_change selects the voice_change branch of this union. */ type:"voice_change";/** Voice identifier to switch to. */ voice:string}|{/** Edit operation discriminator; resynthesize selects the resynthesize branch of this union. */ type:"resynthesize";/** Voice identifier to synthesize with. */ voice:string};/** Model that performs the edit; 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; defaults to the source asset’s folder. */ 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 editing and charging again; reusing it with different content is rejected. e.g. "variations-kite-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}}>;参数
| 名称 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
| library_id | path | string | 是 | Library ID returned by creation. |
| asset_id | path | string | 是 | 32-character asset ID. |
| Idempotency-Key | header | string | 否 | 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. |
请求体
| 必填 | 内容类型 | 说明 |
|---|---|---|
| 是 | application/json |
响应
| 状态码 | 内容类型 | 说明 |
|---|---|---|
| 202 | application/json | The edit job is queued. Poll GET /media/v1/libraries/{library_id}/jobs/{job_id} until its status is completed or failed; the produced asset is a new asset in the source asset’s edit chain, and the source is unchanged. |
| 400 | application/json | OPERATION_NOT_SUPPORTED: the requested operation type is not performed on this asset type in this release — image edits support variations, inpaint, erase, replace_object, recolor and replace_background, video and image remove_background are supported, and upscale, enhance_voice, reframe, redact, trim, mute and crop run through Media’s processing lane (upscale on a picture or a video, enhance_voice on a recording or a video’s audio, reframe, redact, trim, mute and crop on a video), as do erase, replace_person, lip_sync, animate_person and edit_video on a video and talking_avatar on an image. An operation whose model list is empty — matting included — is refused with the model field named. REFERENCE_TYPE_MISMATCH: the source asset or a referenced asset has a material type the chosen model cannot edit, or the edit’s mask is not a PNG file identifier; INVALID_PARAMS: the operation is missing a field it requires, names an enum value outside the accepted set, is given an output or model on an image source, or names a matting model the capabilities do not offer. Select a supported operation and correct the reported field. |
| 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. |