A unified, provider-agnostic chat completions API server supporting OpenAI and AWS Bedrock
The Open Bedrock Server Server provides a comprehensive OpenAI-compatible file management API with S3 backend storage. This allows you to upload, manage, and use files in your chat completions for enhanced AI interactions.
POST /v1/files
Content-Type: multipart/form-data
file: <file_data>
purpose: <purpose_string>
GET /v1/files?purpose=<purpose>&limit=<limit>
GET /v1/files/{file_id}
GET /v1/files/{file_id}/content
DELETE /v1/files/{file_id}
POST /v1/chat/completions
Content-Type: application/json
{
"model": "claude-3-sonnet",
"messages": [
{"role": "user", "content": "Analyze the uploaded data"}
],
"file_ids": ["file-abc123", "file-def456"]
}
The file processing service supports automatic text extraction from:
.txt
, .md
, .py
, .js
, .html
.json
, .csv
, .xml
text/plain
, application/json
, text/csv
, application/xml
, text/html
Unsupported file types are stored but won’t be processed for chat completions.
# Required
S3_FILES_BUCKET=your-files-bucket
# AWS Authentication (choose one method)
# Method 1: Static credentials
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
# Method 2: AWS Profile
AWS_PROFILE=your-profile
# Method 3: IAM Role (for EC2/ECS)
AWS_ROLE_ARN=arn:aws:iam::account:role/your-role
AWS_EXTERNAL_ID=your-external-id
# Method 4: Web Identity (for EKS/Fargate)
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
AWS_ROLE_ARN=arn:aws:iam::account:role/your-role
# Optional
AWS_REGION=us-east-1
# Start server with file support
amazon-chat-completions-server \
--s3-files-bucket your-files-bucket \
--aws-region us-east-1 \
--aws-profile your-profile
import requests
# Upload a file
files = {"file": ("data.csv", open("data.csv", "rb"), "text/csv")}
data = {"purpose": "assistants"}
response = requests.post(
"http://localhost:8000/v1/files",
files=files,
data=data,
headers={"Authorization": "Bearer your-api-key"}
)
file_info = response.json()
file_id = file_info["id"]
# Use file in chat completion
chat_request = {
"model": "claude-3-sonnet",
"messages": [
{"role": "user", "content": "Analyze the data in the uploaded CSV file"}
],
"file_ids": [file_id]
}
response = requests.post(
"http://localhost:8000/v1/chat/completions",
json=chat_request,
headers={"Authorization": "Bearer your-api-key"}
)
print(response.json()["choices"][0]["message"]["content"])
# List all files
response = requests.get(
"http://localhost:8000/v1/files",
headers={"Authorization": "Bearer your-api-key"}
)
files = response.json()["data"]
# Get specific file metadata
response = requests.get(
f"http://localhost:8000/v1/files/{file_id}",
headers={"Authorization": "Bearer your-api-key"}
)
file_metadata = response.json()
# Download file content
response = requests.get(
f"http://localhost:8000/v1/files/{file_id}/content",
headers={"Authorization": "Bearer your-api-key"}
)
file_content = response.content
# Delete file
response = requests.delete(
f"http://localhost:8000/v1/files/{file_id}",
headers={"Authorization": "Bearer your-api-key"}
)
curl -X POST "http://localhost:8000/v1/files" \
-H "Authorization: Bearer your-api-key" \
-F "file=@data.json" \
-F "purpose=assistants"
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-sonnet",
"messages": [
{"role": "user", "content": "What insights can you derive from the uploaded data?"}
],
"file_ids": ["file-abc123"]
}'
curl "http://localhost:8000/v1/files?purpose=assistants&limit=10" \
-H "Authorization: Bearer your-api-key"
// Upload file
const formData = new FormData();
formData.append('file', fs.createReadStream('document.txt'));
formData.append('purpose', 'assistants');
const uploadResponse = await fetch('http://localhost:8000/v1/files', {
method: 'POST',
headers: { 'Authorization': 'Bearer your-api-key' },
body: formData
});
const fileInfo = await uploadResponse.json();
// Use in chat completion
const chatResponse = await fetch('http://localhost:8000/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': 'Bearer your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'claude-3-sonnet',
messages: [
{ role: 'user', content: 'Summarize the uploaded document' }
],
file_ids: [fileInfo.id]
})
});
When files are used in chat completions, they undergo automatic processing:
Text File Processing:
=== UPLOADED FILES CONTEXT ===
The following files have been uploaded and their content is provided below for your reference:
=== File: document.txt (ID: file-abc123) ===
This is the content of the text file.
Multiple lines are preserved.
=== END OF FILES CONTEXT ===
Original user message content...
JSON File Processing:
=== File: data.json (ID: file-def456) ===
JSON File: data.json
Object at root with 3 keys:
name: str = "John Doe"
age: int = 30
items: list
JSON Content:
{
"name": "John Doe",
"age": 30,
"items": ["a", "b", "c"]
}
CSV File Processing:
=== File: sales.csv (ID: file-ghi789) ===
CSV File: sales.csv
Headers: date, product, quantity, price
Total rows: 100
Row 0 (Headers): date, product, quantity, price
Row 1: 2024-01-01, Widget A, 10, 29.99
Row 2: 2024-01-02, Widget B, 5, 49.99
... and 97 more rows
{
"id": "file-abc123def456",
"object": "file",
"bytes": 1024,
"created_at": 1234567890,
"filename": "document.txt",
"purpose": "assistants",
"status": "processed"
}
{
"object": "list",
"data": [
{
"id": "file-abc123",
"object": "file",
"bytes": 1024,
"created_at": 1234567890,
"filename": "document.txt",
"purpose": "assistants",
"status": "processed"
}
]
}
{
"id": "file-abc123",
"object": "file",
"deleted": true
}
File Not Found (404):
{
"detail": "File file-nonexistent not found"
}
Invalid File ID Format (422):
{
"detail": "Invalid file ID format: invalid-id. File IDs must start with 'file-'"
}
S3 Configuration Error (500):
{
"detail": "S3_FILES_BUCKET is not configured. Cannot upload files."
}
File Processing Error: Files that fail to process are still stored and usable, but show error context:
=== File: document.pdf (ID: file-abc123) ===
[File content could not be processed: Unsupported file type: application/pdf]
curl "http://localhost:8000/v1/files/health"
Response:
{
"status": "healthy",
"service": "files",
"s3_configured": true
}
purpose
values for organizationFor additional support, check the application logs and AWS CloudWatch for detailed error information.