Skip to content

Examples

Common API workflows with complete code examples.


Authentication

Login and Get Token

curl -X POST https://api.sartiq.com/api/v1/login/access-token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=your@email.com&password=yourpassword"
import httpx

response = httpx.post(
    "https://api.sartiq.com/api/v1/login/access-token",
    data={"username": "your@email.com", "password": "yourpassword"}
)
token = response.json()["access_token"]
const response = await fetch(
  "https://api.sartiq.com/api/v1/login/access-token",
  {
    method: "POST",
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
    body: new URLSearchParams({
      username: "your@email.com",
      password: "yourpassword",
    }),
  }
);
const { access_token } = await response.json();

Products

List Products

curl https://api.sartiq.com/api/v1/products/ \
  -H "Authorization: Bearer $TOKEN"

Response:

{
  "items": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "name": "Summer Dress",
      "sku": "DRS-001",
      "category": "dresses",
      "images": [
        {"url": "https://...", "type": "primary"}
      ]
    }
  ],
  "total": 1,
  "page": 1,
  "size": 20
}

Create Product

curl -X POST https://api.sartiq.com/api/v1/products/ \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Summer Dress",
    "sku": "DRS-001",
    "category": "dresses"
  }'

Upload Product Image

curl -X POST https://api.sartiq.com/api/v1/products/{product_id}/images \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@product.jpg" \
  -F "type=primary"

Shootings

Create a Shooting

curl -X POST https://api.sartiq.com/api/v1/shootings/ \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Summer Collection 2024",
    "brand_id": "brand-uuid"
  }'

Add a Look to Shooting

curl -X POST https://api.sartiq.com/api/v1/shootings/{shooting_id}/looks \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "main_product_id": "product-uuid",
    "subject_id": "subject-uuid",
    "style_id": "style-uuid",
    "shot_type_ids": ["shot-type-uuid-1", "shot-type-uuid-2"]
  }'

Generations

Trigger Generation for a Shot

curl -X POST https://api.sartiq.com/api/v1/shots/{shot_id}/generate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model_id": "model-uuid",
    "num_predictions": 4
  }'

Check Generation Status

curl https://api.sartiq.com/api/v1/generations/{generation_id} \
  -H "Authorization: Bearer $TOKEN"

Response (completed):

{
  "id": "generation-uuid",
  "status": "completed",
  "predictions": [
    {
      "id": "pred-1",
      "image_url": "https://storage.sartiq.com/predictions/..."
    },
    {
      "id": "pred-2",
      "image_url": "https://storage.sartiq.com/predictions/..."
    }
  ],
  "completed_at": "2024-01-15T10:35:00Z"
}

Approve a Prediction

curl -X POST https://api.sartiq.com/api/v1/shots/{shot_id}/approve \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "prediction_id": "pred-1"
  }'

Complete Workflow Example

End-to-end example: create a shooting, add a look, generate images.

import httpx

BASE_URL = "https://api.sartiq.com/api/v1"

# 1. Authenticate
auth = httpx.post(f"{BASE_URL}/login/access-token", data={
    "username": "your@email.com",
    "password": "yourpassword"
})
token = auth.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}

# 2. Create shooting
shooting = httpx.post(f"{BASE_URL}/shootings/", headers=headers, json={
    "name": "Summer Collection",
    "brand_id": "your-brand-id"
}).json()

# 3. Add a look
look = httpx.post(
    f"{BASE_URL}/shootings/{shooting['id']}/looks",
    headers=headers,
    json={
        "main_product_id": "product-id",
        "subject_id": "subject-id",
        "style_id": "style-id",
        "shot_type_ids": ["full-body-id", "half-body-id"]
    }
).json()

# 4. Generate images for each shot
for shot in look["shots"]:
    generation = httpx.post(
        f"{BASE_URL}/shots/{shot['id']}/generate",
        headers=headers,
        json={"num_predictions": 4}
    ).json()
    print(f"Generation started: {generation['id']}")

# 5. Poll for completion (simplified)
import time
for shot in look["shots"]:
    while True:
        status = httpx.get(
            f"{BASE_URL}/shots/{shot['id']}",
            headers=headers
        ).json()
        if status["status"] in ["review", "approved"]:
            print(f"Shot ready: {status['current_image_url']}")
            break
        time.sleep(5)
const BASE_URL = "https://api.sartiq.com/api/v1";

// 1. Authenticate
const authRes = await fetch(`${BASE_URL}/login/access-token`, {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    username: "your@email.com",
    password: "yourpassword",
  }),
});
const { access_token } = await authRes.json();
const headers = {
  Authorization: `Bearer ${access_token}`,
  "Content-Type": "application/json",
};

// 2. Create shooting
const shootingRes = await fetch(`${BASE_URL}/shootings/`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    name: "Summer Collection",
    brand_id: "your-brand-id",
  }),
});
const shooting = await shootingRes.json();

// 3. Add a look
const lookRes = await fetch(
  `${BASE_URL}/shootings/${shooting.id}/looks`,
  {
    method: "POST",
    headers,
    body: JSON.stringify({
      main_product_id: "product-id",
      subject_id: "subject-id",
      style_id: "style-id",
      shot_type_ids: ["full-body-id", "half-body-id"],
    }),
  }
);
const look = await lookRes.json();

// 4. Generate images
for (const shot of look.shots) {
  await fetch(`${BASE_URL}/shots/${shot.id}/generate`, {
    method: "POST",
    headers,
    body: JSON.stringify({ num_predictions: 4 }),
  });
}

Error Handling

Handle Common Errors

import httpx

try:
    response = httpx.get(
        f"{BASE_URL}/products/{product_id}",
        headers=headers
    )
    response.raise_for_status()
    product = response.json()
except httpx.HTTPStatusError as e:
    if e.response.status_code == 401:
        # Re-authenticate
        pass
    elif e.response.status_code == 404:
        print("Product not found")
    elif e.response.status_code == 422:
        errors = e.response.json()["detail"]
        for error in errors:
            print(f"{error['loc']}: {error['msg']}")
    else:
        raise
const response = await fetch(`${BASE_URL}/products/${productId}`, {
  headers,
});

if (!response.ok) {
  if (response.status === 401) {
    // Re-authenticate
  } else if (response.status === 404) {
    console.log("Product not found");
  } else if (response.status === 422) {
    const { detail } = await response.json();
    detail.forEach((error: any) => {
      console.log(`${error.loc.join(".")}: ${error.msg}`);
    });
  } else {
    throw new Error(`HTTP ${response.status}`);
  }
}