litellm-mirror/docs/my-website/docs/files_endpoints.md
2024-12-24 20:46:43 -08:00

2.3 KiB

import TabItem from '@theme/TabItem'; import Tabs from '@theme/Tabs';

Files API

Files are used to upload documents that can be used with features like Assistants, Fine-tuning, and Batch API.

Quick Start

  • Upload a File
  • List Files
  • Retrieve File Information
  • Delete File
  • Get File Content
$ export OPENAI_API_KEY="sk-..."

$ litellm

# RUNNING on http://0.0.0.0:4000

Upload a File

curl http://localhost:4000/v1/files \
  -H "Authorization: Bearer sk-1234" \
  -F purpose="fine-tune" \
  -F file="@mydata.jsonl"

List Files

curl http://localhost:4000/v1/files \
  -H "Authorization: Bearer sk-1234"

Retrieve File Information

curl http://localhost:4000/v1/files/file-abc123 \
  -H "Authorization: Bearer sk-1234"

Delete File

curl http://localhost:4000/v1/files/file-abc123 \
  -X DELETE \
  -H "Authorization: Bearer sk-1234"

Get File Content

curl http://localhost:4000/v1/files/file-abc123/content \
  -H "Authorization: Bearer sk-1234"

Upload a File

from litellm
import os 

os.environ["OPENAI_API_KEY"] = "sk-.."

file_obj = await litellm.acreate_file(
    file=open("mydata.jsonl", "rb"),
    purpose="fine-tune",
    custom_llm_provider="openai",
)
print("Response from creating file=", file_obj)

List Files

files = await litellm.alist_files(
    custom_llm_provider="openai",
    limit=10
)
print("files=", files)

Retrieve File Information

file = await litellm.aretrieve_file(
    file_id="file-abc123",
    custom_llm_provider="openai"
)
print("file=", file)

Delete File

response = await litellm.adelete_file(
    file_id="file-abc123",
    custom_llm_provider="openai"
)
print("delete response=", response)

Get File Content

content = await litellm.afile_content(
    file_id="file-abc123",
    custom_llm_provider="openai"
)
print("file content=", content)

Supported Providers:

OpenAI

Azure OpenAI

Vertex AI

Swagger API Reference