You can send documents and other media files directly to the chat completions endpoint. Voidon extends the standard OpenAI message format to support a wide range of file types by embedding them as Base64 encoded data within your request.
There is no separate upload endpoint. All files must be included in the messages array of your call to /v1/chat/completions.
{"model":"auto","messages":[{"role":"user","content":[{"type":"text","text":"Please describe this image and summarize the attached document."},{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUg..."}},{"type":"file","file":{"url":"data:application/pdf;base64,JVBERi0xLjcKJeLjz9M..."}}]}]}
The type field can be image_url, audio_url, video_url, or a generic file.
Note
In the examples below, you must replace your-voidon-api-key with your actual API key. You will also need to have local files named example.jpg, example.mp3, example.mp4, and example.pdf for the code to run correctly.
importopenaiimportbase64importmimetypes# Function to encode a local file into a data URIdefencode_file_to_data_uri(file_path):mime_type,_=mimetypes.guess_type(file_path)ifmime_typeisNone:raiseValueError("Could not determine MIME type for file")withopen(file_path,"rb")asfile:encoded_string=base64.b64encode(file.read()).decode("utf-8")returnf"data:{mime_type};base64,{encoded_string}"client=openai.OpenAI(api_key="your-voidon-api-key",base_url="https://api.voidon.astramind.ai/v1")# Prepare the data URIsimage_uri=encode_file_to_data_uri("example.jpg")pdf_uri=encode_file_to_data_uri("example.pdf")response=client.chat.completions.create(model="auto",messages=[{"role":"user","content":[{"type":"text","text":"Describe the image and summarize the PDF."},{"type":"image_url","image_url":{"url":image_uri}},{"type":"file","file":{"url":pdf_uri}}]}])print(response.choices[0].message.content)
importrequestsimportjsonimportbase64importmimetypesAPI_KEY="your-voidon-api-key"API_URL="https://api.voidon.astramind.ai/v1/chat/completions"# Function to encode a local file into a data URIdefencode_file_to_data_uri(file_path):mime_type,_=mimetypes.guess_type(file_path)ifmime_typeisNone:raiseValueError("Could not determine MIME type for file")withopen(file_path,"rb")asfile:encoded_string=base64.b64encode(file.read()).decode("utf-8")returnf"data:{mime_type};base64,{encoded_string}"headers={"Authorization":f"Bearer {API_KEY}","Content-Type":"application/json"}image_uri=encode_file_to_data_uri("example.jpg")pdf_uri=encode_file_to_data_uri("example.pdf")payload={"model":"auto","messages":[{"role":"user","content":[{"type":"text","text":"Describe the image and summarize the PDF."},{"type":"image_url","image_url":{"url":image_uri}},{"type":"file","file":{"url":pdf_uri}}]}]}response=requests.post(API_URL,headers=headers,data=json.dumps(payload))ifresponse.status_code==200:print(response.json()['choices'][0]['message']['content'])else:print(f"Error: {response.status_code} - {response.text}")
// Requires Node.js environmentimportOpenAIfrom'openai';importfsfrom'fs';importpathfrom'path';importmimefrom'mime-types';// npm install mime-typesconstencodeFileToDataUri=(filePath)=>{constmimeType=mime.lookup(filePath);if(!mimeType){thrownewError("Could not determine MIME type");}constfileBuffer=fs.readFileSync(filePath);constbase64Encoded=fileBuffer.toString('base64');return`data:${mimeType};base64,${base64Encoded}`;};constopenai=newOpenAI({apiKey:'your-voidon-api-key',baseURL:'https://api.voidon.astramind.ai/v1'});asyncfunctionmain(){constimageUri=encodeFileToDataUri('example.jpg');constpdfUri=encodeFileToDataUri('example.pdf');constresponse=awaitopenai.chat.completions.create({model:'auto',messages:[{role:'user',content:[{type:'text',text:'Describe the image and summarize the PDF.'},{type:'image_url',image_url:{url:imageUri}},{type:'file',file:{url:pdfUri}}],}],});console.log(response.choices[0].message.content);}main();
packagemainimport("context""encoding/base64""fmt""github.com/sashabaranov/go-openai""log""mime""os""path/filepath")funcencodeFileToDataURI(filePathstring)(string,error){fileBytes,err:=os.ReadFile(filePath)iferr!=nil{return"",err}encodedString:=base64.StdEncoding.EncodeToString(fileBytes)mimeType:=mime.TypeByExtension(filepath.Ext(filePath))ifmimeType==""{mimeType="application/octet-stream"}returnfmt.Sprintf("data:%s;base64,%s",mimeType,encodedString),nil}funcmain(){config:=openai.DefaultConfig("your-voidon-api-key")config.BaseURL="https://api.voidon.astramind.ai/v1"client:=openai.NewClientWithConfig(config)imageURI,err:=encodeFileToDataURI("example.jpg")iferr!=nil{log.Fatalf("Failed to encode image: %v",err)}pdfURI,err:=encodeFileToDataURI("example.pdf")iferr!=nil{log.Fatalf("Failed to encode PDF: %v",err)}resp,err:=client.CreateChatCompletion(context.Background(),openai.ChatCompletionRequest{Model:"auto",Messages:[]openai.ChatCompletionMessage{{Role:openai.ChatMessageRoleUser,MultiContent:[]openai.ChatMessagePart{{Type:openai.ChatMessagePartTypeText,Text:"Describe the image and summarize the PDF.",},{Type:openai.ChatMessagePartTypeImageURL,ImageURL:&openai.ChatMessageImageURL{URL:imageURI,},},// Note: The go-openai library doesn't have a native 'file' type.// You might need to send this as a generic ImageURL or use an HTTP client.// This example assumes the API can interpret an ImageURL part as a generic file.{Type:openai.ChatMessagePartTypeImageURL,ImageURL:&openai.ChatMessageImageURL{URL:pdfURI,},},},},},},)iferr!=nil{fmt.Printf("Error: %v\n",err)return}fmt.Println(resp.Choices[0].Message.Content)}
packagemainimport("bytes""encoding/base64""encoding/json""fmt""io""log""mime""net/http""os""path/filepath")funcencodeFileToDataURI(filePathstring)(string,error){fileBytes,err:=os.ReadFile(filePath)iferr!=nil{return"",err}encodedString:=base64.StdEncoding.EncodeToString(fileBytes)mimeType:=mime.TypeByExtension(filepath.Ext(filePath))ifmimeType==""{mimeType="application/octet-stream"}returnfmt.Sprintf("data:%s;base64,%s",mimeType,encodedString),nil}// Define structs for the JSON payloadtypeMessagePartstruct{Typestring`json:"type"`Textstring`json:"text,omitempty"`ImageURL*URLDetail`json:"image_url,omitempty"`FileURL*URLDetail`json:"file,omitempty"`}typeURLDetailstruct{URLstring`json:"url"`}typeMessagestruct{Rolestring`json:"role"`Content[]MessagePart`json:"content"`}typeRequestPayloadstruct{Modelstring`json:"model"`Messages[]Message`json:"messages"`}funcmain(){apiKey:="your-voidon-api-key"url:="https://api.voidon.astramind.ai/v1/chat/completions"imageURI,err:=encodeFileToDataURI("example.jpg")iferr!=nil{log.Fatalf("Failed to encode image: %v",err)}pdfURI,err:=encodeFileToDataURI("example.pdf")iferr!=nil{log.Fatalf("Failed to encode PDF: %v",err)}payload:=RequestPayload{Model:"auto",Messages:[]Message{{Role:"user",Content:[]MessagePart{{Type:"text",Text:"Describe the image and summarize the PDF."},{Type:"image_url",ImageURL:&URLDetail{URL:imageURI}},{Type:"file",FileURL:&URLDetail{URL:pdfURI}},},},},}requestBody,_:=json.Marshal(payload)req,_:=http.NewRequest("POST",url,bytes.NewBuffer(requestBody))req.Header.Set("Authorization","Bearer "+apiKey)req.Header.Set("Content-Type","application/json")client:=&http.Client{}resp,err:=client.Do(req)iferr!=nil{panic(err)}deferresp.Body.Close()body,_:=io.ReadAll(resp.Body)fmt.Println(string(body))}