Skip to content

How do I avoid saving an API error page as result.mp4 or result.png?

Validate the response before naming or publishing it as media. Download only the owned completed job's content, check status and expected content type, and verify that the resulting file can actually be opened. An .mp4 or .png filename does not turn an HTML login page or JSON error into a video or image. Preserve the job ID and retry delivery rather than creating another generation.

SHIP A RELIABLE INTEGRATIONAISwapLab team · Editorial methodUpdated 3 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Check readiness and use the owned content route; Validate before writing the final filename; Verify the actual artifact and promote it.
Workflow diagram: Check readiness and use the owned content route → Validate before writing the final filename → Verify the actual artifact and promote it. Read the article for evidence and limits.

Use a staging file until the response is known to be the expected object

AISwapLab content downloads require API authentication and ownership; a website session cookie is not a replacement for the API bearer credential. The content route can also deliver chat JSON, so application/json is not universally an error: compare it with the expected job kind and state. An HTTP success alone is insufficient to establish a complete usable image or clip. A partial 206 response may represent only one byte range, not a finished full download.

What to do next

  1. 01

    Check readiness and use the owned content route

    Read the job and wait for completed with a content_url. Resolve that documented route against the expected AISwapLab origin and authenticate from your server. Do not send the key to an arbitrary URL supplied by untrusted input or expose it in a public result link.

  2. 02

    Validate before writing the final filename

    Inspect HTTP status and Content-Type first. For a media job, handle an error body as an error even if the requested filename ends in a media extension. Write to a temporary local file while transferring, distinguish a complete 200 download from intentionally assembled byte ranges, and preserve a redacted diagnostic if the transfer fails.

  3. 03

    Verify the actual artifact and promote it

    Check nonempty file size and open or decode the completed artifact with an appropriate local media tool. For a text job, validate the expected JSON instead. Only after validation move the staged file to the final application result and allow creative review. Keep delivery errors attached to the original job.

A concrete example

Illustrative integration: a worker requests an image but receives a 401 JSON response after its key expires. A naive downloader writes those bytes as result.png. A response-aware worker records the authentication error, leaves no final image and restores the approved credential configuration. It then retrieves the existing completed job rather than submitting a new image. A separate chat task legitimately downloads JSON, so the validation rule uses the task's expected kind instead of banning JSON everywhere.

Download gate

CheckReject or hold when
Job stateNot completed or no content route
ResponseError status or unexpected type for job kind
TransferIncomplete body or unassembled partial range
ArtifactCannot parse/decode as expected

Before you call it ready

  • Status, expected job kind and Content-Type are checked together.
  • Partial or error bytes never become an approved final media file.
  • The actual downloaded object is opened or parsed before delivery.

When to stop or choose another method

Stop final delivery when the response or artifact fails validation. Fix authentication, readiness or transfer handling on the same job; a new generation cannot repair a downloader that saves error pages as media.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation