API reference
Text detections
Find the text labels in an image before changing them with a replace_text edit.
Request and response#
POST /images/text-detections with {"image": "<file_id>"} and an Idempotency-Key. Required scope: figures:generate. Free. It answers synchronously with 200:
{
"id": "c222cd46-d923-4abf-aa28-cdc72ad06623",
"object": "text_detection",
"width": 2048,
"height": 1536,
"texts": [
{ "index": 0, "text": "Nucleus", "corners": [{ "x": 75, "y": 260 }, { "x": 241, "y": 260 }, { "x": 241, "y": 295 }, { "x": 75, "y": 295 }] }
]
}textsare in reading order;cornersare pixel coordinates of each label in the image.- Replaying the same key returns the same detection without running it again; the same key with another image returns
409 IDEMPOTENCY_CONFLICT. - Detections share the website’s limit of 20 per 15 minutes per account; beyond it the answer is
429 RATE_LIMITED. - Pass the
idwith the same image to areplace_textedit. It only works for that image and your account. - The image is a PNG, JPEG or WebP
file_id. A temporary failure of the text recognizer returns503 SERVICE_UNAVAILABLEwithRetry-After: retry with the same key. A detection that ran but produced no result returns502 TASK_FAILED(TEXT_DETECTION_FAILED): send it again with a new key.
cURL#
curl -X POST https://scifig.ai/api/v1/images/text-detections \
-H "Authorization: Bearer $SCIFIG_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=25" \
-H "Content-Type: application/json" \
-d '{
"image": "<file_id>"
}'JavaScript#
const response = await fetch('https://scifig.ai/api/v1/images/text-detections', {
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>"
}),
});
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/text-detections",
headers=headers,
json={
"image": "<file_id>"
},
timeout=60,
)
print(response.status_code, response.json())