# Creación y edición de diagramas de flujo

Dibuja diagramas de flujo científicos y de trabajo en SVG y luego modifícalos con instrucciones adicionales.

Fuente: https://scifig.ai/es/docs/api/flowcharts

## Cuerpo JSON

`POST /flowcharts/generations`. Ámbito requerido: `figures:generate`.

| Campo | Tipo | Obligatorio | Valor predeterminado | Reglas |
| --- | --- | --- | --- | --- |
| prompt | string | sí | — | 1–8000 caracteres |
| aspect_ratio | string | no | `auto` | `auto`, `16:9`, `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `21:9` |
| attachment_file_ids | array | no | — | Hasta 8 archivos subidos con la finalidad `flowchart_attachment`, por ejemplo un protocolo o un borrador |

100 créditos. Una tarea completada tiene un resultado SVG con texto editable y un `editor_url` que lo abre en su conversación FlowChart en el sitio web. Exporta a PNG, PDF, TIFF o PPTX con una [conversión](/es/docs/api/image-conversions) gratuita.

Primero se suben los archivos adjuntos mediante `POST /files` con la finalidad `flowchart_attachment`; cuentan para los límites de subida del sitio web y pueden usarse durante 24 horas.

## Ediciones

`POST /flowcharts/edits` con JSON `{"job": "<flowchart job id>", "instruction": "..."}` modifica el diagrama de flujo generado por la tarea y conserva su relación de aspecto. `instruction` tiene 1–8000 caracteres. 100 créditos. Se aplican las reglas de [edición de gráficos](/es/docs/api/charts): una tarea principal en ejecución devuelve un `409 REVISION_CONFLICT` que permite reintentar con `PARENT_JOB_RUNNING`; si ha fallado, devuelve `400 INVALID_REQUEST` con `JOB_NOT_SUCCEEDED`. Solo se puede editar la última versión; en otro caso, `409 REVISION_CONFLICT` con `NOT_LATEST_REVISION`. Solo se ejecuta una edición a la vez; en otro caso, `EDIT_IN_PROGRESS`. El resultado aparece en la misma conversación FlowChart del sitio web.

## cURL

```bash
curl -X POST https://scifig.ai/api/v1/flowcharts/generations \
  -H "Authorization: Bearer $SCIFIG_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Prefer: wait=25" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
    "aspect_ratio": "4:3"
  }'
```

## JavaScript

```javascript
const response = await fetch('https://scifig.ai/api/v1/flowcharts/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": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
    "aspect_ratio": "4:3"
  }),
});
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/flowcharts/generations",
    headers=headers,
    json={
        "prompt": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
        "aspect_ratio": "4:3"
    },
    timeout=60,
)
print(response.status_code, response.json())
```
