# Image generations

Generate a scientific illustration from a text prompt, optionally guided by reference images.

Source: https://scifig.ai/docs/api/image-generations

## JSON body

`POST /images/generations` with a JSON body. Required scope: `figures:generate`.

| Field | Type | Required | Default | Rules |
| --- | --- | --- | --- | --- |
| prompt | string | yes | — | 3–20,000 characters |
| aspect_ratio | string | no | `1:1` | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9` |
| quality | string | no | `standard` | `standard`, `advanced` or `premium`; sets the model and the price |
| style | string | no | — | `flat`, `2-5d`, `line-art`, `hand-drawn`, `scientific`, `line`, `3d`, `editorial`, `sketch`, `watercolor`, `auto` |
| palette | string or array | no | — | A palette preset id, or 1–4 `#RRGGBB` colours |
| reference_file_ids | array | no | — | 1–3 image `file_id`s (uploads or earlier outputs) |

Unknown fields are rejected with `400 INVALID_REQUEST`; `details.issues` names each problem. Some models, reference images and ratios need a paid plan, which returns `403 PLAN_REQUIRED`.

## Credits

| quality | Credits |
| --- | --- |
| standard | 50 |
| advanced | 75 |
| premium | 100 |

Credits are reserved when the job is created, charged once when it succeeds and returned in full when it fails. The response is a job; see [Jobs and bounded waiting](/docs/api/jobs) for its fields and statuses. Errors are listed under [Errors](/docs/api/errors).

## cURL

```bash
curl -X POST https://scifig.ai/api/v1/images/generations \
  -H "Authorization: Bearer $SCIFIG_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Prefer: wait=25" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Schematic of CRISPR-Cas9 gene editing: guide RNA, Cas9, target DNA and the double-strand break, labelled",
    "aspect_ratio": "4:3",
    "quality": "standard"
  }'
```

## JavaScript

```javascript
const response = await fetch('https://scifig.ai/api/v1/images/generations', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
    'Idempotency-Key': crypto.randomUUID(),
    Prefer: 'wait=25',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "prompt": "Schematic of CRISPR-Cas9 gene editing: guide RNA, Cas9, target DNA and the double-strand break, labelled",
    "aspect_ratio": "4:3",
    "quality": "standard"
  }),
});
const result = await response.json();
console.log(response.status, result);
```

## Python

```python
import os
import uuid

import requests

headers = {
    "Authorization": f"Bearer {os.environ['SCIFIG_API_KEY']}",
    "Idempotency-Key": str(uuid.uuid4()),
    "Prefer": "wait=25",
}
response = requests.post(
    "https://scifig.ai/api/v1/images/generations",
    headers=headers,
    json={
        "prompt": "Schematic of CRISPR-Cas9 gene editing: guide RNA, Cas9, target DNA and the double-strand break, labelled",
        "aspect_ratio": "4:3",
        "quality": "standard"
    },
    timeout=60,
)
print(response.status_code, response.json())
```
