@@ -12,6 +12,7 @@ A generation request may be billable and irreversible. Before the `POST` request
1212- text-to-video or image-to-video mode
1313- the exact prompt and, for image-to-video, the first-frame image
1414- every optional request field, including duration and resolution
15+ - the maximum number of five-second status checks
1516- the expected cost shown by the current MiniMax pricing documentation
1617
1718Do not automatically retry the generation ` POST ` . A retry can create and charge for a duplicate task.
@@ -39,6 +40,24 @@ Select a currently supported model from the official API reference immediately b
3940
4041``` bash
4142export MINIMAX_VIDEO_MODEL=" <model ID from the selected region's current API reference>"
43+ export MINIMAX_MAX_POLLS=" <approved positive integer>"
44+
45+ case " ${MINIMAX_API_KEY:- } " in
46+ " " |" <" * ) echo " Set MINIMAX_API_KEY before continuing." >&2 ; exit 1 ;;
47+ esac
48+ case " ${MINIMAX_VIDEO_MODEL:- } " in
49+ " " |" <" * ) echo " Set MINIMAX_VIDEO_MODEL before continuing." >&2 ; exit 1 ;;
50+ esac
51+ case " ${MINIMAX_API_BASE:- } " in
52+ https://api.minimax.io/v1|https://api.minimaxi.com/v1) ;;
53+ * ) echo " Select a documented MINIMAX_API_BASE value." >&2 ; exit 1 ;;
54+ esac
55+ case " ${MINIMAX_MAX_POLLS:- } " in
56+ " " |" <" * |0* |* [!0-9]* )
57+ echo " Set MINIMAX_MAX_POLLS to a positive integer." >&2
58+ exit 1
59+ ;;
60+ esac
4261```
4362
4463## Build the Approved Request
@@ -67,14 +86,21 @@ Show the complete `request.json` to the user and get final confirmation before c
6786## Create the Task
6887
6988``` bash
70- CREATE_RESPONSE=" $( curl -sS -X POST " $MINIMAX_API_BASE /video_generation" \
89+ jq -e ' type == "object"' request.json > /dev/null || exit 1
90+
91+ if ! CREATE_RESPONSE=" $( curl -sS --fail-with-body \
92+ --connect-timeout 10 --max-time 60 \
93+ -X POST " $MINIMAX_API_BASE /video_generation" \
7194 -H " Authorization: Bearer $MINIMAX_API_KEY " \
7295 -H " Content-Type: application/json" \
73- -d @request.json) "
96+ -d @request.json) " ; then
97+ echo " Task creation failed or timed out; do not resubmit automatically." >&2
98+ exit 1
99+ fi
74100
75- echo " $CREATE_RESPONSE " | jq .
76- [ " $( echo " $CREATE_RESPONSE " | jq -r ' .base_resp.status_code' ) " = " 0" ] || exit 1
77- TASK_ID=" $( echo " $CREATE_RESPONSE " | jq -r ' .task_id // empty' ) "
101+ printf ' %s\n ' " $CREATE_RESPONSE " | jq . || exit 1
102+ [ " $( jq -r ' .base_resp.status_code' <<< " $CREATE_RESPONSE " ) " = " 0" ] || exit 1
103+ TASK_ID=" $( jq -r ' .task_id // empty' <<< " $CREATE_RESPONSE " ) "
78104[ -n " $TASK_ID " ] || exit 1
79105```
80106
@@ -85,30 +111,39 @@ Do not repeat this command automatically if the response is interrupted or ambig
85111Poll at five-second intervals until the API returns a terminal status. Stop on unknown statuses instead of guessing.
86112
87113``` bash
88- while true ; do
89- STATUS_RESPONSE=" $( curl -sS -G " $MINIMAX_API_BASE /query/video_generation" \
114+ POLL_COUNT=0
115+ STATUS=" "
116+ while [ " $POLL_COUNT " -lt " $MINIMAX_MAX_POLLS " ]; do
117+ POLL_COUNT=$(( POLL_COUNT + 1 ))
118+ if ! STATUS_RESPONSE=" $( curl -sS --fail-with-body \
119+ --connect-timeout 10 --max-time 60 \
120+ -G " $MINIMAX_API_BASE /query/video_generation" \
90121 -H " Authorization: Bearer $MINIMAX_API_KEY " \
91- --data-urlencode " task_id=$TASK_ID " ) "
122+ --data-urlencode " task_id=$TASK_ID " ) " ; then
123+ echo " Status request failed or timed out." >&2
124+ exit 1
125+ fi
92126
93- [ " $( echo " $STATUS_RESPONSE " | jq -r ' .base_resp.status_code' ) " = " 0" ] || {
94- echo " $STATUS_RESPONSE " | jq .
127+ jq -e . > /dev/null <<< " $STATUS_RESPONSE" || exit 1
128+ [ " $( jq -r ' .base_resp.status_code' <<< " $STATUS_RESPONSE" ) " = " 0" ] || {
129+ printf ' %s\n' " $STATUS_RESPONSE " | jq .
95130 exit 1
96131 }
97132
98- STATUS=" $( echo " $STATUS_RESPONSE " | jq -r ' .status // empty' ) "
133+ STATUS=" $( jq -r ' .status // empty' <<< " $STATUS_RESPONSE " ) "
99134 echo " task=$TASK_ID status=$STATUS "
100135 case " $STATUS " in
101136 Success)
102- FILE_ID=" $( echo " $STATUS_RESPONSE " | jq -r ' .file_id // empty' ) "
137+ FILE_ID=" $( jq -r ' .file_id // empty' <<< " $STATUS_RESPONSE " ) "
103138 [ -n " $FILE_ID " ] || exit 1
104139 break
105140 ;;
106141 Fail)
107- echo " $STATUS_RESPONSE " | jq .
142+ printf ' %s\n ' " $STATUS_RESPONSE " | jq .
108143 exit 1
109144 ;;
110145 Preparing|Queueing|Processing)
111- sleep 5
146+ [ " $POLL_COUNT " -ge " $MINIMAX_MAX_POLLS " ] || sleep 5
112147 ;;
113148 * )
114149 echo " Unknown video generation status: $STATUS "
@@ -117,15 +152,26 @@ while true; do
117152 esac
118153done
119154
120- FILE_RESPONSE=" $( curl -sS -G " $MINIMAX_API_BASE /files/retrieve" \
155+ [ " $STATUS " = " Success" ] || {
156+ echo " Polling stopped after $MINIMAX_MAX_POLLS status checks." >&2
157+ exit 1
158+ }
159+
160+ if ! FILE_RESPONSE=" $( curl -sS --fail-with-body \
161+ --connect-timeout 10 --max-time 60 \
162+ -G " $MINIMAX_API_BASE /files/retrieve" \
121163 -H " Authorization: Bearer $MINIMAX_API_KEY " \
122- --data-urlencode " file_id=$FILE_ID " ) "
164+ --data-urlencode " file_id=$FILE_ID " ) " ; then
165+ echo " File retrieval failed or timed out." >&2
166+ exit 1
167+ fi
123168
124- [ " $( echo " $FILE_RESPONSE " | jq -r ' .base_resp.status_code' ) " = " 0" ] || {
125- echo " $FILE_RESPONSE " | jq .
169+ jq -e . > /dev/null <<< " $FILE_RESPONSE" || exit 1
170+ [ " $( jq -r ' .base_resp.status_code' <<< " $FILE_RESPONSE" ) " = " 0" ] || {
171+ printf ' %s\n' " $FILE_RESPONSE " | jq .
126172 exit 1
127173}
128- DOWNLOAD_URL=" $( echo " $FILE_RESPONSE " | jq -r ' .file.download_url // empty' ) "
174+ DOWNLOAD_URL=" $( jq -r ' .file.download_url // empty' <<< " $FILE_RESPONSE " ) "
129175[ -n " $DOWNLOAD_URL " ] || exit 1
130176```
131177
0 commit comments