Portkey supports managing files in two ways:
  1. Provider Files: Uploading and managing files directly to any provider using the unified signature
  2. Portkey Files: Uploading files to Portkey and using them for batching/fine-tuning requests with any provider

1. Provider Files

Upload and manage files directly to providers (OpenAI, Bedrock, etc.) using Portkey’s unified API signature. This approach is useful when you need provider-specific file features or want to manage files directly on the provider’s platform.

Supported Providers

Quick Example

curl -X POST https://api.portkey.ai/v1/files \
  -H "Authorization: Bearer $PORTKEY_API_KEY" \
  -H "x-portkey-provider: openai" \
  -F "purpose=fine-tune" \
  -F "file=@training_data.jsonl"

2. Portkey Files

Upload files to Portkey and reuse them for batching inference with any provider and fine-tuning with supported providers. This approach is ideal for:
  • Testing your data with different foundation models
  • Performing A/B testing across multiple providers
  • Batch inference with provider-agnostic file management
  • Reusing the same file across multiple batch jobs

File Requirements

  • Format: JSONL files where each line contains a single request payload

Uploading Files

curl -X POST https://api.portkey.ai/v1/files \
  -H "Authorization: Bearer $PORTKEY_API_KEY" \
  -F "purpose=batch" \
  -F "file=@batch_data.jsonl"

Listing Files

curl -X GET https://api.portkey.ai/v1/files \
  -H "Authorization: Bearer $PORTKEY_API_KEY"

Get File Details

curl -X GET https://api.portkey.ai/v1/files/{file_id} \
  -H "Authorization: Bearer $PORTKEY_API_KEY"

Get File Content

curl -X GET https://api.portkey.ai/v1/files/{file_id}/content \
  -H "Authorization: Bearer $PORTKEY_API_KEY"

File Format Examples

Batch Inference JSONL Format

Each line should be a valid JSON object representing a single request:
{"custom_id": "request-1", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}
{"custom_id": "request-2", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-3.5-turbo-0125", "messages": [{"role": "system", "content": "You are an unhelpful assistant."},{"role": "user", "content": "Hello world!"}],"max_tokens": 1000}}

Fine-tuning JSONL Format

For fine-tuning, each line should contain training examples:
{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi! How can I help you today?"}]}
{"messages": [{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What's 2+2?"}, {"role": "assistant", "content": "2+2 equals 4."}]}

Security & Best Practices

  • Encryption: Files are encrypted at rest using AES-256
  • Access Control: File access is gated by workspace permissions
  • Provider Upload: Portkey uploads files to providers using least-privilege credentials