cURL · API Virtual Try-On
API Virtual Try-On dengan cURL
Cara tercepat untuk memahami API apa pun adalah memanggilnya dari shell. Dokumentasi Photta dirancang mengutamakan cURL — semua yang ada di halaman ini berjalan di satu terminal, tidak perlu Node atau Python.
Dalam satu kalimat
Ekspor `PHOTTA_API_KEY`, POST ke `https://ai.photta.app/api/v1/tryon/apparel` dengan JSON body yang tepat, ambil ID generasi, lalu jalankan loop `curl … /tryon/apparel/:id` setiap 3 detik hingga `data.status` menjadi `completed` — biasanya dalam 1.5 hingga 4 menit. Gunakan `jq` untuk mengekstrak URL output dari respons akhir.
Diperbarui · 2026-04-19
Request pertama Anda
# Submit a try-on job. The API returns 202 Accepted + a generation ID.
JOB=$(curl -s -X POST "$PHOTTA_BASE_URL/tryon/apparel" \
-H "$AUTH_HEADER" \
-H "Content-Type: application/json" \
-d '{
"product_type": "dress",
"product_images": ["https://example.com/dress.jpg"],
"mannequin_id": "mnq_athena_ts",
"pose_id": "pose_standing_front",
"resolution": "2K",
"aspect_ratio": "3:4"
}')
ID=$(echo "$JOB" | jq -r '.data.id')
echo "Generation $ID queued"
# Poll every 3 seconds until the job completes (max 6 minutes).
for i in $(seq 1 120); do
RESULT=$(curl -s "$PHOTTA_BASE_URL/tryon/apparel/$ID" -H "$AUTH_HEADER")
STATUS=$(echo "$RESULT" | jq -r '.data.status')
if [ "$STATUS" = "completed" ]; then
echo "$RESULT" | jq -r '.data.output_url'
break
fi
if [ "$STATUS" = "failed" ]; then
echo "$RESULT" | jq -r '.data.error_message' >&2
exit 1
fi
sleep 3
doneApa yang diharapkan
Typical completion
1–3min
2K / 4K credits
4 / 6
Styles
2
Batch-ready
yes
Cara kerja
API Virtual Try-On dengan cURL
Lima langkah shell, nol dependensi selain curl dan jq.
- 01
Langkah 1
Daftar dan buat key
Buka ai.photta.app, buka tab Developers, klik Generate API key. Key live dimulai dengan `photta_live_`.
- 02
Langkah 2
Ekspor key tersebut
Simpan `export PHOTTA_API_KEY="photta_live_xxx"` di profil shell Anda atau file `.envrc` sehingga setiap panggilan curl berikutnya mengambilnya secara otomatis.
- 03
Langkah 3
Tetapkan base URL
`export PHOTTA_BASE_URL="https://ai.photta.app/api/v1"` menjaga perintah curl tetap pendek dan memudahkan penggantian ke URL sandbox saat nanti dirilis.
- 04
Langkah 4
Kirim dan poll
POST ke `$PHOTTA_BASE_URL/tryon/apparel` untuk mendapatkan ID, lalu jalankan loop `curl $PHOTTA_BASE_URL/tryon/apparel/$ID` setiap 3 detik. Pipe respons ke jq untuk mengekstrak `.data.status` dengan bersih.
- 05
Langkah 5
Simpan hasilnya
Saat job selesai, ambil `.data.output_url` dengan jq dan gunakan `curl -o` untuk menyimpan byte-nya ke penyimpanan lokal — siap untuk langkah pipeline berikutnya.
Kode, ujung ke ujung
Copy, paste, done.
Four snippets — install prerequisites, wrap the REST call, submit + poll, then handle the errors that actually happen in production.
# Verify curl is available
curl --version
# Export your API key so the rest of the calls can reference it
export PHOTTA_API_KEY="photta_live_xxxxx"# Pin the base URL in a shell variable so every call is a one-liner.
export PHOTTA_BASE_URL="https://ai.photta.app/api/v1"
# Reusable auth header — every request needs it.
AUTH_HEADER="Authorization: Bearer $PHOTTA_API_KEY"# Submit a try-on job. The API returns 202 Accepted + a generation ID.
JOB=$(curl -s -X POST "$PHOTTA_BASE_URL/tryon/apparel" \
-H "$AUTH_HEADER" \
-H "Content-Type: application/json" \
-d '{
"product_type": "dress",
"product_images": ["https://example.com/dress.jpg"],
"mannequin_id": "mnq_athena_ts",
"pose_id": "pose_standing_front",
"resolution": "2K",
"aspect_ratio": "3:4"
}')
ID=$(echo "$JOB" | jq -r '.data.id')
echo "Generation $ID queued"
# Poll every 3 seconds until the job completes (max 6 minutes).
for i in $(seq 1 120); do
RESULT=$(curl -s "$PHOTTA_BASE_URL/tryon/apparel/$ID" -H "$AUTH_HEADER")
STATUS=$(echo "$RESULT" | jq -r '.data.status')
if [ "$STATUS" = "completed" ]; then
echo "$RESULT" | jq -r '.data.output_url'
break
fi
if [ "$STATUS" = "failed" ]; then
echo "$RESULT" | jq -r '.data.error_message' >&2
exit 1
fi
sleep 3
done# -w pulls out the HTTP status without polluting the JSON body.
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "$PHOTTA_BASE_URL/tryon/apparel" \
-H "$AUTH_HEADER" \
-H "Content-Type: application/json" \
-d '{ "product_type": "dress" }')
BODY=$(echo "$RESPONSE" | sed '$d')
STATUS=$(echo "$RESPONSE" | tail -1)
case "$STATUS" in
200|202)
echo "$BODY" | jq '.data' ;;
402)
echo "Out of credits" ; echo "$BODY" | jq '.error' ;;
429)
RETRY=$(echo "$BODY" | jq -r '.error.retry_after')
echo "Rate limited — retry in ${RETRY}s" ;;
*)
echo "Error $STATUS" ; echo "$BODY" | jq '.error' ;;
esacMengapa pola ini
Mengapa cURL masih menjadi cara tercepat untuk memverifikasi API
- Zero install — cURL ships with every major OS
- Pairs with `jq` for scripted pipelines (CI, cron, bash hooks)
- Ideal for smoke-testing endpoints before wiring them into code
- All code in this page copy-pastes into any POSIX shell
Apa yang tidak bisa dilakukan
Honest caveats
- cURL's polling loop blocks your terminal — move to Node/Python for parallel workers
- No streaming parser for the result; you fetch the final URL when the job is done
- Windows Command Prompt users should run WSL or PowerShell's curl.exe wrapper
Pertanyaan pengembang lainnya
Questions other developers ask
Apakah ada alat CLI Photta?+
Belum ada — tetapi cURL ditambah wrapper bash lima belas baris sudah cukup mumpuni. Dokumentasi memprioritaskan contoh cURL karena setiap bahasa dapat menjalankan subprocess, dan shell adalah standar umum di pipeline CI.
Apakah saya butuh jq untuk menggunakan API?+
Tidak wajib — tetapi pipeline skrip jauh lebih mudah dengannya. jq memungkinkan Anda mengambil `.data.id`, `.data.status`, dan `.data.output_url` dari respons JSON tanpa harus mem-parsing-nya secara manual. Instal dengan `brew install jq` di macOS atau `apt install jq` di Debian/Ubuntu.
Bagaimana cara autentikasi dengan curl?+
Tambahkan `-H "Authorization: Bearer $PHOTTA_API_KEY"` pada setiap request. Simpan key di variabel lingkungan, jangan pernah tulis langsung di skrip yang Anda commit. `curl --oauth2-bearer` juga berfungsi tetapi bentuk header eksplisit lebih jelas di dokumentasi dan log.
Bisakah saya menggunakan skrip berbasis curl di produksi?+
Untuk backfill batch sekali jalan dan cron job, ya — ribuan tim melakukan backfill katalog dengan cara ini. Untuk aplikasi jangka panjang, bahasa pemrograman sungguhan biasanya lebih baik karena penanganan error, retry, dan observabilitas yang lebih mumpuni. Contoh curl di halaman ini tetap akurat bahkan setelah Anda beralih ke Node atau Python; struktur request-nya sama.
Bagaimana cara polling dari loop bash?+
Gunakan `for i in $(seq 1 120); do … ; sleep 3; done` dengan pengecekan status di dalam body loop. Keluar dari loop saat `.data.status` bernilai `completed` atau `failed`. Contoh kode di halaman ini menunjukkan pola yang tepat, termasuk batas atas yang ketat agar job macet tidak menggantung skrip selamanya.
Bagaimana cara membaca respons error di curl?+
Gunakan `curl -w "\n%{http_code}"` untuk menangkap HTTP status code bersama body JSON. Cabangkan berdasarkan status: 402 untuk kredit tidak mencukupi, 429 untuk rate limit (ikuti nilai Retry-After), 5xx untuk error server sementara. Body error selalu memiliki field `error.code` dan `error.message`.
cURL · API Virtual Try-On
Buat akun dan dapatkan API key
Ekspor `PHOTTA_API_KEY`, POST ke `https://ai.photta.app/api/v1/tryon/apparel` dengan JSON body yang tepat, ambil ID generasi, lalu jalankan loop `curl … /tryon/apparel/:id` setiap 3 detik hingga `data.status` menjadi `completed` — biasanya dalam 1.5 hingga 4 menit. Gunakan `jq` untuk mengekstrak URL output dari respons akhir.