Upload image

October 14, 2024

Table of contents

  1. Request Headers
  2. Query Parameters
  3. Responses
  4. Model
  5. Examples
  6. Try It

Use hailuoai.video account to upload image, see Setup MiniMax for details.

Upload .png and .jpeg images up to 5GB in size that you want to use for your image generations via videos/create.

Please be patient, on average, it takes about 1 minute per GB to upload.

https://api.useapi.net/v1/minimax/files/?…

Request Headers
Authorization: Bearer {API token}
Content-Type: select from the table below
  • API token is required, see Setup useapi.net for details.
  • Content-Type is required, select from the table below:
Content-Type File Extension
image/png png
image/jpeg jpeg
Query Parameters
  • account is optional when only one account configured. However, if you have multiple accounts configured, this parameter becomes required.
Responses
  • 200 OK

    {
        "ossPath": "<file url>",
        "fileID": "user:user_id-minimax:account-file:file_id"
    }
    
  • 400 Bad Request

    {
        "error": "<Error message>",
        "code": 400
    }
    
  • 401 Unauthorized

    {
      "error": "Unauthorized",
      "code": 401
    }
    
Model
{ // TypeScript, all fields are optional
  ossPath: string
  fileID: string
  error: string
  code: number
}
Examples
  • curl "https://api.useapi.net/v1/minimax/files/?account=account" \
      -H "Authorization: Bearer …" \
      -H "Content-Type: image/jpeg" \
      --data-binary /path/to/your/image.jpeg
    
  • const token = "API token";
    const account = "Previously configured video account"; 
    const apiUrl = `https://api.useapi.net/v1/minimax/files/?account=${account}`; 
    let blob;
    /*
        // Example 1: Fetch image from URL
        const imageUrl = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg";
        const responseImage = await fetch(imageUrl);
        blob = await responseImage.blob();
    */
    /* 
        // Example 2: Load image from local file (Blob)
        const fsp = require('fs').promises;
        const imageFileName = "./cat.png";
        blob = new Blob([await fsp.readFile(imageFileName)]);
    */
    /*
        // Example 3: Load from input file html element
        // <input id="image-file" type="file"> 
        const imageFile = document.getElementById(`image-file`);
        if (imageFile.files[0])
            blob = imageFile.files[0]);
    */
    const response = await fetch(apiUrl, {
      method: "POST"
      headers: {
        "Authorization": `Bearer ${token}`,
      },
      body: blob
    });
    const result = await response.json();
    console.log("response", {response, result});
    
  • import requests
    token = "API token"
    account = "Previously configured video account"
    apiUrl = f"https://api.useapi.net/v1/minimax/files/?account={account}"
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'image/jpeg'
    }
    
    # # Example 1: Fetch image from URL
    # image_url = "https://upload.wikimedia.org/wikipedia/commons/7/7d/Mona_Lisa_color_restoration.jpg"
    # response_image = requests.get(image_url)
    # file_content = response_image.content
    
    # # Example 2: Load image from local file
    # image_file_path = "./image.jpg"
    # with open(image_file_path, 'rb') as image_file:
    #     file_content = image_file.read()
    
    response = requests.post(api_url, headers=headers, data=file_content)
    print(response, response.json())
    
Try It

Please be patient, comrades are checking every byte of your file for illegal propaganda, so give them some time.