SciFig

API reference

Image edits

Edit an image by instruction or region, replace its background, change its aspect ratio, recolor it, or replace its text.

Operations#

POST /images/edits with a JSON body. Required scope: figures:generate. image is a file_id (an upload or an earlier output); operation selects the edit and defaults to instruct. The same tools are on the website’s result toolbar.

operationWhat it doesFieldsCredits
instructEdits the whole image as instructed; with a mask, redraws only the masked regioninstruction (1–2,000 characters), optional mask, quality50 / 75 / 100 by quality; with a mask 100
white_backgroundReplaces the background with solid white (not transparency)quality50 / 75 / 100
aspect_ratioReframes the whole figure to a new ratio, extending the backgroundaspect_ratio (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9), quality50 / 75 / 100
recolorApplies a palette to the artwork, keeping label coloursoptional palette (1–8 #RRGGBB; without it a palette is chosen), quality50 / 75 / 100
replace_textChanges text labels in place, keeping font and positiontext_detection, replacements100

A mask is a PNG uploaded with purpose mask, the same size as the image, white where the image may change. A region edit always uses the premium model, whatever quality says. replace_text does not take quality: it always uses the text-editing model and is priced at the premium level.

Replacing text#

  • Call POST /images/text-detections on the same image. It is free and returns an id and the texts with their index.
  • Send operation: "replace_text", text_detection: <id> and replacements: [{"index": 0, "text": "Figure 1"}]. Texts you do not list stay as they are.
  • An index the detection does not have returns 400 INVALID_REQUEST with details.reason = TEXT_INDEX_OUT_OF_RANGE and charges nothing.

Credits#

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 for its fields and statuses. Errors are listed under Errors.

cURL#

curl -X POST https://scifig.ai/api/v1/images/edits \
  -H "Authorization: Bearer $SCIFIG_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Prefer: wait=25" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "<file_id>",
    "operation": "aspect_ratio",
    "aspect_ratio": "16:9"
  }'

JavaScript#

const response = await fetch('https://scifig.ai/api/v1/images/edits', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
    'Idempotency-Key': crypto.randomUUID(),
    Prefer: 'wait=25',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "image": "<file_id>",
    "operation": "aspect_ratio",
    "aspect_ratio": "16:9"
  }),
});
const result = await response.json();
console.log(response.status, result);

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/edits",
    headers=headers,
    json={
        "image": "<file_id>",
        "operation": "aspect_ratio",
        "aspect_ratio": "16:9"
    },
    timeout=60,
)
print(response.status_code, response.json())