# 이미지 생성

텍스트 프롬프트로 과학 그림을 생성하며, 참조 이미지를 선택적으로 사용할 수 있습니다.

출처: https://scifig.ai/ko/docs/api/image-generations

## JSON 본문

JSON 본문을 포함한 `POST /images/generations`. 필요한 범위: `figures:generate`.

| 필드 | 유형 | 필수 | 기본값 | 규칙 |
| --- | --- | --- | --- | --- |
| prompt | string | 예 | — | 3–20,000자 |
| aspect_ratio | string | 아니요 | `1:1` | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9` |
| quality | string | 아니요 | `standard` | `standard`, `advanced` 또는 `premium`. 모델 및 가격 설정 |
| style | string | 아니요 | — | `flat`, `2-5d`, `line-art`, `hand-drawn`, `scientific`, `line`, `3d`, `editorial`, `sketch`, `watercolor`, `auto` |
| palette | 문자열 또는 배열 | 아니요 | — | 팔레트 사전 설정 ID 또는 1–4개의 `#RRGGBB` 색상 |
| reference_file_ids | array | 아니요 | — | 이미지 `file_id` 1–3개(업로드 또는 이전 결과) |

알 수 없는 필드는 `400 INVALID_REQUEST`로 거부되며 `details.issues`에 각 문제가 표시됩니다. 일부 모델, 참조 이미지 및 화면 비율에는 유료 요금제가 필요하며, 미가입 시 `403 PLAN_REQUIRED`를 반환합니다.

## 크레딧

| quality | 크레딧 |
| --- | --- |
| standard | 50 |
| advanced | 75 |
| premium | 100 |

작업 생성 시 크레딧을 예약하고, 성공 시 한 번만 차감하며, 실패 시 전액 반환합니다. 응답은 작업 객체입니다. 필드와 상태는 [작업 및 대기 시간 제한](/ko/docs/api/jobs)을, 오류는 [오류](/ko/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())
```
