Files
Upload a file
Upload a file with specified purpose, file name, and file type.
POST
/
v1
/
files
/
upload
Together AI SDK (Python)
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_dir, "data.jsonl")
file = client.files.upload(file=file_path)
print(file.id)import Together from "together-ai";
const client = new Together();
const file = await client.files.upload("data.jsonl", "fine-tune");
console.log(file.id);
import Together from "together-ai";
const client = new Together();
const file = await client.files.upload("data.jsonl", "fine-tune");
console.log(file.id);
curl "https://api.together.ai/v1/files/upload" \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-F "file=@/path/to/data.jsonl" \
-F "file_name=data.jsonl" \
-F "purpose=fine-tune"
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.ai/v1/files/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$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.together.ai/v1/files/upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
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.together.ai/v1/files/upload")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/files/upload")
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"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "file",
"created_at": 123,
"filename": "my_file.jsonl",
"bytes": 123,
"purpose": "fine-tune",
"FileType": "jsonl",
"processing_status": "PENDING",
"validation_report": {
"valid": true,
"dataset_format": "<string>",
"dataset_has_sample_weights": true,
"dataset_has_message_weights": true,
"dataset_is_multimodal": true,
"dataset_has_tools": true,
"dataset_has_parallel_tool_calls": true,
"dataset_has_reasoning": true,
"nlines": 123,
"file_id": "<string>",
"error_type": "INVALID_FORMAT",
"error": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}Authorizations
Body
multipart/form-data
Response
File uploaded successfully
Structured information describing a file uploaded to Together.
Was this page helpful?
⌘I
Together AI SDK (Python)
from together import Together
import os
client = Together(
api_key=os.environ.get("TOGETHER_API_KEY"),
)
current_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_dir, "data.jsonl")
file = client.files.upload(file=file_path)
print(file.id)import Together from "together-ai";
const client = new Together();
const file = await client.files.upload("data.jsonl", "fine-tune");
console.log(file.id);
import Together from "together-ai";
const client = new Together();
const file = await client.files.upload("data.jsonl", "fine-tune");
console.log(file.id);
curl "https://api.together.ai/v1/files/upload" \
-H "Authorization: Bearer $TOGETHER_API_KEY" \
-F "file=@/path/to/data.jsonl" \
-F "file_name=data.jsonl" \
-F "purpose=fine-tune"
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.together.ai/v1/files/upload",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$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.together.ai/v1/files/upload"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
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.together.ai/v1/files/upload")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.together.ai/v1/files/upload")
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"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"purpose\"\r\n\r\nfine-tune\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_name\"\r\n\r\ndataset.csv\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_type\"\r\n\r\njsonl\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "file",
"created_at": 123,
"filename": "my_file.jsonl",
"bytes": 123,
"purpose": "fine-tune",
"FileType": "jsonl",
"processing_status": "PENDING",
"validation_report": {
"valid": true,
"dataset_format": "<string>",
"dataset_has_sample_weights": true,
"dataset_has_message_weights": true,
"dataset_is_multimodal": true,
"dataset_has_tools": true,
"dataset_has_parallel_tool_calls": true,
"dataset_has_reasoning": true,
"nlines": 123,
"file_id": "<string>",
"error_type": "INVALID_FORMAT",
"error": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": null,
"code": null
}
}