Skip to content

What should my database store for each AI generation request?

Store an internal task ID, owning application user, immutable approved payload, idempotency identifier, quote and approval context, returned job ID, current state and delivery outcome. Keep secrets in separate server configuration. This task record is what connects a user action to existing remote work when a worker, browser or HTTP connection disappears.

SHIP A RELIABLE INTEGRATIONAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Create the record before dispatch; Attach remote identifiers promptly; Track delivery and acceptance.
Workflow diagram: Create the record before dispatch → Attach remote identifiers promptly → Track delivery and acceptance. Read the article for evidence and limits.

One status field is often insufficient

Your local queue state, AISwapLab generation status, private download outcome and creative approval answer different questions. A completed remote job can still await local delivery, and a delivered file can fail the user's brief. Preserve those distinctions instead of overwriting everything with success or error. The suggested record columns belong to your application database; adding fields such as internal_task_id to an AISwapLab creation body is not implied by this design.

What to do next

  1. 01

    Create the record before dispatch

    Persist the intended model, exact body and unique identifier before sending the first creation request. Record who approved the spending ceiling and which quote was reviewed.

  2. 02

    Attach remote identifiers promptly

    When a response arrives, save job ID and returned routes before notifying a transient frontend. Keep the original payload immutable so a network retry can recover the same task.

  3. 03

    Track delivery and acceptance

    Record validated download completion and the user's review separately from technical generation. Use safe identifiers in logs while retaining private content only in authorized storage.

A concrete example

Illustrative record: a task can be locally delivered, remotely completed and creatively rejected at the same time. Those three facts explain both the successful technical path and why the project still has no approved final image.

Task event and recovery ledger

Observed local eventPersist before moving onRecovery after a crash
Approved but not sentOwner, exact body snapshot, quote/approval and idempotency valueDispatch only that approved task
Send attempted; response absentSend-attempt time and original request identityRecover unchanged submission; do not invent a fresh task
Remote completed; local delivery incompleteReturned job/content route and validated transfer stateRetrieve that result without another creation
Delivered but creatively rejectedArtifact version and specific review findingNew revision needs separate approval and identity

Before you call it ready

  • Approval exists before network dispatch.
  • Remote task identity is durable.
  • Delivery and creative acceptance have separate fields.

When to stop or choose another method

If your schema cannot represent accepted-but-unknown or completed-but-undelivered work, add those states before launch. Otherwise ordinary failures can become hidden duplication or lost customer output.

Sources

One task. A recoverable workflow.

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

Open API documentation