Sending Files as Multipart/Form-Data from Custom GPT to External API Endpoint

Hi everyone,

I’m currently working on creating a custom GPT model, and I need some guidance on sending files to an external API endpoint. My goal is to have the GPT model send a file as multipart/form-data when a user attaches a file in a playground environment. Below, you can find the OpenAPI schema for the endpoint:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Receive API",
    "description": "Some description",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "URL address"
    }
  ],
  "paths": {
    "/v2": {
      "post": {
        "summary": "description",
        "description": "xxxxxxxx",
        "operationId": "V2",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    },
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {}
  }
}

However, I’m encountering an issue where the file content is not included in the request body, and I consistently receive the following error message:

{
  "response_data": {
    "detail": [
      {
        "type": "missing",
        "loc": [
          "body",
          "file"
        ],
        "msg": "Field required",
        "input": null,
        "url": "https://errors.pydantic.dev/2.5/v/missing"
      }
    ]
  },
  "status_code": 422,
  "action_id": "g-bf3979cc51b8108aa720d1f18c3d9e4bc9b670aa"
}

I’m wondering if it’s possible to send a file from a GPT model to an external endpoint, and if so, should I modify the schema for this endpoint? Any advice or insights on how to achieve this would be greatly appreciated.

Thank you in advance for your help!

Hello @vah.sah ,

Were you able to figure this out? I am also stuck on the same for days.
It will really help if you can help please.

Thank you,
Dhruv

Hello @DhruvAwasthi ,

I’ve made several attempts to tackle this task using different methods. It appears that, given the current configurations of custom GPTs, you can send data in the application/json format, but there’s a limitation on the maximum length, which is approximately 500 characters. Consequently, the only viable approach involves encoding your data, breaking it into smaller chunks, sending these chunks to an external API, and then reconstructing the data on the other end. However, it’s worth noting that this approach may encounter difficulties when dealing with large files, including extended data transfer times and the possibility of losing or skipping some chunks.

At this moment, the most practical solution would be to find a way to perform a similar task within the GPT’s environment, where you have access to the data. However, it’s important to be aware that custom GPTs have limited computational resources in this context.

1 Like

Thank you so much @vah.sah.
This really helps!