google-file-upload (file upload north america)
Upload files to Google Generative AI API (North America region)
POST
/
v1beta
/
files
google-file-upload (file upload north america)
curl --request POST \
--url https://api.example.com/v1beta/filesimport requests
url = "https://api.example.com/v1beta/files"
response = requests.post(url)
print(response.text)const options = {method: 'POST'};
fetch('https://api.example.com/v1beta/files', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/v1beta/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/v1beta/files"
req, _ := http.NewRequest("POST", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/v1beta/files")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1beta/files")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
response = http.request(request)
puts response.read_bodyThis endpoint allows you to upload files for use with Google’s Generative AI models in the North America region.
curl --location 'https://api-na.gptproto.com/upload/v1beta/files' \
--header 'x-goog-api-key: YOUR_API_KEY' \
--form 'file=@"/path/to/your/file.pdf"'
import requests
url = "https://api-na.gptproto.com/upload/v1beta/files"
headers = {
"x-goog-api-key": "YOUR_API_KEY"
}
files = {
"file": open("/path/to/your/file.pdf", "rb")
}
response = requests.post(url, headers=headers, files=files)
result = response.json()
print(result)
const url = "https://api-na.gptproto.com/upload/v1beta/files";
const formData = new FormData();
formData.append("file", fileInput.files[0]);
fetch(url, {
method: "POST",
headers: {
"x-goog-api-key": "YOUR_API_KEY"
},
body: formData
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
url := "https://api-na.gptproto.com/upload/v1beta/files"
file, _ := os.Open("/path/to/your/file.pdf")
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, _ := writer.CreateFormFile("file", "file.pdf")
io.Copy(part, file)
writer.Close()
req, _ := http.NewRequest("POST", url, body)
req.Header.Set("x-goog-api-key", "YOUR_API_KEY")
req.Header.Set("Content-Type", writer.FormDataContentType())
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
responseBody, _ := io.ReadAll(resp.Body)
fmt.Println(string(responseBody))
}
{
"error": {
"message": "Invalid signature",
"type": "401"
}
}
{
"error": {
"message": "Internal server error",
"type": "500"
}
}
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
file | file | ✅ Yes | - | The file to upload |
⌘I

