Mọi yêu cầu gửi đến https://jenvid.com. Gửi khóa API JenVid dưới dạng bearer token. POST https://jenvid.com/v1/media/generate · Authorization: Bearer $JENVID_API_KEY · Quyền cần thiết: generate, read, assets
Gửi yêu cầu tới POST /v1/media/generate. Máy chủ trả về 202 kèm task_id. Hãy poll GET /v1/media/tasks/{task_id} mỗi 5 giây cho đến khi is_final là true: lúc đó trạng thái là succeeded, failed hoặc cancelled và chính tác vụ này chứa kết quả (outputs) hoặc lỗi (error_code và error_message). Gửi lại với cùng Idempotency-Key sẽ trả về tác vụ ban đầu. ID và URL trong phản hồi chỉ mang tính minh họa.
# Needs curl and jq.
# 1. Submit. The response is 202 with task_id, state and credits_held.
ID=$(curl -s -X POST "https://jenvid.com/v1/media/generate" \
-H "Authorization: Bearer $JENVID_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"model": "gpt-image-2.6-flare-2k",
"mode": "t2i",
"params": {}
}' | jq -r .task_id)
echo "task: $ID"
# 2. Poll every 5 seconds until is_final is true (state is then succeeded, failed or cancelled).
while true; do
TASK=$(curl -s "https://jenvid.com/v1/media/tasks/$ID" -H "Authorization: Bearer $JENVID_API_KEY")
echo "state: $(echo "$TASK" | jq -r .state)"
[ "$(echo "$TASK" | jq -r .is_final)" = "true" ] && break
sleep 5
done
# 3. The final task carries the result: outputs[].url when succeeded, error_code and error_message when failed.
echo "$TASK" | jq '{state, outputs, error_code, error_message, credits}'
Lỗi dùng mã chữ thường và có retryable cùng request_id. Yêu cầu hủy đang chờ chưa phải là đã hủy: nếu mô hình vẫn hoàn tất, tác vụ vẫn có thể bị tính phí. Xem tài liệu tham chiếu API để biết cách hủy.
API kiểu tài nguyên (thay thế)
POST /v1/generations nhận cùng các giá trị trong inputs (và quote_id tùy chọn) và trả về tài nguyên generation: hãy poll GET /v1/generations/{id} theo id cho đến khi status là succeeded, failed hoặc cancelled, rồi lấy GET /v1/generations/{id}/result. Mã lỗi viết HOA. Tích hợp mới nên ưu tiên media API ở trên; cả hai dùng cùng quy trình và giá.
# Needs curl and jq.
# 1. Submit. The response is 202 with the generation id.
ID=$(curl -s -X POST "https://jenvid.com/v1/generations" \
-H "Authorization: Bearer $JENVID_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"mode": "t2i",
"model": "gpt-image-2.6-flare-2k",
"inputs": {}
}' | jq -r .id)
echo "generation: $ID"
# 2. Poll until the status is succeeded, failed or cancelled.
while true; do
STATUS=$(curl -s "https://jenvid.com/v1/generations/$ID" -H "Authorization: Bearer $JENVID_API_KEY" | jq -r .status)
echo "status: $STATUS"
case "$STATUS" in succeeded|failed|cancelled) break ;; esac
sleep 2
done
# 3. Fetch the result (only available once the status is succeeded).
curl -s "https://jenvid.com/v1/generations/$ID/result" -H "Authorization: Bearer $JENVID_API_KEY"