How to Batch 3D API Jobs Without Duplicate Submissions
Compare real TRELLIS 202 and 400 responses and test a SQLite job claim. See run IDs, a simulated timeout, a rendered GLB and cost accounting.

A batch submitted two TRELLIS jobs with the same image and seed. The request with a 1024 texture was accepted, returned a run ID and eventually produced a GLB. The request with a texture size of 777 returned HTTP 400 and no ID. Those two outcomes need different retry rules. We also tested a local SQLite ledger against eight competing workers and a simulated timeout before the ID arrived. This guide shows how to keep a batch moving without treating every error as another paid submission.
Key takeaway
- A live TRELLIS request with
texture_size: 1024returned HTTP 202, then completed after nine status lookups with the same run ID. It returned a 1,852,468-byte GLB with 17,608 triangles. - The same route, image and seed with
texture_size: 777returned HTTP 400 and no run ID. The error listed 512, 1024 and 2048 as accepted values for this field. - A local ledger gave one of eight competing workers a claim on the same queued row. It also rejected reuse of a key with a different payload and blocked a second claim after a simulated ambiguous submit timeout.
- The HTTP trace establishes request counts and outcomes. It does not establish charges for those requests. Use the organization’s settled billing record to fill in actual cost.
Separate rejection, polling and ambiguous submission
The first live request used the public TRELLIS example image, seed 77 and the documented size 1024. The second changed only that size to 777. The first had a provider ID and could be polled. The second never reached a pollable state in the recorded response. Before sending a corrected request, record the rejection on the original application job. If you use an immutable payload per key, give the corrected version its own key. SandBase run API · TRELLIS model parameters

The response summaries come from the actual HTTP calls. The invalid request returned no ID. The accepted request used one ID for all nine status lookups.
| Observed situation | Next action | New generation POST |
|---|---|---|
| HTTP 202 with ID | Persist the ID and poll it | No |
| HTTP 400 with unsupported value | Correct the payload, review and schedule a new version | Only for the corrected job |
| GET times out or temporarily fails | Retry the lookup for the same ID | No |
| POST outcome unresolved, no ID received | Record unknown and reconcile the original attempt | Wait for a decision |
| Provider completes, file fails validation | Record the asset issue and choose a repair or another attempt | Only if a new run is needed |
The third case is a status read, so it can be repeated with the stored ID. The fourth case is harder because the server may have accepted the request even though the client did not receive the response. An application lock can prevent a second local worker from attempting the same row. It cannot make an external POST idempotent. If the selected operation supports idempotency, use its documented semantics and key. Otherwise keep an ambiguous request visible for reconciliation.
Use a local job key with an immutable payload
The ledger stores the application key, canonicalized payload, state, provider run ID when available and an error field. The key identifies one submitted intention. The example claims the queued row with a conditional SQL update. A worker can proceed only if its update changed one row. A later worker sees the existing state and skips submission.

