Implementation:BerriAI Litellm Create File
| Knowledge Sources | Domains | Last Updated |
|---|---|---|
| BerriAI/litellm | File Management, API Integration, Cloud Storage | 2026-02-15 |
Overview
Concrete tool for uploading training and other data files to LLM providers provided by LiteLLM.
Description
The create_file function in LiteLLM provides a unified interface for uploading files to multiple LLM providers including OpenAI, Azure OpenAI, Vertex AI, Gemini, Bedrock, hosted vLLM, and Manus. It accepts a file object, a purpose tag (such as "fine-tune"), and a provider specification, then routes the upload to the appropriate provider-specific handler. The function handles API base resolution, credential lookup, timeout configuration, and response normalization, returning a standardized OpenAIFileObject regardless of the underlying provider. Both synchronous and asynchronous execution modes are supported.
Usage
Use create_file when:
- Uploading a JSONL training file before creating a fine-tuning job.
- Uploading files for the Assistants API or Batch API.
- Needing a single function call that works across OpenAI, Azure, Vertex AI, Bedrock, and other supported providers.
Code Reference
Source Location
litellm/files/main.py (lines 60-292)
Signature
# Async version
async def acreate_file(
file: FileTypes,
purpose: Literal["assistants", "batch", "fine-tune"],
expires_after: Optional[FileExpiresAfter] = None,
custom_llm_provider: Literal[
"openai", "azure", "gemini", "vertex_ai", "bedrock", "hosted_vllm", "manus"
] = "openai",
extra_headers: Optional[Dict[str, str]] = None,
extra_body: Optional[Dict[str, str]] = None,
**kwargs,
) -> OpenAIFileObject:
# Sync version
def create_file(
file: FileTypes,
purpose: Literal["assistants", "batch", "fine-tune"],
expires_after: Optional[FileExpiresAfter] = None,
custom_llm_provider: Optional[Literal[
"openai", "azure", "gemini", "vertex_ai", "bedrock", "hosted_vllm", "manus"
]] = None,
extra_headers: Optional[Dict[str, str]] = None,
extra_body: Optional[Dict[str, str]] = None,
**kwargs,
) -> Union[OpenAIFileObject, Coroutine[Any, Any, OpenAIFileObject]]:
Import
from litellm.files.main import create_file, acreate_file
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
| file | FileTypes |
Yes | The file content to upload. Accepts file-like objects, tuples of (filename, content), or bytes. |
| purpose | Literal["assistants", "batch", "fine-tune"] |
Yes | The intended purpose of the file. Use "fine-tune" for training data. |
| expires_after | Optional[FileExpiresAfter] |
No | Expiration policy for the uploaded file. |
| custom_llm_provider | Optional[Literal["openai", "azure", "gemini", "vertex_ai", "bedrock", "hosted_vllm", "manus"]] |
No | The LLM provider to upload to. Defaults to "openai". |
| extra_headers | Optional[Dict[str, str]] |
No | Additional HTTP headers to include in the upload request. |
| extra_body | Optional[Dict[str, str]] |
No | Additional fields to include in the request body. |
| **kwargs | various | No | Additional parameters including api_key, api_base, timeout, and provider-specific options.
|
Outputs
| Return Type | Description |
|---|---|
OpenAIFileObject |
A normalized file object containing the file ID, filename, purpose, bytes count, creation timestamp, and status. For sync calls, may return a Coroutine if called from an async context internally.
|
Usage Examples
Upload a training file to OpenAI
from litellm.files.main import create_file
# Upload a JSONL training file
file_object = create_file(
file=open("training_data.jsonl", "rb"),
purpose="fine-tune",
custom_llm_provider="openai",
)
print(file_object.id) # e.g., "file-abc123"
print(file_object.purpose) # "fine-tune"
print(file_object.filename) # "training_data.jsonl"
Async upload to Azure OpenAI
import asyncio
from litellm.files.main import acreate_file
async def upload_training_data():
file_object = await acreate_file(
file=open("training_data.jsonl", "rb"),
purpose="fine-tune",
custom_llm_provider="azure",
api_base="https://my-resource.openai.azure.com/",
api_key="my-azure-api-key",
api_version="2024-02-01",
)
return file_object
result = asyncio.run(upload_training_data())
print(result.id)
Upload to Vertex AI
from litellm.files.main import create_file
file_object = create_file(
file=open("training_data.jsonl", "rb"),
purpose="fine-tune",
custom_llm_provider="vertex_ai",
vertex_project="my-gcp-project",
vertex_location="us-central1",
)
print(file_object.id)