Write file
curl --request POST \
--url https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"content_base64": "<string>"
}
'import requests
url = "https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file"
payload = {
"path": "<string>",
"content_base64": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', content_base64: '<string>'})
};
fetch('https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file', 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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file",
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([
'path' => '<string>',
'content_base64' => '<string>'
]),
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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file")
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 \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"path": "<string>",
"size_bytes": 123
}Sessions
Write file
Upload a file to a cloud browser’s machine for the agent to use.
POST
/
api
/
v2
/
sessions
/
{session_id}
/
files
/
write_file
Write file
curl --request POST \
--url https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"path": "<string>",
"content_base64": "<string>"
}
'import requests
url = "https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file"
payload = {
"path": "<string>",
"content_base64": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({path: '<string>', content_base64: '<string>'})
};
fetch('https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file', 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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file",
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([
'path' => '<string>',
'content_base64' => '<string>'
]),
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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file"
payload := strings.NewReader("{\n \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\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://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://agp.eu.hcompany.ai/api/v2/sessions/{session_id}/files/write_file")
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 \"path\": \"<string>\",\n \"content_base64\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"path": "<string>",
"size_bytes": 123
}Writes a file onto the machine hosting a cloud browser, so the agent can attach it to a form, upload it to a site, or read it. The content is sent base64-encoded; an existing file at the same path is overwritten.
Returns the written file’s
Files are capped at 8 MiB; larger ones are rejected. Only
Tell the agent where the file is, for example with a message: “Upload
path and size_bytes.
session_id is the browser session id from the session’s RunnerSessionEvent, not the agent session id. See list files for how to obtain it.~/Downloads is writable.
Path parameters
string
required
The browser session id.
Request body
string
required
Destination path. Absolute, or relative to the browser’s home (
~/Downloads/cv.pdf).string
required
The file’s bytes, base64-encoded.
Response
string
The written file’s resolved path.
integer
Bytes written.
Examples
curl -X POST https://agp.eu.hcompany.ai/api/v2/sessions/$BROWSER_SESSION_ID/files/write_file \
-H "Authorization: Bearer $HAI_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"path\": \"~/Downloads/cv.pdf\", \"content_base64\": \"$(base64 -i cv.pdf)\"}"
import base64
from hai_agents import Client
client = Client()
with open("cv.pdf", "rb") as f:
content = base64.b64encode(f.read()).decode()
client.session_files.write_file(browser_session_id, path="~/Downloads/cv.pdf", content_base64=content)
import { readFileSync } from "node:fs";
import { HaiAgentsClient } from "hai-agents";
const client = new HaiAgentsClient();
await client.sessionFiles.writeFile({
sessionId: browserSessionId,
path: "~/Downloads/cv.pdf",
contentBase64: readFileSync("cv.pdf").toString("base64"),
});
Response
{
"path": "/home/hai/Downloads/cv.pdf",
"size_bytes": 182044
}
~/Downloads/cv.pdf in the application form.”Was this page helpful?