AI Router · CLI · MCPCheapest eligible quotes before you create
task · activation

Script a repeatable image generation workflow

Sequence model discovery, generation, wait, and download with explicit failures.

Start with 20 free credits
Tool rack

Freeze the command surface before scripting

A repeatable image workflow starts by pinning the npm package and checking the interface actually installed. The npm registry and repository commit `c29bc9a91204ae04c7ce124a756b79730e9b2838` both identify version 0.1.2, and the repository manifest requires Node.js 20 or newer. Matching version labels do not prove that an arbitrary local installation is intact or unchanged. Record the resolved artifact version beside every run, and test that artifact's help and JSON behavior before promoting an automation change.

The pinned repository configuration reads `OFFLINECREATOR_API_KEY` from the environment, requires it for local CLI use, and accepts only values beginning with `oc_live_` or `oc_test_`. Inject the value through the runner's secret environment facility; keeping it out of arguments, committed files, and shell tracing is the wrapper's safety policy. Invoke the pinned executable's `models` command, require a zero process status, and parse stdout as JSON. Select a model identifier from that response instead of embedding an unverified name indefinitely.

Credit gauge

Submit one generation and preserve its JSON

At pinned repository commit `c29bc9a`, the CLI accepts `generate` with `--model` or `--modelId`, a required `--prompt`, and an optional `--aspect` or `--aspectRatio`. Its parser recognizes only `16:9`, `9:16`, and `1:1`; another ratio is omitted rather than forwarded as a supported value. Build the command as an argument array so prompt punctuation is not reinterpreted by a shell. Save the exact non-secret arguments, artifact version, start time, stdout, stderr, and process status as one run record.

Treat submission as successful only when the command exits zero and stdout parses to the expected JSON object. If model or prompt is missing, the parser writes usage text to stderr and returns 1. Errors thrown by configuration or API calls are caught by the entry point, printed to stderr, and also produce process status 1. Never retry merely because stdout is empty: first classify the diagnostic and determine whether a remote generation might already have been created.

Command strip

Use the bounded wait branch deliberately

For a newly started text-to-image job, add `--wait` when the foreground process may remain attached. At pinned repository commit `c29bc9a`, the parser invokes the wait helper only when the start response does not say an upload is required, and it has no standalone `wait` CLI command. A script must not invent that command for a previously stored job. Upload-required work needs the separate upload and submit workflow before polling can represent generation progress.

The public client polls the generation every 1.5 seconds by default for up to 120 seconds. It returns when status is `completed` or `failed`. At the deadline it performs one final read and returns that payload with `timedOut: true`; timeout is therefore an unresolved observation, not proof of failure or cancellation. Persist the generation UUID before branching so a later operator or supported MCP/API client can reconcile the same job instead of submitting a duplicate.

Scope ledger

Retrieve only a verified completed output

Advance to retrieval only when parsed JSON identifies the job as completed and includes an output URL. At pinned repository commit `c29bc9a`, the command parser does not expose a standalone `download` subcommand; its supported cases are models, balance or credits, generate, and help. A shell workflow can pass the returned URL to a separate HTTP downloader, but it should not describe that downloader as an OfflineCreator CLI feature. Write to a temporary file, verify the transfer succeeded, then rename into the final output path.

The public client normalizes output URLs against the configured Studio origin. If an absolute URL uses another origin, the helper either maps an API path back to the configured origin or refuses to expose it; malformed or untrusted values are replaced with `outputUrlError`. Require an HTTPS Studio-origin URL, avoid logging URL query details, and fail closed when the field is absent. Do not treat a JSON response containing `failed`, `timedOut`, or `outputUrlError` as a downloadable result.

Related circuit

Give the wrapper its own small result contract: operation name, pinned package version, started timestamp, process status, parsed generation UUID, last observed state, timeout flag, and final local path. Keep raw stdout and sanitized stderr as separate artifacts. Exit zero only after a completed response has been downloaded and atomically placed at the requested path. Use distinct nonzero wrapper codes for invalid local configuration, submission uncertainty, remote failure, wait timeout, malformed JSON, and transfer failure.

Test the wrapper without production credentials by exercising local argument and parsing boundaries: missing prompt must be nonzero, help must be zero, malformed fixture JSON must be rejected, a timed-out fixture must retain its UUID, and an untrusted output URL must never reach the downloader. These checks validate your adapter rather than claiming a live generation succeeded. An authenticated production call was intentionally outside this research task.