Quickstart: an API key
From nothing to a downloaded image in five commands. With an API key you pay for every call, from your own Nostrad balance, and nobody signs in: use it for your own server, a script, or an app whose users don't have Nostrad accounts.
The other way in is Sign in with Nostrad: each person who uses your app signs in and pays from their own Nostrad balance. Both reach the same models; the documentation compares them.
This needs credit. Step 4 runs a real job and charges your Nostrad balance, so add some first. A job is refused with 402 if your balance can't cover the most it could cost. Each model's price is under Models in the console, and in the list in step 3.
Each step has the command for curl (macOS, Linux, Git Bash) and for PowerShell (Windows). The same steps as one JavaScript file are at the end.
1. Make a key
- Open the developer console and log in with your Nostrad account.
- Create app (or open one), then Services: tick Make images.
- API keys → Create API key: a name, the image service, and a monthly limit. Copy the key from the window that opens: it is shown once.
2. Put it in your shell
Only in your shell or your server's secret store: never in code, a file you share, or a web page.
export NOSTRAD_API_KEY="<paste the key>"
$env:NOSTRAD_API_KEY = "<paste the key>"
$h = @{ Authorization = "Bearer $env:NOSTRAD_API_KEY" }
3. List the models
curl https://gateway.nostrad.ai/v1/models -H "Authorization: Bearer $NOSTRAD_API_KEY"
(Invoke-RestMethod https://gateway.nostrad.ai/v1/models -Headers $h).models | Where-Object available | Select-Object id, label
Each model has an id, its inputs and settings, its price and available. The commands below use stability:stable-diffusion-3.5-large as an example. Put in the id of an image model that shows available: true: it may not be this one, and one that's switched off answers "this model is switched off right now".
4. Run an image job
curl https://gateway.nostrad.ai/v1/jobs -H "Authorization: Bearer $NOSTRAD_API_KEY" -H "content-type: application/json" -d '{"model": "stability:stable-diffusion-3.5-large", "inputs": {"prompt": "a lighthouse at dawn"}}'
$body = @{ model = "stability:stable-diffusion-3.5-large"; inputs = @{ prompt = "a lighthouse at dawn" } } | ConvertTo-Json
$job = try { Invoke-RestMethod https://gateway.nostrad.ai/v1/jobs -Method Post -Headers $h -ContentType "application/json" -Body $body } catch { $_.ErrorDetails.Message | ConvertFrom-Json }
$job
The answer is the job. Its state is done if it finished at once, or queued or processing while it runs. A refusal or a job that fails while it's starting comes with an error status and says why in detail or error: PowerShell treats that status as a failed command, which is why this one has try and catch.
5. Wait for it
Ask again every few seconds until state is done or failed. Use the job_id from the answer.
curl https://gateway.nostrad.ai/v1/jobs/<job_id> -H "Authorization: Bearer $NOSTRAD_API_KEY"
while ($job.state -in "queued", "processing") { Start-Sleep 3; $job = Invoke-RestMethod "https://gateway.nostrad.ai/v1/jobs/$($job.job_id)" -Headers $h }
$job.state
$job.error
A failed job says why in error and costs nothing, unless a content check blocked it: that's charged the listed price, the same as a job that finished. A done job shows what it cost in cost_cents.
6. Download the image
outputs[0].url is a path on the gateway, like /files/job_..._0.png. Fetch it with the same key.
curl https://gateway.nostrad.ai/files/<file name from outputs[0].url> -H "Authorization: Bearer $NOSTRAD_API_KEY" -o lighthouse.png
$name = ($job.outputs[0].url -split "/")[-1]
Invoke-WebRequest "https://gateway.nostrad.ai$($job.outputs[0].url)" -Headers $h -OutFile $name -UseBasicParsing
Save it on your side: a result passes through. It leaves Nostrad 12 hours after Nostrad has finished sending all of it to you (7 days if it never does); Nostrad can't tell whether you saved it, so keep your copy. To keep results in the person's storage instead, see Files and storage.
All of it as one JavaScript file
Save it as quickstart.mjs and run node quickstart.mjs (Node 20 or later) in the shell where NOSTRAD_API_KEY is set.
// quickstart.mjs: list the models, run an image job, wait for it, save the image.
import { writeFile } from "node:fs/promises";
const GATEWAY = "https://gateway.nostrad.ai";
const auth = { authorization: `Bearer ${process.env.NOSTRAD_API_KEY}` };
async function call(path, init = {}) {
const r = await fetch(GATEWAY + path, { ...init, headers: { ...auth, ...init.headers } });
if (!r.ok) {
const answer = await r.json().catch(() => ({}));
throw new Error(`${r.status}: ${answer.detail ?? answer.error ?? r.statusText}`);
}
return r;
}
// 3. List the models.
const { models } = await (await call("/v1/models")).json();
console.log(models.filter((m) => m.available).map((m) => m.id).join("\n"));
// 4. Run an image job.
let job = await (await call("/v1/jobs", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ model: "stability:stable-diffusion-3.5-large", inputs: { prompt: "a lighthouse at dawn" } }),
})).json();
// 5. Wait for it.
while (job.state === "queued" || job.state === "processing") {
await new Promise((done) => setTimeout(done, 3000));
job = await (await call(`/v1/jobs/${job.job_id}`)).json();
}
if (job.state === "failed") throw new Error(job.error);
// 6. Download the image.
const name = job.outputs[0].url.split("/").pop();
await writeFile(name, Buffer.from(await (await call(job.outputs[0].url)).arrayBuffer()));
console.log(`saved ${name}; it cost ${job.cost_cents} cents`);
If something is refused
| Status | Usually |
|---|---|
| 401 | The key is wrong, deleted or expired, or not in the header: check that NOSTRAD_API_KEY is set in this shell, or rotate the key under API keys |
| 402 | Your balance is used up. Add credit at https://accounts.nostrad.ai/account#credit |
403, over_limit | The key's monthly limit is reached; the words end with what is used and when it resets. Raise the key's limit under API keys |
| 403 | The key doesn't have that service, or the model needs Sign in with Nostrad |
| 404 | A model id or job id that isn't there: copy it from the answer |
| 429 | More than about 600 job starts, or 3,000 other requests, a minute for your account, all its keys together: wait retry-after seconds. With concurrent_requests_limit: your account already has as many jobs running as it may; start it again when one ends |
| 502 | "Nostrad error": not your request; nothing was charged. Try again later |
Every status is in the documentation's error table. Next: jobs (cancel, webhooks), files and the library, and API keys (rotate, limits, addresses).