Sample code for 30+ languages & platforms
AutoIt

Upload an Image File to an AI Provider (OpenAI, Google, Antropic, X)

See more AI Examples

Uploads an image file to an AI provider using the provider's File API and returns the id that can later be used to reference the file in an query. This currently works with ChatGPT and Gemini, but not other AI's. Most AI's currently don't have the ability to reference pre-uploaded image data in conversations.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oAi = ObjCreate("Chilkat.Ai")

; Can currently be "openai" or "google" because these are the only AI's that can reference pre-loaded image data by file ID.
$oAi.Provider = "openai"
; Use your provider's API key.
$oAi.ApiKey = "MY_API_KEY"

; We can upload directly from a file in the filesystem, or from a Chilkat BinData.

Local $sContentType = "image/jpeg"
Local $sLocalFilePath = "qa_data/jpg/starfish.jpg"
Local $sFilenameOnServer = "starfish.jpg"

; Upload directly from a file.
Local $sFile_id = $oAi.UploadFile($sLocalFilePath,$sContentType)
If ($oAi.LastMethodSuccess = False) Then
    ConsoleWrite($oAi.LastErrorText & @CRLF)
    ConsoleWrite("AI File Upload Failed." & @CRLF)
Else
    ConsoleWrite("File ID: " & $sFile_id & @CRLF)
    ConsoleWrite("File uploaded." & @CRLF)
EndIf

; Upload from the contents of a Chilkat BinData
$oBd = ObjCreate("Chilkat.BinData")
$bSuccess = $oBd.LoadFile($sLocalFilePath)
If ($bSuccess = False) Then
    ConsoleWrite($oBd.LastErrorText & @CRLF)
    Exit
EndIf

$sFile_id = $oAi.UploadFileBd($oBd,$sFilenameOnServer,$sContentType)
If ($oAi.LastMethodSuccess = False) Then
    ConsoleWrite($oAi.LastErrorText & @CRLF)
    ConsoleWrite("AI File Upload Failed." & @CRLF)
Else
    ConsoleWrite("File ID: " & $sFile_id & @CRLF)
    ConsoleWrite("File uploaded." & @CRLF)
EndIf