Files API
Effective August 1, 2024 Anyscale Endpoints API will be available exclusively through the fully Hosted Anyscale Platform. Multi-tenant access to LLM models will be removed.
With the Hosted Anyscale Platform, you can access the latest GPUs billed by the second, and deploy models on your own dedicated instances. Enjoy full customization to build your end-to-end applications with Anyscale. Get started today.
The Files API is available at https://api.endpoints.anyscale.com/v1/files
. This API allows you to upload training and validation datasets to use for your fine-tuning jobs.
This API is compatible with the OpenAI SDK.
APIs
Upload file
POST https://api.endpoints.anyscale.com/v1/files
Uploads a file for use in fine-tuning. The file format must be in the JSON Lines format, which is a newline separated list of JSON objects.
See Data format for more details on the exact file format schema.
Request body
file
string - The contents of the file to upload.
Returns
A file object
Use the OpenAI SDK
import openai
client = openai.OpenAI(
base_url = "https://api.endpoints.anyscale.com/v1",
api_key = "esecret_yourAuthTokenHere"
)
file_name = "train.jsonl"
file = client.files.create(
file=open(file_name, "rb"),
purpose="fine-tune",
user_provided_filename=file_name,
)
Use cURL
curl https://api.endpoints.anyscale.com/v1/files \
-H "Authorization: Bearer esecret_yourAuthTokenHere" \
-F 'file=@train.jsonl'
If you're seeing 504
errors with Your request has exceeded the timeout of 3 minutes
when uploading, change the base URL for uploading to:
https://app.endpoints.anyscale.com/endpoints-api/v1
List files
GET https://api.endpoints.anyscale.com/v1/files
Gets a list of all the files that you uploaded to the Endpoints service.
Returns
A list of file object in the following format:
{
"data": [File, ...]
}
Use the OpenAI SDK
import openai
client = openai.OpenAI(
base_url = "https://api.endpoints.anyscale.com/v1",
api_key = "esecret_yourAuthTokenHere")
files = client.files.list()
Use cURL
curl https://api.endpoints.anyscale.com/v1/files \
-H "Authorization: Bearer esecret_yourAuthTokenHere"
Get file
GET https://api.endpoints.anyscale.com/v1/files/{file_id}
Gets the metadata of a single file that you uploaded to the Endpoints service.
Returns
A file object.
Use the OpenAI SDK
import openai
client = openai.OpenAI(
base_url = "https://api.endpoints.anyscale.com/v1",
api_key = "esecret_yourAuthTokenHere")
file = client.files.retrieve("file_123")
Use cURL
curl https://api.endpoints.anyscale.com/v1/files/file_123 \
-H "Authorization: Bearer esecret_yourAuthTokenHere"
Get file contents
GET https://api.endpoints.anyscale.com/v1/files/{file_id}/content
Returns the contents of the file that you uploaded to the Endpoints service.
📌 When using cURL, you must pass in a
-L
parameter to automatically follow redirects and retrieve the file contents.
Returns
The contents of the uploaded file.
Use the OpenAI SDK
import openai
client = openai.OpenAI(
base_url = "https://api.endpoints.anyscale.com/v1",
api_key = "esecret_yourAuthTokenHere")
content = client.files.retrieve_content("file_123")
Use cURL
curl -L https://api.endpoints.anyscale.com/v1/files/file_123/content \
-H "Authorization: Bearer esecret_yourAuthTokenHere"
Loading .jsonl
files
Many of the files are in jsonl
format. The training data, the validation data, and the fine-tuning results are all in this format. The following code snippet shows how to load a jsonl
file into a list of JSON objects.
from json import loads
jsonl_lines = content.decode("utf-8").split("\n")
content = [loads(line) for line in jsonl_lines if line != ""]
Delete file
DELETE https://api.endpoints.anyscale.com/v1/files/{file_id}
Deletes a file that was previously uploaded to the endpoints service.
Returns
The deleted file object.
Use the OpenAI SDK
import openai
client = openai.OpenAI(
base_url = "https://api.endpoints.anyscale.com/v1",
api_key = "esecret_yourAuthTokenHere")
content = openai.files.delete("file_123")
Use cURL
curl -X DELETE https://api.endpoints.anyscale.com/v1/files/file_123 \
-H "Authorization: Bearer esecret_yourAuthTokenHere"
Models
File
The file object represents a file that you uploaded to the Endpoints service. These files are referenced by ID in the fine-tuning API to use for training and validation.
📌 The following fields that are available in OpenAI's File object aren't supported by Anyscale Endpoints:
object
,purpose
,status
,status_details
Attributes
id
string - The id of the file.bytes
int | null - The size of the file in bytes or null, if the size is unknown.created_at
string - The date and time of the uploaded file in ISO 8601 format.filename
string - The original name of the uploaded file.
{
"id": "file_123",
"bytes": 123,
"created_at": "2023-09-14T18:00:00Z",
"filename": "train.jsonl"
}