A tenant's image-generation bill should be explainable without opening a candidate's application. That constraint changes how to choose a text-to-image API for a Node.js web app: start with the response contract and the evidence needed to attribute each call.

Short answer: choose the API with a clear REST flow, understandable authentication, stable documentation, and a predictable image response. Keep a small application contract in front of it so swapping the provider behind image generation leaves the rest of the web app's code intact. For this workflow, per-call cost attribution belongs in that contract review from day one.

Consider an e-commerce employer's hiring workspace. Recruiters score candidates against a job rubric; generated illustrations accompany explanations of the rubric. The image is presentation material. It supplies no evidence about a candidate and must not determine their score. This gives the integration a useful boundary: generate an illustration from an approved rubric description, then associate the generation operation with the tenant that requested it.

Keep those separate.

An attractive SDK example won't tell you whether tenant A's rubric illustrations can be distinguished from tenant B's when someone asks about usage. A documented response shape, a trusted tenant association, and an explicit treatment of missing cost information will.

How should a web app choose a text-to-image API response contract?

Before: a route handler sends a prompt and passes the provider's response directly to the page. The page learns the provider's representation. Accounting happens somewhere else, if it happens at all.

After: the server associates the operation with an authenticated tenant, requests an image, checks the documented response, and adapts it into the application's presentation contract. A separate accounting record preserves the operation's observed cost and completion evidence. The browser renders the illustration without learning how the upstream provider represents it.

Diagram in words: authenticated tenant → rubric illustration request → provider adapter → application image result. Alongside that path: operation identifier → observed call record → tenant usage summary.

The distinction matters because “the image rendered” and “the call was attributed” answer different questions. A successful render is useful evidence for the product team. It doesn't establish which tenant incurred the charge. Conversely, a cost record cannot prove that the browser received a usable image. Keep both outcomes visible, and avoid placing candidate text or full prompts in routine accounting logs.

Attribution comes first.

For response-format review, ask where the image material lives, what the consumer must do to render it, and which fields are required. Read the selected model's documentation before implementing the adapter. Don't assume two APIs return interchangeable image results because their request examples both contain a prompt. A universal parser needs evidence that the chosen responses actually share a contract.

Model discovery can help select models without changing the core generation code. Treat that as configuration discovery, though; a stable application interface does not promise identical output characteristics across models. Approve a replacement against the rubric-illustration use case before routing tenant traffic to it.

Compare documentation through the same tenant workflow

For a junior-friendly MVP, make each candidate API answer the same practical questions. Can a developer identify the authentication mechanism, find a complete generation request, understand the response, and preserve the evidence needed for tenant attribution? Advanced controls are useful only if this application needs them. Clear basics come first.

OpenAI, Replicate, and Stability AI are real alternatives to put through that review. The table below defines a fair documentation exercise, rather than claiming an unmeasured winner. Their names alone establish neither response compatibility nor accounting completeness.

Option Documentation exercise for this app Decision boundary
OpenAI Read the image-generation guide and identify the selected model's request and response contract. Choose it if that documented flow fits the rendering and attribution requirements; don't assume an SDK removes the need to inspect results.
Replicate Read its getting-started material, then trace the selected model's documented inputs and outputs. Choose it if the model's documented result and completion flow fit the app; keep model-specific assumptions inside the adapter.
Stability AI Review the API reference for the chosen image operation and its output handling. Choose it if the documented controls and response suit rubric illustrations; avoid adding controls the MVP cannot justify.
Gemini Review the image-generation documentation and trace the chosen model's response into the rendering component. Include it when its documented workflow meets the same acceptance criteria; do not infer compatibility from another provider's SDK.

These are distinct starting points: an image guide, a selected-model review, and an operation reference. Apply the same acceptance criteria to all three. A useful comparison records what each document establishes, what the application must implement, and which questions remain unanswered. It doesn't turn missing evidence into a negative capability claim.

Infrai offers one API key and one bill across backend capabilities, with a plain REST API and no SDK required, while letting you switch vendors without changing the calling code. The capability contract stays stable while the vendor behind it changes. A single credential and unified billing avoid separate credentials and invoices for each vendor. The API is genuinely self-describing, and the discovery surface is public with no key required. For a junior developer reviewing the contract, that makes discovery inspectable before adding credentials. Its OpenAI-compatible surface supports existing clients, and its specified per-call cost, vendor, latency, and request metadata provides useful inputs for the tenant accounting workflow. The application still owns tenant attribution. No provider-level cost field can infer the authenticated tenant for you.

The trade-off is extra application responsibility. This approach is not a fit if the acceptance criterion is specialized moderation or advanced upscaling; evaluate alternatives against those specific requirements before selecting a general generation integration. Provider metadata alone cannot produce tenant-level accounting.

That last responsibility is the important one here. Prefer a documented, inspectable integration over a large model menu. If you later add rubric titles, prompt rewriting, or alt text, chat completions can cover that adjacent work without introducing another provider. Keep those calls distinguishable from image generation in your usage records.

Make missing cost visible with a small local ledger

Start with a small model-discovery request over plain HTTP, with no SDK required. This TypeScript example reads the configured service base URL ending in /v1 from IMAGE_API_BASE_URL and the credential from INFRAI_API_KEY. Set both on the server, then run the file with your project's TypeScript runner. It uses the native model catalog, checks status, and applies bounded backoff for rate limits. The sample permits 3 attempts and stops if the requested wait exceeds 60 seconds; these are example policy choices. It does not generate or charge for an illustration on the reader's behalf. Inspect the selected image capability's documented schema before implementing generation; chat model discovery alone does not establish image-model compatibility.

