Skip to main content
An OpenAI-compatible Files API for managing batch and fine-tune related files. All endpoints are relative to:
https://api.deepinfra.com/v1/openai
Fine-tuning is not yet supported.
Currently the only API that uses files is the Batch API, which accepts files of up to 200 MB.

Objects

The FileObject

Most file endpoints return a FileObject describing an uploaded file.
FieldTypeDescription
idstringThe file identifier, referenced in API endpoints.
objectstringThe object type, always "file".
bytesintegerThe size of the file, in bytes.
created_atintegerUnix timestamp (in seconds) for when the file was created.
expires_atintegerUnix timestamp (in seconds) for when the file will be deleted.
filenamestringThe name of the file.
purposestringThe intended purpose of the file. One of "batch", "fine-tune", or "batch-output".
{
  "id": "file_abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1680202602,
  "filename": "requests.jsonl",
  "purpose": "batch"
}

Create file

POST /files
Creates a file used in other API endpoints. Creating a file requires the following parameters:
The file to be uploaded.
The intended purpose of the file. Can be "batch" or "fine-tune" for upload, but only "batch" is currently supported.
Controls how long the file remains available. An object with two fields:
  • anchor (optional) — must be "created_at". The expiry is measured from when the file is created. Defaults to "created_at".
  • seconds (optional) — the number of seconds the file stays available after the anchor. An integer between 3600 (1 hour) and 2592000 (30 days). Defaults to 2592000 (30 days).
This endpoint returns a FileObject.
from openai import OpenAI

client = OpenAI(
    api_key="$DEEPINFRA_TOKEN",
    base_url="https://api.deepinfra.com/v1/openai",
)

file = client.files.create(
    file=open("requests.jsonl", "rb"),
    purpose="batch",
    expires_after={"anchor": "created_at", "seconds": 604800},
)
print(file.id)
{
  "id": "file_abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1678215402,
  "filename": "requests.jsonl",
  "purpose": "batch"
}

List files

GET /files
Listing files requires the following parameters:
A pagination cursor. The returned list starts from the object right after the file with this id. If omitted, the list starts from the first file.
An integer between 1 and 10000. The returned list will have at most limit elements. Defaults to 10000.
Sort order by created_at, either "asc" (ascending) or "desc" (descending).
Only returns files of the given purpose. If omitted, files are not filtered by purpose.
The returned object has the following fields:
FieldTypeDescription
objectstringThe object type, always "list".
dataarrayA list of FileObject.
first_idstringThe id of the first file in the list.
last_idstringThe id of the last file in the list.
has_morebooleantrue if there are more files after last_id.
files = client.files.list(
    purpose="batch",
    limit=20,
    order="desc",
)
for file in files.data:
    print(file.id, file.filename)
{
  "object": "list",
  "data": [
    {
      "id": "file_abc123",
      "object": "file",
      "bytes": 120000,
      "created_at": 1677610602,
      "expires_at": 1678215402,
      "filename": "requests.jsonl",
      "purpose": "batch"
    },
    {
      "id": "file_def456",
      "object": "file",
      "bytes": 84000,
      "created_at": 1677520000,
      "expires_at": 1678124800,
      "filename": "eval.jsonl",
      "purpose": "batch"
    }
  ],
  "first_id": "file_abc123",
  "last_id": "file_def456",
  "has_more": false
}

Retrieve a file

GET /files/{file_id}
Returns information about a specific file. Retrieving a file requires the following parameters:
The id of the file to retrieve.
This endpoint returns a FileObject.
file = client.files.retrieve("file_abc123")
print(file.id, file.filename)
{
  "id": "file_abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1678215402,
  "filename": "requests.jsonl",
  "purpose": "batch"
}

Retrieve file content

GET /files/{file_id}/content
Returns the content of a specified file. Retrieving file content requires the following parameters:
The id of the file whose content to retrieve.
This endpoint returns the binary response content.
content = client.files.content("file_abc123")
print(content.text)

Delete a file

DELETE /files/{file_id}
Deletes a file and removes it from all storages. Deleting a file requires the following parameters:
The id of the file to delete.
This endpoint returns a FileDeleted object with the following fields:
FieldTypeDescription
idstringThe id of the deleted file.
deletedbooleantrue if the file was deleted.
objectstringThe object type, always "file".
deleted = client.files.delete("file_abc123")
print(deleted.deleted)
{
  "id": "file_abc123",
  "deleted": true,
  "object": "file"
}

File API Limits

LimitValue
Maximum size of a single user-created file512 MB
Maximum file size with purpose = "batch"200 MB
Maximum total file size per user (including response files)2 GB