# Generazione di immagini

Genera un’illustrazione scientifica da una descrizione testuale, eventualmente guidata da immagini di riferimento.

Fonte: https://scifig.ai/it/docs/api/image-generations

## Corpo JSON

`POST /images/generations` con un corpo JSON. Ambito richiesto: `figures:generate`.

| Campo | Tipo | Obbligatorio | Valore predefinito | Regole |
| --- | --- | --- | --- | --- |
| prompt | string | sì | — | 3–20.000 caratteri |
| 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` o `premium`; determina modello e prezzo |
| style | string | no | — | `flat`, `2-5d`, `line-art`, `hand-drawn`, `scientific`, `line`, `3d`, `editorial`, `sketch`, `watercolor`, `auto` |
| palette | stringa o array | no | — | Identificativo di una palette predefinita o 1–4 colori `#RRGGBB` |
| reference_file_ids | array | no | — | 1–3 `file_id` di immagini, da caricamenti o risultati precedenti |

I campi sconosciuti vengono rifiutati con `400 INVALID_REQUEST`; `details.issues` indica ogni problema. Alcuni modelli, immagini di riferimento e proporzioni richiedono un piano a pagamento; in quel caso viene restituito `403 PLAN_REQUIRED`.

## Crediti

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

I crediti vengono riservati alla creazione del processo, addebitati una sola volta se riesce e restituiti integralmente se fallisce. La risposta è un processo; consulta [Processi e attesa limitata](/it/docs/api/jobs) per i campi e gli stati. Gli errori sono elencati in [Errori](/it/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())
```
