curl
curl "https://sharemy.ai/v1/jobs/$JOB_ID" \
-H "Authorization: Bearer $SHAREMYAI_API_KEY"import os
import httpx
url = f"https://sharemy.ai/v1/jobs/{os.environ['JOB_ID']}"
response = httpx.get(url, headers={"Authorization": "Bearer " + os.environ["SHAREMYAI_API_KEY"]})
response.raise_for_status()
print(response.json()["status"])const url = `https://sharemy.ai/v1/jobs/${process.env.JOB_ID}`;
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.SHAREMYAI_API_KEY}` },
});
const job = await response.json();
if (!response.ok) throw new Error(job.error.message);
console.log(job.status);{
"id": "<string>",
"object": "job",
"created": 123,
"endpoint": "/v1/images/generations",
"status": "queued",
"completed_at": 123,
"result": {
"created": 123,
"data": [
{
"b64_json": "<string>",
"revised_prompt": null,
"seed": 123
}
]
},
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "Send your API token as Authorization: Bearer smai_…. Create one at https://sharemy.ai, account panel, API tokens.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}{
"error": {
"message": "This account is suspended. If you think that is a mistake, contact us.",
"type": "invalid_request_error",
"param": null,
"code": "account_suspended"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}API reference
Image jobs
Run an image edit or generation in the background. Poll for the pictures or cancel unfinished work.
GET
/
v1
/
jobs
/
{id}
curl
curl "https://sharemy.ai/v1/jobs/$JOB_ID" \
-H "Authorization: Bearer $SHAREMYAI_API_KEY"import os
import httpx
url = f"https://sharemy.ai/v1/jobs/{os.environ['JOB_ID']}"
response = httpx.get(url, headers={"Authorization": "Bearer " + os.environ["SHAREMYAI_API_KEY"]})
response.raise_for_status()
print(response.json()["status"])const url = `https://sharemy.ai/v1/jobs/${process.env.JOB_ID}`;
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.SHAREMYAI_API_KEY}` },
});
const job = await response.json();
if (!response.ok) throw new Error(job.error.message);
console.log(job.status);{
"id": "<string>",
"object": "job",
"created": 123,
"endpoint": "/v1/images/generations",
"status": "queued",
"completed_at": 123,
"result": {
"created": 123,
"data": [
{
"b64_json": "<string>",
"revised_prompt": null,
"seed": 123
}
]
},
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "Send your API token as Authorization: Bearer smai_…. Create one at https://sharemy.ai, account panel, API tokens.",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}{
"error": {
"message": "This account is suspended. If you think that is a mistake, contact us.",
"type": "invalid_request_error",
"param": null,
"code": "account_suspended"
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}{
"error": {
"message": "<string>",
"type": "invalid_request_error",
"param": "<string>",
"code": "model_not_found",
"price_credits": 123,
"balance_credits": 123
}
}Send
You can disconnect after submission. The job keeps one of your account’s four concurrent slots until it finishes. You can poll and cancel even when all four slots are in use. If result storage is unavailable at submission, you get
Finished jobs include
If the job is unfinished, you get HTTP 200 with
Prefer: respond-async with an edit or a generation. You can also set the async field. Use "async": true in JSON or -F async=true in a multipart form. The JSON string "true" also works. Generations accept JSON or multipart fields. Edits take multipart uploads.
Start a job
The API checks the request fields before it returns HTTP 202. Save the relative path inLocation. Wait the number of seconds in Retry-After before your first poll.
HTTP/1.1 202 Accepted
Location: /v1/jobs/job_69ba81e5-6a67-4cd5-a28b-2e023337b936
Retry-After: 2
Content-Type: application/json
{"id":"job_69ba81e5-6a67-4cd5-a28b-2e023337b936","object":"job","status":"queued","created":1764547200,"endpoint":"/v1/images/edits"}
503 storage_unavailable.
Poll for the result
SendGET /v1/jobs/{id} with a token from the account that submitted the job. Each successful lookup returns HTTP 200. Read status to decide what to do next.
status | What to do |
|---|---|
queued | Wait for a machine. Read Retry-After (2 seconds) before polling again. |
running | A machine has the job. Wait for Retry-After before polling again. A job can return to queued if it needs another machine. |
succeeded | Read result. It has the same created and data shape as the synchronous endpoint. Decode each result.data[].b64_json to get a PNG. |
failed | Read error.code, error.message, error.type and error.param. A refusal such as no_provider can arrive here after a 202. Any held credits are refunded. |
cancelled | Stop polling. The job was cancelled and its hold refunded. |
completed_at. Both timestamps use Unix seconds. A successful job lookup with a result includes the cost and balance headers from the job’s quote. A network restart marks unfinished jobs failed with error.code set to interrupted. You can submit a new request. You aren’t charged for the interrupted job.
Polling example
These examples submit one generation, wait for eachRetry-After, and save the finished PNG. Use the same loop with the Location from an edit.
set -eo pipefail
origin=https://sharemy.ai
auth="Authorization: Bearer $SHAREMYAI_API_KEY"
headers=$(mktemp)
body=$(mktemp)
trap 'rm -f "$headers" "$body"' EXIT
header() {
awk -v name="$1:" 'tolower($1) == name { sub(/\r$/, "", $2); print $2 }' "$headers"
}
curl -fsS -D "$headers" -o "$body" "$origin/v1/images/generations" \
-H "$auth" -H 'Prefer: respond-async' -H 'Content-Type: application/json' \
-d '{"model":"flux2-klein","prompt":"A lighthouse at dusk"}'
url="$origin$(header location)"
while true; do
sleep "$(header retry-after)"
curl -fsS -D "$headers" -o "$body" -H "$auth" "$url"
case "$(jq -r '.status' "$body")" in
queued|running) continue ;;
succeeded) jq -er '.result.data[0].b64_json' "$body" | base64 --decode > lighthouse.png; break ;;
*) jq -c '{status, error}' "$body" >&2; exit 1 ;;
esac
done
import base64, os, time
from pathlib import Path
import httpx
from openai import OpenAI
key = os.environ["SHAREMYAI_API_KEY"]
origin = "https://sharemy.ai"
client = OpenAI(api_key=key, base_url=origin + "/v1")
receipt = client.images.with_raw_response.generate(
model="flux2-klein",
prompt="A lighthouse at dusk",
extra_headers={"Prefer": "respond-async"},
)
url = origin + receipt.headers["Location"]
delay = int(receipt.headers["Retry-After"])
with httpx.Client(headers={"Authorization": f"Bearer {key}"}) as http:
while True:
time.sleep(delay)
response = http.get(url)
response.raise_for_status()
job = response.json()
if job["status"] in ("queued", "running"):
delay = int(response.headers["Retry-After"])
continue
if job["status"] != "succeeded":
raise RuntimeError(job.get("error", job["status"]))
png = job["result"]["data"][0]["b64_json"]
Path("lighthouse.png").write_bytes(base64.b64decode(png))
break
import fs from "node:fs";
import { setTimeout as sleep } from "node:timers/promises";
import OpenAI from "openai";
const apiKey = process.env.SHAREMYAI_API_KEY;
const origin = "https://sharemy.ai";
const client = new OpenAI({ apiKey, baseURL: origin + "/v1" });
const receipt = await client.images.generate(
{ model: "flux2-klein", prompt: "A lighthouse at dusk" },
{ headers: { Prefer: "respond-async" } },
).asResponse();
const url = new URL(receipt.headers.get("Location"), origin);
let delay = Number(receipt.headers.get("Retry-After"));
while (true) {
await sleep(delay * 1000);
const response = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` } });
const job = await response.json();
if (!response.ok) throw new Error(job.error.message);
if (["queued", "running"].includes(job.status)) {
delay = Number(response.headers.get("Retry-After"));
continue;
}
if (job.status !== "succeeded") throw new Error(job.error?.message ?? job.status);
fs.writeFileSync("lighthouse.png", Buffer.from(job.result.data[0].b64_json, "base64"));
break;
}
Cancel a job
SendPOST /v1/jobs/{id}/cancel with the same account’s token. You can leave the body empty.
curl -X POST "https://sharemy.ai/v1/jobs/$JOB_ID/cancel" \
-H "Authorization: Bearer $SHAREMYAI_API_KEY"
status: "cancelled" and the full hold goes back to your balance. If it has already finished, you get its current state. Cancelling a successful job returns its result and leaves the charge in place.
Ownership and expiry
You have one hour fromcompleted_at to retrieve a finished job. After that, polling or cancelling returns 404 job_expired to your account. An unknown id or another account’s id returns 404 not_found, even if that job has expired. Both errors name id in error.param.Authorizations
Response
The current state. Check status even on HTTP 200. A successful job includes result and a failed job includes error.