async function inspectCatalog(): Promise<void> { const base = process.env.IMAGE_API_BASE_URL; const key = process.env.INFRAI_API_KEY; if (!base || !key) throw new Error("Set the base URL and API key"); const url = new URL(`${base.replace(/\/$/, "")}/ai/models`); if (url.protocol !== "https:") throw new Error("HTTPS is required"); for (let attempt = 0; attempt < 3; attempt++) { const response = await fetch(url, { method: "GET", headers: { Authorization: `Bearer ${key}` }, }); if (response.status === 429 && attempt < 2) { const retryAfter = response.headers.get("Retry-After"); const seconds = retryAfter === null ? NaN : Number(retryAfter); const date = retryAfter === null ? NaN : Date.parse(retryAfter); const requested = Number.isFinite(seconds) ? seconds * 1000 : Number.isFinite(date) ? date - Date.now() : 0; const delay = Math.max(1000 * 2 ** attempt, requested); await response.body?.cancel(); if (delay > 60000) throw new Error("Retry later as requested"); await new Promise(resolve => setTimeout(resolve, delay)); continue; } if (!response.ok) { throw new Error(`Catalog HTTP ${response.status}: ${await response.text()}`); } console.log(await response.json()); return; } } inspectCatalog().catch(error => { console.error(error); process.exitCode = 1; }); 

Now isolate the accounting boundary. The following example makes no network requests and defines an application-owned record, not a provider response schema. Save it as tenant-ledger.ts and run it with the same TypeScript runner. Its record is synthetic; it represents neither a measured request nor a vendor price.

The example deliberately omits cost observations. That makes the most dangerous reporting mistake easy to see: missing cost must not become a claim that generation was free.

type ObservedCall = { tenantId: string; callId: string; operationId: string; costUsd: number | null; }; const calls = new Map<string, ObservedCall>(); function observe(call: ObservedCall): void { if (!call.tenantId || !call.callId || !call.operationId) { throw new Error("Tenant, call, and operation identifiers are required"); } if (call.costUsd !== null && (!Number.isFinite(call.costUsd) || call.costUsd < 0)) { throw new Error("Observed cost must be finite and nonnegative"); } const key = JSON.stringify([call.tenantId, call.callId]); const existing = calls.get(key); if (existing && JSON.stringify(existing) !== JSON.stringify(call)) { throw new Error("Conflicting observation for an existing call"); } calls.set(key, { ...call }); } function summarize(tenantId: string) { const rows = [...calls.values()].filter(c => c.tenantId === tenantId); return { tenantId, observedCalls: rows.length, knownSubtotalUsd: rows.reduce((sum, c) => sum + (c.costUsd ?? 0), 0), callsWithoutCost: rows.filter(c => c.costUsd === null).length, complete: rows.every(c => c.costUsd !== null), }; } const illustrativeCall: ObservedCall = { tenantId: "merchant-a", callId: "illustrative-call-1", operationId: "rubric-illustration-1", costUsd: null, }; observe(illustrativeCall); observe(illustrativeCall); console.log(summarize("merchant-a")); 

The duplicate observation leaves one record. The summary reports one call without cost and marks the result incomplete. Its known subtotal is only a subtotal. Label it that way in the UI.

Unknown isn't free.

There's a second trap here. Deduplicating a log observation is different from deduplicating an upstream generation request. If two actual provider calls occur during one user operation, record both calls under that operation. Otherwise the dashboard can undercount usage while appearing perfectly tidy. Handle upstream retry behavior according to the selected API's documented idempotency rules. This local map prevents duplicate observations only; it provides neither durable storage nor safe coordination between server processes.

For a production design, persist the observations and make the uniqueness rule explicit. Treat the example's call identifier as an application identifier until an adapter has verified the meaning of the provider's request identifier. Do not assume that an arbitrary response ID identifies a billable call. Keep full identifiers in restricted accounting records; aggregate operational metrics by bounded dimensions such as capability and completion state. Putting every request identifier into metric labels makes the metrics harder to operate without improving attribution.

An alert should answer a teachable question: are completed illustration operations missing accounting observations? A second check should distinguish incomplete attribution from increased known spend. A merchant dashboard that displays a subtotal without its completeness state invites the wrong interpretation, even if the arithmetic is correct. The example intentionally leaves the budget threshold unset because an application's alert policy should come from its own operating requirements.

Does this add too much work for an MVP?

The first objection is reasonable: why build accounting before the image feature works? Keep the first version small. Bind the tenant on the server, retain the operation identifier, normalize the image response, and capture the available call evidence. These are application responsibilities that an SDK cannot decide for you. You can defer an elaborate dashboard while preserving the records it will need.

Start with evidence.

The second objection is about provider switching: if the contract stays put, can every model be swapped freely? No. A stable interface preserves the calling code; it does not establish equivalent image content, controls, moderation, or suitability for a rubric illustration. Review those separately. The image should remain explanatory material, with candidate scoring grounded in the job rubric rather than generated imagery.

For this hiring workspace, the practical choice is the API whose documented generation flow a junior developer can explain from request through rendered image and attributed call. Select the provider on that evidence. Keep missing cost visible, preserve the tenant boundary, and make model changes a reviewed configuration decision.

Sources

References for reviewing the competing integrations and prompt design: