Uploads
Create presigned URLs for batch file upload
Generate presigned URLs for uploading multiple files to the specified namespace.
POST
/
v1
/
namespace
/
{namespaceId}
/
uploads
/
batch
TypeScript
import { Agentset } from "agentset";
import fs from 'fs';
const agentset = new Agentset({ apiKey: 'agentset_xxx' });
const ns = agentset.namespace('ns_xxx');
const results = await ns.uploads.uploadBatch([
{
file: fs.createReadStream("./example-1.md"),
contentType: "text/markdown",
},
{
file: fs.createReadStream("./example-2.md"),
contentType: "text/markdown",
},
]);
console.log("Uploaded successfully: ", results.map((result) => result.key));
// OR get the pre-signed URLs manually
const file1 = fs.readFileSync("./example-1.md");
const file2 = fs.readFileSync("./example-2.md");
const results = await ns.uploads.createBatch({
files: [
{
fileName: "example-1.md",
fileSize: file1.length,
contentType: "text/markdown",
},
{
fileName: "example-2.md",
fileSize: file2.length,
contentType: "text/markdown",
},
],
});
await Promise.all([file1, file2].map(async (file, i) => {
await fetch(results[i]!.url, {
method: "PUT",
body: file,
headers: {
"Content-Type": "text/markdown",
},
});
}));
console.log("Upload URLs:", results.map((result) => result.key));from agentset import Agentset
with Agentset(
namespace_id="ns_123",
token="AGENTSET_API_KEY",
) as a_client:
res = a_client.uploads.create_batch(files=[])
# Handle response
print(res)curl --request POST \
--url https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"files": [
{
"fileName": "<string>",
"contentType": "<string>",
"fileSize": 104857600.5
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
files: [{fileName: '<string>', contentType: '<string>', fileSize: 104857600.5}]
})
};
fetch('https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch', 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.agentset.ai/v1/namespace/{namespaceId}/uploads/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'files' => [
[
'fileName' => '<string>',
'contentType' => '<string>',
'fileSize' => 104857600.5
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch"
payload := strings.NewReader("{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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.agentset.ai/v1/namespace/{namespaceId}/uploads/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": [
{
"url": "<string>",
"key": "<string>"
}
]
}{
"success": false,
"error": {
"code": "bad_request",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#bad-request"
}
}{
"success": false,
"error": {
"code": "unauthorized",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#unauthorized"
}
}{
"success": false,
"error": {
"code": "forbidden",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#forbidden"
}
}{
"success": false,
"error": {
"code": "not_found",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#not-found"
}
}{
"success": false,
"error": {
"code": "conflict",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#conflict"
}
}{
"success": false,
"error": {
"code": "invite_expired",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#invite-expired"
}
}{
"success": false,
"error": {
"code": "unprocessable_entity",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#unprocessable-entity"
}
}{
"success": false,
"error": {
"code": "rate_limit_exceeded",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#rate-limit_exceeded"
}
}{
"success": false,
"error": {
"code": "internal_server_error",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#internal-server_error"
}
}Authorizations
Default authentication mechanism
Path Parameters
The id of the namespace (prefixed with ns_)
Example:
"ns_123"
Body
application/json
Required array length:
1 - 100 elementsShow child attributes
Show child attributes
⌘I
TypeScript
import { Agentset } from "agentset";
import fs from 'fs';
const agentset = new Agentset({ apiKey: 'agentset_xxx' });
const ns = agentset.namespace('ns_xxx');
const results = await ns.uploads.uploadBatch([
{
file: fs.createReadStream("./example-1.md"),
contentType: "text/markdown",
},
{
file: fs.createReadStream("./example-2.md"),
contentType: "text/markdown",
},
]);
console.log("Uploaded successfully: ", results.map((result) => result.key));
// OR get the pre-signed URLs manually
const file1 = fs.readFileSync("./example-1.md");
const file2 = fs.readFileSync("./example-2.md");
const results = await ns.uploads.createBatch({
files: [
{
fileName: "example-1.md",
fileSize: file1.length,
contentType: "text/markdown",
},
{
fileName: "example-2.md",
fileSize: file2.length,
contentType: "text/markdown",
},
],
});
await Promise.all([file1, file2].map(async (file, i) => {
await fetch(results[i]!.url, {
method: "PUT",
body: file,
headers: {
"Content-Type": "text/markdown",
},
});
}));
console.log("Upload URLs:", results.map((result) => result.key));from agentset import Agentset
with Agentset(
namespace_id="ns_123",
token="AGENTSET_API_KEY",
) as a_client:
res = a_client.uploads.create_batch(files=[])
# Handle response
print(res)curl --request POST \
--url https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"files": [
{
"fileName": "<string>",
"contentType": "<string>",
"fileSize": 104857600.5
}
]
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
files: [{fileName: '<string>', contentType: '<string>', fileSize: 104857600.5}]
})
};
fetch('https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch', 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.agentset.ai/v1/namespace/{namespaceId}/uploads/batch",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'files' => [
[
'fileName' => '<string>',
'contentType' => '<string>',
'fileSize' => 104857600.5
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch"
payload := strings.NewReader("{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
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.agentset.ai/v1/namespace/{namespaceId}/uploads/batch")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.agentset.ai/v1/namespace/{namespaceId}/uploads/batch")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"files\": [\n {\n \"fileName\": \"<string>\",\n \"contentType\": \"<string>\",\n \"fileSize\": 104857600.5\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": [
{
"url": "<string>",
"key": "<string>"
}
]
}{
"success": false,
"error": {
"code": "bad_request",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#bad-request"
}
}{
"success": false,
"error": {
"code": "unauthorized",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#unauthorized"
}
}{
"success": false,
"error": {
"code": "forbidden",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#forbidden"
}
}{
"success": false,
"error": {
"code": "not_found",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#not-found"
}
}{
"success": false,
"error": {
"code": "conflict",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#conflict"
}
}{
"success": false,
"error": {
"code": "invite_expired",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#invite-expired"
}
}{
"success": false,
"error": {
"code": "unprocessable_entity",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#unprocessable-entity"
}
}{
"success": false,
"error": {
"code": "rate_limit_exceeded",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#rate-limit_exceeded"
}
}{
"success": false,
"error": {
"code": "internal_server_error",
"message": "The requested resource was not found.",
"doc_url": "https://docs.agentset.ai/api-reference/errors#internal-server_error"
}
}