Engineering design reference

Design a production face swap pipeline end to end

Turn a media-generation request into an owned, observable, and correctly settled task. This reference separates the current DeepSwapAI API contract from general architecture decisions your integration must make.

By DeepSwapAI Product TeamReviewed July 22, 2026Technical design guide

A public-contract reference, not a private infrastructure diagram

This is a public-contract design reference, not a diagram of DeepSwapAI's private infrastructure. It distinguishes behavior verified in the public API from recommended integration controls. It does not disclose provider topology, queue technology, model placement, worker count, internal network design, throughput, latency, SLA, accuracy, or visual-quality benchmarks.

Use it to decide where ownership, validation, task state, retry, settlement, delivery, deletion, and evidence should live in your own integration. For exact multipart fields and responses, use the API documentation and OpenAPI 3.1 contract.

Five asynchronous workflows share one control shape

Every current generation workflow authenticates with a Bearer API key, accepts multipart media, returns a taskId, and exposes owner-scoped status through GET on the same route. Completion uses polling; webhook callbacks and official language SDKs are not currently published.

WorkflowPOST and polling GETCost unitPrimary bound
Photo/api/ai-tasks2 credits per task30 MB per image
Batch photo/api/ai-tasks/batch-face-swap2 credits per output20 images, 200 MB combined
Mapped group photo/api/ai-tasks/multi-face-swap2 credits per replacement face10 mapped faces, 120 MB combined
Video/api/ai-tasks/video2/s at 720p or 5/s at 1080p300 seconds, 200 MB target
GIF / short clip/api/ai-tasks/gif3 credits per second30 seconds, 100 MB target

The live workspace and API documentation remain authoritative for exact formats, minimum charges, and request fields. A verified account email is required, one generation can be active per account, and exhausted limits can return HTTP 429 with retry information.

Give each irreversible decision one owner

01

Ingress and identity

Terminate TLS, authenticate the server-held key, assign a request correlation ID, and bind every task to one account.

02

Policy and validation

Check permission state, workflow fields, detected media type, byte size, count, duration, mapping, account readiness, and credit availability.

03

Task ledger

Persist the taskId, owner, workflow, expected charge, state transitions, timestamps, and settlement outcome before returning control.

04

Bounded processing

Decouple request acceptance from generation, cap active work, and distinguish retryable transport failures from invalid inputs.

05

Settlement

Use one atomic authority for reserve, completion, and failed-task refund decisions so a retry cannot charge or refund twice.

06

Delivery and deletion

Authorize result access by task owner, apply the image-export entitlement, and remove media on the documented 24-hour schedule.

Move from request contract to evidence-backed deletion

  1. Freeze the public request contract. Choose the exact workflow and record fields, media limits, cost unit, and terminal states.
  2. Gate authorization, consent, and account readiness. Keep the API key server-side and require a permission decision before accepting media.
  3. Validate media and calculate cost before enqueueing. Inspect detected type, size, count, duration, mapping, and available credits before expensive work.
  4. Create one durable task record. Persist ownership, workflow, expected charge, input references, state, and taskId.
  5. Process asynchronously behind a bounded queue. Limit concurrency and classify transient versus permanent failures.
  6. Settle credits exactly once. Commit completed work and apply the documented failed-processing refund path without double settlement.
  7. Expose owner-scoped status and result access. Poll at a measured interval and stop at COMPLETED, FAILED, or CANCELLED.
  8. Enforce deletion and retain operational evidence. Remove media on schedule while retaining only the minimum allowed task, billing, security, and support record.

Keep processing state separate from money state

PENDINGPROCESSINGCOMPLETEDor FAILED / CANCELLED
EventTask recordCredit actionClient action
Request rejected before task creationNo accepted taskDo not infer a chargeCorrect the request or account state
Task acceptedPersist taskId and expected costTreat settlement as server-ownedBegin measured polling
Task completedTerminal resultCompleted work remains settledAuthorize result retrieval
Processing failedTerminal failureCurrent contract refunds failed processing automaticallyRead the failure before deciding to resubmit
Response outcome uncertainReconcile before another POSTNever guess from a timeoutUse the stored taskId or account history

No idempotency-key field is documented in the public contract. The calling service should disable duplicate submission, persist the first taskId, and reconcile an uncertain network response before issuing another POST.

Retry only when the failure class permits it

StatusFailure classArchitecture response
400Invalid request or mediaReject permanently until fields or media change.
401 / 403Key or account readinessRotate the key or complete verification; do not loop.
402Insufficient creditsAdd credits and submit a new task only after confirmation.
404Wrong owner, route, or taskIdReconcile identity and stored task metadata.
429Rate or active-generation limitHonor Retry-After when supplied, add jitter, and cap retries.
500Temporary acceptance or read failureUse bounded exponential backoff and reconcile before duplicate submission.

Trace control decisions without copying sensitive media into logs

Recommended task telemetry includes a correlation ID, taskId, account identifier, workflow, sanitized media facts, expected credit amount, state transitions, retry count, error class, settlement event, and deletion timestamp. Do not log API keys, face images, complete uploaded filenames, signed result URLs, or multipart bodies. The W3C Trace Context recommendation defines interoperable request context; it is a design option, not a claim about DeepSwapAI's private implementation.

For upload defenses, validate decoded filenames, detected content, allowed formats, counts, and sizes; do not trust the browser-supplied Content-Type alone. The OWASP File Upload Cheat Sheet is the external security reference. Use the consent and disclosure planner for the human authorization gate and the Trust Center for current public service boundaries.

Choose managed, self-hosted, or hybrid by the controls you must own

ModelYou ownExternal dependencyBest fit
Managed APIConsent gate, application UX, task persistence, polling, review, and business policyPublished API, limits, pricing, and processing behaviorTeams prioritizing integration speed over infrastructure control
Self-hostedModel, GPU capacity, queue, moderation, storage, security, settlement, deletion, and incident responseModel and infrastructure supply chainTeams with a justified control or deployment requirement and operations capacity
HybridInternal policy, orchestration, audit record, review, and provider abstractionOne or more bounded generation servicesTeams that need application-level control without operating every model component
Decision boundary: this matrix compares responsibility, not output quality. It does not establish that one deployment model is faster, safer, cheaper, or more accurate.

Current product facts plus primary external standards

The DeepSwapAI Product Team checked the five public routes, Bearer authentication, multipart requests, task states, polling flow, error responses, concurrency boundary, credit settlement, trial image entitlement, and 24-hour media deletion on July 22, 2026. The recommended controls are informed by the OpenAPI Specification 3.1.2, OWASP upload guidance, NIST AI RMF 1.0, and W3C Trace Context. See the claim verification methodology for how current product statements are separated from general design guidance.

Know what the public contract does and does not establish

Is this DeepSwapAI's private production architecture?

No. It is a public-contract design reference and does not disclose provider topology, queue technology, model placement, worker count, internal network, or service-level targets.

How does a client learn that a task finished?

Keep the taskId returned by POST and poll GET on the same workflow route until COMPLETED, FAILED, or CANCELLED. Webhook callbacks are not currently published.

Can the API key be placed in client code?

No. Treat it as a server-side secret and keep it out of browser bundles, mobile binaries, repositories, analytics, logs, and support messages.

Does the API publish an idempotency key?

No idempotency-key field is documented. Prevent duplicate submission, persist the first taskId, and reconcile uncertain responses before another POST.

Does this design guarantee throughput or quality?

No. It is not a benchmark, SLA, accuracy score, or quality guarantee.

Implement against the verified contract

Use the exact endpoint reference and OpenAPI file when you are ready to turn this control model into a server-side integration.

Open API documentation