Unified 4-route asset API
Every /v1/assets* route is workspace-private and served with Cache-Control: no-store. Instead of repeating large files across retries or passing external URLs directly to multiple providers, upload or import media once into private workspace storage and reference the returned assetKey (inputs/<workspaceId>/<uuid>.<ext>) inside generation requests.
| Method & Path | Operation ID | Scope | Purpose |
|---|---|---|---|
POST /v1/assets | assets.create | generate | Unified create/upload endpoint supporting multipart/form-data direct upload, JSON base64, public HTTPS url import, owned job_output reuse, or presigned single-PUT upload preparation |
POST /v1/assets/complete | assets.complete | generate | Verifies uploaded bytes (magic signature, byte length, SHA-256) after a presigned PUT and transitions the asset to state: "ready" |
GET /v1/assets | assets.get | read | Lists workspace assets (?state=, ?mediaTypePrefix=, ?limit=1..100, ?cursor=) or inspects one asset by ?key=<assetKey> (cannot combine ?key= with list filters) |
DELETE /v1/assets | assets.delete | generate | Tombstones and deletes a workspace-owned asset via ?key=<assetKey> query parameter or JSON body { "key": "<assetKey>" } (missing or conflicting keys return 400) |
Exact upload modes and byte limits
Choose the upload path that matches your file size and runtime environment:
| Mode | Transport / Payload | Max Size | Steps | Idempotency-Key |
|---|---|---|---|---|
| REST direct multipart | POST /v1/assets (multipart/form-data, single "file" part) | 4 MiB (4,194,304 bytes) | 1 (returns ready) | Optional |
| REST JSON base64 | POST /v1/assets ({ "source": "base64", "mediaType", "dataBase64" }) | 3 MiB (3,145,728 decoded bytes) | 1 (returns ready) | Optional |
| REST / MCP presigned PUT | POST /v1/assets ({ "mediaType", "size" }) → PUT uploadUrl → POST /v1/assets/complete | 100 MiB (104,857,600 bytes) | 3 (direct to storage) | Not required |
| Public HTTPS URL import | POST /v1/assets ({ "source": "url", "url", "type" }) or MCP upload_asset / upload_attachment | 100 MiB (104,857,600 bytes) | 1 (bounded SSRF-safe GET) | Required |
| Owned output reuse | POST /v1/assets ({ "source": "job_output", "sourceJobId", "outputIndex" }) or MCP upload_asset | Bound by retained output | 1 (server-side copy) | Required |
| MCP inline base64 (last resort) | MCP upload_asset (source: "base64") | 64 KiB (65,536 decoded bytes) | 1 (returns ready) | Required |
Supported media types and container validation
OpenGen validates actual file magic bytes and container structure (not just file extensions or Content-Type headers) across 11 supported MIME types:
- Images:
image/png,image/jpeg,image/webp - Video:
video/mp4,video/webm - Audio:
audio/mpeg,audio/wav,audio/ogg,audio/flac,audio/mp4,audio/webm
Public HTTPS URL import security (source: "url")
URL imports are strictly credential-free, no-redirect HTTPS GET fetches on public IP addresses (DNS is resolved and pinned before TLS connection; local, private, link-local, mapped, and reserved addresses are rejected), with Accept-Encoding: identity, 30-second timeout (408 input_download_timeout), and strict magic-byte verification.
Uploading and reusing assets
Small direct uploads (<= 4 MiB) and URL/output imports
# 1. Single-step multipart upload (<= 4 MiB, exactly one part named "file")
curl --fail-with-body -X POST "$OPENGEN_API_URL/v1/assets" \
-H "Authorization: Bearer $OPENGEN_API_KEY" \
-F "[email protected];type=image/png"
# 2. Bounded public HTTPS import (requires Idempotency-Key)
curl --fail-with-body -X POST "$OPENGEN_API_URL/v1/assets" \
-H "Authorization: Bearer $OPENGEN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: import-frame-001" \
-d '{
"source": "url",
"url": "https://cdn.example.com/media/frame.png",
"type": "image"
}'
# 3. Reuse a prior completed job output by its stable outputIndex
curl --fail-with-body -X POST "$OPENGEN_API_URL/v1/assets" \
-H "Authorization: Bearer $OPENGEN_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: reuse-job-output-001" \
-d '{
"source": "job_output",
"sourceJobId": "00000000-0000-4000-8000-000000000001",
"outputIndex": 0
}'Large files up to 100 MiB (presigned single-PUT + complete)
For files larger than 4 MiB (or any file up to 100 MiB), prepare a presigned single-PUT upload, stream the raw bytes directly to object storage with the exact returned headers (do not send your OpenGen Authorization header to the storage uploadUrl and do not follow redirects), and finalize with POST /v1/assets/complete:
FILE_SIZE=$(wc -c < clip.mp4 | tr -d ' ')
# 1. Prepare presigned PUT plan
PLAN=$(curl --fail-with-body -X POST "$OPENGEN_API_URL/v1/assets" \
-H "Authorization: Bearer $OPENGEN_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"mediaType\":\"video/mp4\",\"size\":$FILE_SIZE}")
ASSET_KEY=$(printf '%s' "$PLAN" | jq -r '.key')
UPLOAD_URL=$(printf '%s' "$PLAN" | jq -r '.uploadUrl')
# 2. PUT bytes directly to private storage forwarding every required header in PLAN.headers
# (Content-Type plus signed storage preconditions such as If-None-Match or x-goog-if-generation-match)
printf '%s' "$PLAN" \
| jq -r '.headers | to_entries[] | "header = " + ("\(.key): \(.value)" | @json)' \
| curl --fail -X PUT "$UPLOAD_URL" -K - --data-binary @clip.mp4
# 3. Verify and finalize the uploaded asset
curl --fail-with-body -X POST "$OPENGEN_API_URL/v1/assets/complete" \
-H "Authorization: Bearer $OPENGEN_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"key\":\"$ASSET_KEY\"}"Hosted chat attachments over MCP (upload_attachment)
Hosted chat assistants that support file parameter references (_meta['openai/fileParams']) call upload_attachment with { "file": { "download_url", "file_id", "mime_type?", "file_name?" }, "type": "image" | "video" | "audio", "idempotencyKey": "..." }. OpenGen downloads the attachment directly via its SSRF-safe HTTPS importer into private workspace storage and returns a reusable assetKey without passing binary bytes through model context tokens.
Listing, inspecting, and deleting assets
Assets transition through prepared, uploading, processing, ready, failed, expired, and deleted. Only ready assets can be admitted into new generations. Calling DELETE /v1/assets tombstones the key immediately (blocking new admissions while preserving pinned references for already-accepted jobs) and returns { "state": "deleted", "inUse": <boolean> }.
# List ready image assets with cursor pagination
curl --fail-with-body \
"$OPENGEN_API_URL/v1/assets?state=ready&mediaTypePrefix=image/&limit=25" \
-H "Authorization: Bearer $OPENGEN_API_KEY"
# Inspect a single asset by key
curl --fail-with-body \
"$OPENGEN_API_URL/v1/assets?key=$(printf '%s' "$ASSET_KEY" | jq -sRr @uri)" \
-H "Authorization: Bearer $OPENGEN_API_KEY"
# Delete an owned asset via query parameter (or JSON body {"key": "..."})
curl --fail-with-body -X DELETE \
"$OPENGEN_API_URL/v1/assets?key=$(printf '%s' "$ASSET_KEY" | jq -sRr @uri)" \
-H "Authorization: Bearer $OPENGEN_API_KEY"Referencing assets in generation payloads
Pass { "assetKey": "<returned key>" } inside any canonical media field (firstFrame, lastFrame, keyframes[].image, sourceVideo, mask, references[].asset, elements[].images[], elements[].video, elements[].voice, or targetAudio). See Image to Video, Image Edit, and Reference to Video for complete runnable examples.