
Model a paid Imagild operation in Django as durable business intent, separate from the HTTP attempt that submits it. Use database constraints for logical uniqueness, persist the exact request and idempotency identity, and coordinate submission through an outbox rather than holding a transaction open during generation.
The Imagild API console supplies the remote task contract. Django owns your application's user permissions, operation records and transaction boundaries; it does not change the provider's membership or billing rules.
Key Takeaways
- Use a unique local intent identity and a stable provider idempotency key.
- Commit operation and outbox event together, then perform remote HTTP outside that transaction.
- A database rollback cannot undo a request already accepted by an external service.
Define identities before adding retry code
An application may have many customers using one provider account. Scope customer-visible operations to the correct local owner, while making generated provider idempotency keys unique across your application.
This illustrative Django 5.2 model is a starting point, not a complete application or an Imagild database schema:
import uuid
from django.conf import settings
from django.db import models
class MediaOperation(models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT
)
client_operation_id = models.CharField(max_length=100)
idempotency_key = models.UUIDField(default=uuid.uuid4, unique=True)
request_payload = models.JSONField()
provider_task_id = models.UUIDField(null=True, blank=True, unique=True)
local_state = models.CharField(max_length=32, default="ready")
last_remote_status = models.CharField(max_length=32, blank=True)
class Meta:
constraints = [
models.UniqueConstraint(
fields=["owner", "client_operation_id"],
name="unique_owner_media_intent",
)
]
Use str(operation.idempotency_key) as the HTTP Idempotency-Key. Keep the serialized provider payload immutable once submitted. The Django constraints reference documents database uniqueness; a form-level “already exists” check alone does not resolve simultaneous requests.
Put the outbox in the same transaction
Django's transaction documentation explains atomic and post-commit callbacks. Design the intake transaction to create or find the user's intent, verify its frozen parameters, approve its budget and create a durable outbox row.
Only after commit should a dispatcher submit the provider HTTP request. Do not keep locks open while waiting for a video to finish. Do not assume rolling back your own row will cancel remote work that was already accepted.
An on_commit callback can notify a dispatcher after a successful commit, but it is not itself a durable outbox. If the process stops between commit and notification, a dispatcher must still discover the stored event later.
Distinguish submission from reconciliation
For an image operation, the worker sends only supported model, prompt, resolution and optional owned reference fields to the image generation endpoint. Video uses its supported duration, ratio, resolution and enhancement fields. Local owner and local_state columns are not provider JSON parameters.
On HTTP 202, save data.id. If that response was lost, retry the identical operation with its original key and unchanged parameters. If the task ID is already stored, use GET to read it.
The same key with changed parameters conflicts. A new creative request should create another approved operation, not mutate the earlier payload and hope the same identity will mean something else.
Store observations without rewriting history
Keep remote task status and usage state separately from local worker states. “Worker interrupted” describes your app; failed or unknown must come from an actual remote observation.
Authorize every operation lookup by owner. Use a valid server-side Bearer key and active membership when reading provider tasks or content. The failed-job checklist supports clear recovery messages.
Verify concurrency and crash behavior
Test two simultaneous requests with the same local intent and ensure one operation wins. Then deliver its outbox event twice, stop a worker after acceptance and resume using the persisted identity.
Use fixture quotes based on current rates in the model hub. Confirm that a creative retake receives separate approval, as explained in the points planning guide. These tests validate your transaction design without claiming global exactly-once delivery or an atomic transaction spanning Django and Imagild.
Related tasks
- What Should You Check Before Retrying a Failed Image or Video Job?
- Imagild Points, Resolution and Jobs: Plan a Creation Before You Spend
Sources and scope
- Imagild API console: Active-member access, supported media request fields, idempotency, asynchronous task records and authenticated downloads; checked against the 2026-10-28 relay contract.
- Django 5.2 transactions: atomic transactions and on_commit callbacks; callbacks are not part of the committed transaction and are not themselves a persistent outbox.
- Django 5.2 UniqueConstraint: Database-level uniqueness declarations used in the illustrative application model.
Product instructions were checked against the current Imagild API contract and the public model catalog. Code, budgets and acceptance checks are illustrative; this article does not claim a new paid generation test, an uptime measurement, a search-volume study or a ranking of AI citations.
Prepared by Imagild Editorial, the company editorial team responsible for these guides. AI assisted research and drafting. This is documentation-based guidance with proposed examples, not a claim of hands-on testing or an independent product review. Report a correction.
Cover: Original Imagild product screenshot captured on 28 October 2026; model availability and prices may change. This image is not an API response or a performance benchmark.