Skip to main content

/files

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

1. Setup config.yaml​

# for /files endpoints
files_settings:
- custom_llm_provider: azure
api_base: https://exampleopenaiendpoint-production.up.railway.app
api_key: fake-key
api_version: "2023-03-15-preview"
- custom_llm_provider: openai
api_key: os.environ/OPENAI_API_KEY

2. Start LiteLLM PROXY Server​

litellm --config /path/to/config.yaml

## RUNNING on http://0.0.0.0:4000

3. Use OpenAI's /files endpoints​

Upload a File

from openai import OpenAI

client = OpenAI(
api_key="sk-...",
base_url="http://0.0.0.0:4000/v1"
)

client.files.create(
file=wav_data,
purpose="user_data",
extra_body={"custom_llm_provider": "openai"}
)

List Files

from openai import OpenAI

client = OpenAI(
api_key="sk-...",
base_url="http://0.0.0.0:4000/v1"
)

files = client.files.list(extra_body={"custom_llm_provider": "openai"})
print("files=", files)

Retrieve File Information

from openai import OpenAI

client = OpenAI(
api_key="sk-...",
base_url="http://0.0.0.0:4000/v1"
)

file = client.files.retrieve(file_id="file-abc123", extra_body={"custom_llm_provider": "openai"})
print("file=", file)

Delete File

from openai import OpenAI

client = OpenAI(
api_key="sk-...",
base_url="http://0.0.0.0:4000/v1"
)

response = client.files.delete(file_id="file-abc123", extra_body={"custom_llm_provider": "openai"})
print("delete response=", response)

Get File Content

from openai import OpenAI

client = OpenAI(
api_key="sk-...",
base_url="http://0.0.0.0:4000/v1"
)

content = client.files.content(file_id="file-abc123", extra_body={"custom_llm_provider": "openai"})
print("content=", content)

Supported Providers:​

OpenAI​

Azure OpenAI​

Vertex AI​

Swagger API Reference​