This screenshot is from the local test. The ambiguous timeout is simulated. No live requests are issued by this ledger exercise.
We ran eight local workers with separate SQLite connections against one queued row. One claimed it and seven were blocked. Registering that key with another payload raised an error. We separately ran the ledger demonstration twice and got the same output. The fixture moves one job through pending, running and completed, records an input rejection, and records an unknown state before any ID. None of those final rows allows another submission claim. This is a state-machine test and a concurrency check on the local store. It does not cover every production race or a distributed queue.
Save the example as ledger.py. It uses the Python standard library and a new demonstration database. The completed fixture uses a demonstration ID. No HTTP calls occur in this code. The live request trace came from a separate client.
import argparse
import hashlib
import json
import sqlite3
SCHEMA = """
CREATE TABLE IF NOT EXISTS job (
key TEXT PRIMARY KEY,
payload TEXT NOT NULL,
state TEXT NOT NULL,
run_id TEXT UNIQUE,
error TEXT
);
"""
def register(db, key, payload):
serialized = json.dumps(payload, sort_keys=True, separators=(",", ":"))
with db:
db.execute("INSERT OR IGNORE INTO job VALUES (?, ?, 'queued', NULL, NULL)",
(key, serialized))
prior = db.execute("SELECT payload FROM job WHERE key=?", (key,)).fetchone()[0]
if prior != serialized:
raise ValueError("Key reused with a different payload")
def claim(db, key):
with db:
return db.execute("UPDATE job SET state='submitting' WHERE key=? AND state='queued'",
(key,)).rowcount == 1
def receive(db, key, state, run_id=None, error=None):
with db:
updated = db.execute("""
UPDATE job SET state=?,run_id=?,error=? WHERE key=? AND state='submitting'
""", (state, run_id, error, key)).rowcount
if updated != 1:
raise ValueError("Unexpected state during submission")
def poll_result(db, key, run_id, state, error=None):
with db:
updated = db.execute("""
UPDATE job SET state=?,error=? WHERE key=? AND run_id=?
AND state IN ('pending','running')
""", (state,error,key,run_id)).rowcount
if updated != 1:
raise ValueError("Run ID or state mismatch during poll")
def demo(database):
with sqlite3.connect(database) as db:
db.row_factory = sqlite3.Row
db.executescript(SCHEMA)
good = {"model":"trellis/trellis","image":"public-example","texture_size":1024}
bad = {**good, "texture_size":777}
for key,payload in [("recorded-complete",good),("invalid-size",bad),("lost-submit",good)]:
register(db,key,payload)
if claim(db,"recorded-complete"):
receive(db,"recorded-complete","pending","recorded-demo-id")
poll_result(db,"recorded-complete","recorded-demo-id","running")
poll_result(db,"recorded-complete","recorded-demo-id","completed")
if claim(db,"invalid-size"):
receive(db,"invalid-size","rejected",error="HTTP 400: unsupported texture_size")
if claim(db,"lost-submit"):
receive(db,"lost-submit","unknown",error="Simulated timeout before receiving an ID")
rows = []
for row in db.execute("SELECT key,payload,state,run_id,error FROM job ORDER BY key"):
record = dict(row)
record["payload_sha256"] = hashlib.sha256(record.pop("payload").encode()).hexdigest()
record["second_claim_allowed"] = claim(db, record["key"])
rows.append(record)
print(json.dumps(rows, indent=2))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--database", default="retry-demo.sqlite")
demo(parser.parse_args().database)python3 ledger.py --database retry-demo.sqlite > first.json
python3 ledger.py --database retry-demo.sqlite > second.json
cmp first.json second.jsonUse a fresh database filename for the first run. The first call shows rejected, unknown and completed with second claim set to false. The second gives the same output. In a production worker, record the claim before issuing the POST. On restart, a row left in submitting with no ID needs investigation. Keep that state available so a retry policy can distinguish an interrupted worker from a job that was never claimed.
Keep cost attached to attempts and acceptance
A batch has application jobs, provider runs and accepted deliverables. An HTTP request count mixes different kinds of work. A status GET reuses the same run ID. A new POST can create another run. An accepted model output can still fail your asset policy and require local repair or another generation. Preserve those distinctions in the report.
| Ledger field | Where it comes from | What it answers |
|---|---|---|
| Application key and payload hash | Queue record | Which version did the worker attempt? |
| Provider run ID | Accepted response | Which status and billing entries belong to it? |
| Settled charge and currency | Organization billing records | What amount actually settled? |
| Asset validation and visual status | Intake process | Did the output become usable? |
| Repair effort | Recorded local work | What additional work made it deliverable? |
If you have a fixed spending cap, calculate an estimated exposure from submissions eligible to create a new run, then reconcile with actual charges. Keep unknown charges as unknown until settlement. A price shown on a route page may describe the current configuration, while an actual invoice can reflect the account and options used at the time. If two jobs produce one accepted asset, include both settled generation costs and any recorded repair effort when you calculate the cost per accepted result. The budget API comparison provides one worked example using actual charges and a defined acceptance rubric.
Verify the result of the successful job

The successful request returned this GLB. The local inspection counted 1,852,468 bytes, 17,608 triangles, one embedded image and no validator errors or warnings.
The valid job completed with one output item. We downloaded it, verified the GLB header and measured the mesh and embedded image count. It rendered in Three.js. Record the output hash and the validation report with the job. Keep the visual decision separately if the batch needs exact parts or a particular silhouette. A finished provider run only says generation reached its terminal state. Use automated GLB intake to record material, geometry and visual checks.
Use a route such as TRELLIS image-to-3D to start with one known-valid payload, then add a deliberately rejected input in a controlled test. Before enabling retries for many jobs, simulate an interrupted submit, confirm a second worker cannot claim the same row and test what happens when the status lookup is unavailable. The single-run backend walkthrough shows a concrete submit, resume and download path. Extend it with your queue and billing records when you need to operate a batch.
Keep a small reconciliation queue
Store the last attempt time and what the worker observed before handing an unresolved row to an operator. If the provider run is recovered, link its ID and resume polling. If the provider confirms that no request was accepted, schedule a fresh attempt according to your project’s budget. Preserve both decisions in the audit log. A queue that silently reclassifies unknown as queued can hide the very duplicate cost it was meant to control.
Check the backlog separately from charges. The number of uncertain rows tells you how much work needs reconciliation, while the billing table says what has actually settled. A project can pause new submissions when uncertainty becomes too high and continue polling known IDs. Once the records are reconciled, resume admission using the remaining budget and the same immutable key rules.
For an observed four-route batch with delivery sizes and visual checks, see 12 batch web-asset jobs compared.
FAQ
Should a 400 immediately retry?
Inspect the response and fix the input first. The observed 400 was an unsupported enum value, so the same payload would ask for the same unsupported configuration. Use a new version after correction.
Is the local key the same as the SandBase run ID?
The application key exists before submitting. The provider run ID comes from an accepted response. Store both. Use the provider ID for status lookups and the local key to manage queue ownership.
What if I never receive an ID after submission?
Keep the original attempt in an unresolved state and reconcile it using the request and provider records you have. That prevents a restarted worker from treating the ambiguous submission as fresh work.
Found this useful? Share it