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
runs:createandruns:readscopes, andlibrary:readto download the outputs. 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 run
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 run 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. If any check
fails, nothing is held and no run starts.
POST /v1/runs. The Prefer: wait=60
header holds the response for up to 60 seconds while the run is in
progress. The Idempotency-Key header makes the request safe to retry; use
a new key for each new run.- If the run ends within the wait, the response is
200. - Otherwise, the response is
202with the run’s current state.
Location header gives the run’s path, such as
/v1/runs/0b7f2c1e-5d4a-4c3b-9a8f-7e6d5c4b3a21.3
Read the run until it ends
Read the run by its ID. Add A read only reads the run’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 run ends or the wait runs out.Run statuses
A run 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 run and reads it until it ends, without a library. It runs on Node.js 18 or later as an ES module. The SDKs do the same, with retries, in one call.Download your outputs
Each succeeded output’sasset.id is an asset in your organization’s Library,
in the run’s project, where your team can also open it in ZeroGen. To fetch the
file on your server, read the asset’s download with a key that has the
library:read scope:
url downloads the original file until expiresAt.
Request it without your API key, because the storage service refuses a request
that also sends an Authorization header. With the url in DOWNLOAD_URL:
url can download the file until it expires, so keep it out
of logs. To download again later, read the asset’s download again for a new
url.
To show an output without downloading it, use the URLs in its
asset.preview; see Previews.
You can also send the asset ID as an input to a later run. For details, see
Uploads and URL inputs.
Next steps
- Read Models in the API 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.