Skip to content

Get started

Quickstart ​

From a key to a finished image over REST. You need a Synesta account and curl.

1. Create a key ​

Open the console, «API keys» and create a key. You accept the API terms and confirm with your password. The key is shown once: copy it right away.

bash
export SYNESTA_API_KEY="syn_live_..."

Keep the key in an environment variable

Do not put the key into code or links. The API reads it only from the Authorization header.

2. Top up the API balance ​

REST is paid from a separate API balance in US dollars, no plan needed. Top up in the console, «Billing»: from $5 to $1000. See Billing and storage.

3. Check access ​

bash
curl https://api.synesta.ai/v1/account \
  -H "Authorization: Bearer $SYNESTA_API_KEY"

The response has the plan, the credit balance, api_balance_usd, the credit price usd_per_credit and the key limits.

4. Pick a model ​

bash
curl "https://api.synesta.ai/v1/models?type=image" \
  -H "Authorization: Bearer $SYNESTA_API_KEY"

The model id goes into the model field. What a model accepts (aspect ratios, resolutions, references) is in capabilities of GET /models/{id}.

5. Get the price ​

bash
curl -X POST https://api.synesta.ai/v1/estimate \
  -H "Authorization: Bearer $SYNESTA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"type":"image","model":"MODEL_ID","prompt":"A lighthouse at dawn"}'

credits is the price in credits, cost_usd is what the API balance will be charged. Nothing is charged now.

6. Start the generation ​

bash
curl -X POST https://api.synesta.ai/v1/generations \
  -H "Authorization: Bearer $SYNESTA_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type":"image","model":"MODEL_ID","prompt":"A lighthouse at dawn","max_credits":20}'

The answer is 202 with the generation in its initial status. max_credits is your price cap: a more expensive run is refused. Idempotency-Key is required, see Idempotency.

7. Fetch the result ​

bash
curl https://api.synesta.ai/v1/generations/GENERATION_ID \
  -H "Authorization: Bearer $SYNESTA_API_KEY"

Repeat until status is done or failed. On done the file links are in outputs[].url. How often to ask: Polling.

The same in JavaScript and Python ​

js
const BASE = 'https://api.synesta.ai/v1';
const headers = { Authorization: `Bearer ${process.env.SYNESTA_API_KEY}` };

const start = await fetch(`${BASE}/generations`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json', 'Idempotency-Key': crypto.randomUUID() },
  body: JSON.stringify({ type: 'image', model: 'MODEL_ID', prompt: 'A lighthouse at dawn', max_credits: 20 }),
});
let { data } = await start.json();

while (data.status !== 'done' && data.status !== 'failed') {
  await new Promise((r) => setTimeout(r, 3000));
  ({ data } = await (await fetch(`${BASE}/generations/${data.id}`, { headers })).json());
}
console.log(data.status, data.outputs.map((o) => o.url));
python
import os, time, uuid, requests

BASE = "https://api.synesta.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['SYNESTA_API_KEY']}"}

res = requests.post(
    f"{BASE}/generations",
    headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
    json={"type": "image", "model": "MODEL_ID", "prompt": "A lighthouse at dawn", "max_credits": 20},
)
data = res.json()["data"]

while data["status"] not in ("done", "failed"):
    time.sleep(3)
    data = requests.get(f"{BASE}/generations/{data['id']}", headers=headers).json()["data"]

print(data["status"], [o["url"] for o in data["outputs"]])

Next ​