Before you begin
- Your organization must be in the API private beta.
-
Create an API key in ZeroGen under Settings → API keys. The key needs the
generations:createandgenerations:readscopes. A test key runs the same requests on placeholder media at no charge, so start with one. -
Store the key in an environment variable on your server:
Create and read a generation
1
Check your key
Read the calling key’s own access. This request needs no scope.The response names the key’s mode (
live or test), the scopes it can use
now, and its organization. For details, see
Authentication.2
Create a generation and wait for it
Send the model ID and a prompt to ZeroGen validates the request against the model’s schema, prices it, holds
the quoted amount, and starts the work, all in this one call. Nothing is
charged unless every check passes.
POST /v1/generations. The
Prefer: wait=60 header holds the response for up to 60 seconds while the
generation runs. The Idempotency-Key header makes the request safe to
retry; use a new key for each new generation.- If the generation ends within the wait, the response is
200. - Otherwise, the response is
202with the generation’s current state.
Location header gives the generation’s path, such as
/v1/generations/0b7f2c1e-5d4a-4c3b-9a8f-7e6d5c4b3a21.3
Read the generation until it ends
Read the generation by its ID. Add A read only reads the generation’s stored state, so reading more often
doesn’t add work or cost. Each read still counts toward your
rate limits.
Prefer: wait=N, up to 60 seconds, to
hold the response until the generation ends or the wait runs out.Generation statuses
A generation has one of the following statuses. The last four are final.
Each output in
outputs has its own status: queued, running,
succeeded, failed, or cancelled. A failed output carries an error in
the error envelope’s shape.
Poll from your code
The following Node.js example creates a generation and reads it until it ends, without a library. It runs on Node.js 18 or later as an ES module. The SDK does the same, with retries, in one call.Find your outputs
Each succeeded output’sasset.id is an asset in your organization’s Library,
in the generation’s project. Your team can open and download it in ZeroGen,
and you can send the asset ID as an input to a later generation. For details,
see Uploads and URL inputs.
Next steps
- Read Models to find a model and the request schema it accepts.
- Read Billing to understand
quotedMicroUsd, holds, and charges. - Read Idempotency before you retry requests in production.