Write a file or create a directory
Writes the raw request body to the file at path, whatever its Content-Type: 201 with the file’s entry when it was created, 200 when it replaced one. The file is replaced in one step: readers see the whole old content or the whole new content, and a write that fails or is cut off (the client leaves, the body is too large, the time runs out) leaves the file exactly as it was. Missing parent directories are created (0755) once the whole body has arrived. A new file gets 0644; a replaced one keeps its permission bits. A write through a symlink writes the file it points to and keeps the link, even when that file doesn’t exist yet.
Permissions: a write needs permission to write both the file and its directory (permission_denied otherwise: a file you own in a directory you can’t write can still be changed with an exec), and a non-root writer becomes the replaced file’s owner; root keeps the old owner. Costs: an overwrite needs room for both copies until the new one replaces the old; hard links to the old file keep the old content, and processes holding it open keep reading it. Files the sandbox mounts itself (/etc/hosts, /etc/resolv.conf, /etc/hostname) can’t be replaced this way (file_operation_failed; use an exec).
A directory at path, or something that’s neither a file nor a directory (a device, FIFO or socket, which is kept), is path_type_mismatch; so is a path ending in /, or a parent that’s a file. A path ending in . or .., or under the reserved /.telnyx directory, is invalid_path.
Size and time: up to 64 MiB. A declared Content-Length over it is file_too_large before anything is sent to the sandbox; a body without one is refused as soon as it passes it. The body must be complete 2 s before the call’s time budget ends: a body still arriving then is 408 (code 10008), and the file is unchanged. A 503 after the whole body was sent may have written the file; retrying writes the same content again, which is harmless.
With directory=true and an empty body (else 400): creates the directory at path with any missing parents, 201, or 200 if a directory was already there; trailing slashes are ignored, and a file in the way is path_type_mismatch.
Send an Idempotency-Key: a retry with the same key, path, flags and body gets the stored answer, and nothing is written again; a different request with it is idempotency_key_reused.
path is absolute, at most 4096 bytes in UTF-8, and must be valid UTF-8 once percent-decoded; it’s taken as the sandbox’s kernel resolves it (., .. and // included). A path holding a NUL byte is invalid_path.
The sandbox must be running (else sandbox_not_running); file calls keep working during the stop’s grace period, so you can fetch results from a sandbox that’s ending. They run as the sandbox’s own user, with its permissions: what that user may not do, or a read-only file system, is permission_denied. Another refusal by the sandbox’s file system (no space, a name too long, a busy file or mount point, a symlink loop, an I/O error) is file_operation_failed, with a fixed text naming the reason. File calls don’t count as activity for idle_timeout.
Each call has a 64 MiB limit and a time budget of about 12 s for its whole transfer, so a full-size file needs about 5.3 MiB/s between you and the API to read, and about 6.4 MiB/s to write (a write’s body must arrive 2 s before the budget ends). Move larger data through Cloud Storage from an exec.
curl --request PUT \
--url https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/octet-stream' \
--data '{"accuracy": 0.912, "split": "test"}'import requests
url = "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files"
payload = "{\"accuracy\": 0.912, \"split\": \"test\"}"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/octet-stream"
}
response = requests.put(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/octet-stream'},
body: '{"accuracy": 0.912, "split": "test"}'
};
fetch('https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/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.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"accuracy\": 0.912, \"split\": \"test\"}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/octet-stream"
],
]);
$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.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files"
payload := strings.NewReader("{\"accuracy\": 0.912, \"split\": \"test\"}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/octet-stream")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/octet-stream")
.body("{\"accuracy\": 0.912, \"split\": \"test\"}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/octet-stream'
request.body = "{\"accuracy\": 0.912, \"split\": \"test\"}"
response = http.request(request)
puts response.read_body{
"data": {
"name": "results.json",
"path": "/app/out/results.json",
"type": "file",
"size_bytes": 18234,
"modified_at": "2026-11-13T10:42:17Z"
}
}{
"data": {
"name": "results.json",
"path": "/app/out/results.json",
"type": "file",
"size_bytes": 18234,
"modified_at": "2026-11-13T10:42:17Z"
}
}{
"errors": [
{
"title": "<string>",
"code": "<string>",
"detail": "<string>",
"meta": {
"url": null
},
"source": {
"parameter": null,
"pointer": null
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request."
}
]
}{
"errors": [
{
"title": "sandboxes_not_whitelisted",
"detail": "The organization isn't whitelisted."
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "Sandbox not found."
}
]
}{
"errors": [
{
"code": "10008",
"title": "Request timeout",
"detail": "The request body didn't arrive in time."
}
]
}{
"errors": [
{
"title": "path_type_mismatch",
"detail": "The path is a directory."
}
]
}{
"errors": [
{
"title": "file_too_large",
"detail": "The file is larger than 64 MiB."
}
]
}{
"errors": [
{
"title": "invalid_path",
"detail": "The path is reserved."
}
]
}{
"errors": [
{
"code": "10037",
"title": "Service unavailable",
"detail": "A dependency can't answer right now; retry later."
}
]
}Authorizations
Headers
Optional client-chosen key (e.g. a UUID, at most 255 characters) that makes the call safe to retry. Within 24 h, the same key with the same request returns the stored response instead of acting twice; the same key with a different request fails with idempotency_key_reused; a request with a key that's still being processed fails with request_in_progress.
1 - 255Query Parameters
Body
The file's contents, as raw bytes whatever the Content-Type; empty when directory=true.
The body is of type file.
Was this page helpful?
curl --request PUT \
--url https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/octet-stream' \
--data '{"accuracy": 0.912, "split": "test"}'import requests
url = "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files"
payload = "{\"accuracy\": 0.912, \"split\": \"test\"}"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/octet-stream"
}
response = requests.put(url, data=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/octet-stream'},
body: '{"accuracy": 0.912, "split": "test"}'
};
fetch('https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/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.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => "{\"accuracy\": 0.912, \"split\": \"test\"}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/octet-stream"
],
]);
$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.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files"
payload := strings.NewReader("{\"accuracy\": 0.912, \"split\": \"test\"}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/octet-stream")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/octet-stream")
.body("{\"accuracy\": 0.912, \"split\": \"test\"}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/files")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/octet-stream'
request.body = "{\"accuracy\": 0.912, \"split\": \"test\"}"
response = http.request(request)
puts response.read_body{
"data": {
"name": "results.json",
"path": "/app/out/results.json",
"type": "file",
"size_bytes": 18234,
"modified_at": "2026-11-13T10:42:17Z"
}
}{
"data": {
"name": "results.json",
"path": "/app/out/results.json",
"type": "file",
"size_bytes": 18234,
"modified_at": "2026-11-13T10:42:17Z"
}
}{
"errors": [
{
"title": "<string>",
"code": "<string>",
"detail": "<string>",
"meta": {
"url": null
},
"source": {
"parameter": null,
"pointer": null
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request."
}
]
}{
"errors": [
{
"title": "sandboxes_not_whitelisted",
"detail": "The organization isn't whitelisted."
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "Sandbox not found."
}
]
}{
"errors": [
{
"code": "10008",
"title": "Request timeout",
"detail": "The request body didn't arrive in time."
}
]
}{
"errors": [
{
"title": "path_type_mismatch",
"detail": "The path is a directory."
}
]
}{
"errors": [
{
"title": "file_too_large",
"detail": "The file is larger than 64 MiB."
}
]
}{
"errors": [
{
"title": "invalid_path",
"detail": "The path is reserved."
}
]
}{
"errors": [
{
"code": "10037",
"title": "Service unavailable",
"detail": "A dependency can't answer right now; retry later."
}
]
}