fork download
  1. #!/bin/bash
  2. set -e
  3.  
  4. URL="https://a...content-available-to-author-only...r.ai/v1/ai-image-generator"
  5. STATUS_URL="https://a...content-available-to-author-only...r.ai/v1/image-projects"
  6. API_KEY="mhk_live_6obdalK0WmxuGHP0e74je44pZw3t3cvblbW31v1CLlXRyuo13sp5STNtN35mFcmJYe11KVnZ7bxn2GYf" # change to your API key
  7. OUTPUT_PATH="output.png"
  8.  
  9. create_response=$(curl -s $URL \
  10. --request POST \
  11. --header "Content-Type: application/json" \
  12. --header "Authorization: Bearer $API_KEY" \
  13. --data '{
  14. "image_count": 1,
  15. "orientation": "landscape",
  16. "style": {
  17. "prompt": "Epic anime art of wizard casting a cosmic spell in the sky that says \"Magic Hour\""
  18. }
  19. }')
  20.  
  21. project_id=$(echo $create_response | jq -r '.id')
  22. credits_charged=$(echo $create_response | jq -r '.credits_charged')
  23.  
  24. echo "queued image with id $project_id, spent $credits_charged credits"
  25. while true; do
  26. status_response=$(curl -s $STATUS_URL/$project_id --header "Authorization: Bearer $API_KEY")
  27.  
  28. status=$(echo $status_response | jq -r '.status')
  29.  
  30. if [ "$status" == "complete" ]; then
  31. echo "render complete!"
  32. download_url=$(echo $status_response | jq -r '.downloads[0].url')
  33.  
  34. echo "downloading image from $download_url..."
  35. curl -s $download_url -o $OUTPUT_PATH
  36.  
  37. echo "file downloaded successfully to $OUTPUT_PATH"
  38. break
  39. elif [ "$status" == "error" ]; then
  40. echo "render failed"
  41. break
  42. else
  43. echo "render in progress"
  44. fi
  45. done
Success #stdin #stdout 0.02s 25892KB
stdin
Standard input is empty
stdout
set -e

URL="https://a...content-available-to-author-only...r.ai/v1/ai-image-generator"
STATUS_URL="https://a...content-available-to-author-only...r.ai/v1/image-projects"
API_KEY="mhk_live_6obdalK0WmxuGHP0e74je44pZw3t3cvblbW31v1CLlXRyuo13sp5STNtN35mFcmJYe11KVnZ7bxn2GYf" # change to your API key
OUTPUT_PATH="output.png"

create_response=$(curl -s $URL \
  --request POST \
  --header "Content-Type: application/json" \
  --header "Authorization: Bearer $API_KEY" \
  --data '{
    "image_count": 1,
    "orientation": "landscape",
    "style": {
      "prompt": "Epic anime art of wizard casting a cosmic spell in the sky that says \"Magic Hour\""
    }
  }')

project_id=$(echo $create_response | jq -r '.id')
credits_charged=$(echo $create_response | jq -r '.credits_charged')

echo "queued image with id $project_id, spent $credits_charged credits"
while true; do
    status_response=$(curl -s $STATUS_URL/$project_id --header "Authorization: Bearer $API_KEY")

    status=$(echo $status_response | jq -r '.status')

    if [ "$status" == "complete" ]; then
        echo "render complete!"
        download_url=$(echo $status_response | jq -r '.downloads[0].url')

        echo "downloading image from $download_url..."
        curl -s $download_url -o $OUTPUT_PATH

        echo "file downloaded successfully to $OUTPUT_PATH"
        break
    elif [ "$status" == "error" ]; then
        echo "render failed"
        break
    else
        echo "render in progress"
        sleep 1
    fi
done