# Create a generation

One request starts the job and, with wait, returns the finished result.

`POST /v1/generations` answers `202` with the job. Add `?wait=60` and the request stays open until the job finishes (up to 60 seconds), then answers `200` with the result.

curl:

```sh
curl "https://api.opengrid.one/v1/generations?wait=60" \
  -H "Authorization: Bearer $OPENGRID_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "nano-banana-pro",
  "variant": "2k",
  "quantity": 1,
  "input": {
    "prompt": "A paper boat drifting down a rain gutter, golden hour",
    "aspect_ratio": "16:9"
  }
}'
```

Python:

```python
import os, uuid, requests

api = "https://api.opengrid.one/v1"
headers = {"Authorization": f"Bearer {os.environ['OPENGRID_API_KEY']}"}

# Start the job and wait for it. You are charged only if it succeeds.
job = requests.post(
    f"{api}/generations?wait=60",
    headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
    json={
        "model": "nano-banana-pro",
        "variant": "2k",
        "quantity": 1,
        "input": {
            "prompt": "A paper boat drifting down a rain gutter, golden hour",
            "aspect_ratio": "16:9"
        }
    },
).json()

# A long video can outlast one request: keep waiting on the same job.
while job["status"] in ("queued", "running"):
    job = requests.get(f"{api}/generations/{job['id']}?wait=60", headers=headers).json()

print(job["status"], job["outputs"], job["charged_usd"])
```

JavaScript:

```js
const api = "https://api.opengrid.one/v1";
const headers = {
  Authorization: `Bearer ${process.env.OPENGRID_API_KEY}`,
  "Content-Type": "application/json",
};

// Start the job and wait for it. You are charged only if it succeeds.
let job = await fetch(`${api}/generations?wait=60`, {
  method: "POST",
  headers: { ...headers, "Idempotency-Key": crypto.randomUUID() },
  body: JSON.stringify({
    "model": "nano-banana-pro",
    "variant": "2k",
    "quantity": 1,
    "input": {
      "prompt": "A paper boat drifting down a rain gutter, golden hour",
      "aspect_ratio": "16:9"
    }
  }),
}).then((r) => r.json());

// A long video can outlast one request: keep waiting on the same job.
while (job.status === "queued" || job.status === "running") {
  job = await fetch(`${api}/generations/${job.id}?wait=60`, { headers }).then((r) => r.json());
}

console.log(job.status, job.outputs?.[0]?.url, job.charged_usd);
```

## Body

| Field | Required | Meaning |
|---|---|---|
| `model` | Yes | A model id from the catalog. |
| `variant` | If more than one | A variant id such as `720p`. |
| `quantity` | Depends on the unit | Seconds, images or runs, within the model's range. Leave out for `per_1k_chars`. |
| `input` | Yes | The model's own fields, such as `prompt` and `aspect_ratio`. |
| `routing` | No | `balanced` (default), `cheapest` or `fastest`. See [Routing](https://opengrid.one/docs/routing). |
| `fallback` | No | Default `true`. `false` runs on one provider only and refunds on failure. |
| `own_key_fallback` | No | Default `true`. If you have stored your own provider key in Settings, a job runs on your key at no charge from OpenGrid: first when the provider reports enough credits on your account for the run, otherwise as a last resort after OpenGrid's providers. `false` turns that off for this request. With your own Higgsfield or World Labs key stored, `model` can also name one of their endpoints directly, as `higgsfield/<endpoint>` or `worldlabs/<task>`: `input` is sent to the provider as written, and the run is on your key alone. |
| `max_price_usd` | No | A cap. Providers that would cost more are never used. |

## Headers

| Header | Required | Meaning |
|---|---|---|
| `Authorization` | Yes | `Bearer og_live_...` |
| `Content-Type` | Yes | `application/json` |
| `Idempotency-Key` | Recommended | 8 to 100 characters. Makes a retry safe. See [Idempotency](https://opengrid.one/docs/idempotency). |

## Query

| Parameter | Meaning |
|---|---|
| `wait` | 0 to 60. Seconds to hold the request open while the job is unfinished. Default 0. |

## What happens when you submit

1. The request is priced on every provider that can take your exact input, and a plan of up to three providers is built.
2. `max_usd`, the highest price in that plan, is held from your balance.
3. The job runs on the first provider. If it fails, the job moves to the next.
4. On success you are charged the price of the provider that finished it, and the rest of the hold is returned. On failure the whole hold is returned.

202 Accepted:

```json
{
  "id": "5b0e7c1e-6f0e-4a55-9d9b-3f2a8f1c2d10",
  "model": "nano-banana-pro",
  "variant": "2k",
  "quantity": 1,
  "unit": "per_image",
  "routing": "balanced",
  "status": "running",
  "charged_usd": 0.1575,
  "estimated_usd": 0.141225,
  "max_usd": 0.1575,
  "currency": "USD",
  "attempts": 1,
  "outputs": null,
  "available_until": null,
  "error": null,
  "created_at": "2026-11-24T18:03:11.412Z",
  "finished_at": null
}
```

Source: https://opengrid.one/docs/generations
