Files & vector stores
Upload files and manage vector stores for use with the Assistants API through Prism.
About
Prism proxies the OpenAI Files and Vector Stores APIs. Upload documents for assistant file search, fine-tuning data, or batch processing. Vector stores index uploaded files for semantic retrieval during assistant runs.
Like the Assistants API, files and vector stores are stored on OpenAI’s servers. Use the OpenAI SDK pointed at Prism.
Files
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/files | Upload a file |
| GET | /v1/files | List files |
| GET | /v1/files/{file_id} | Get file metadata |
| GET | /v1/files/{file_id}/content | Download file content |
| DELETE | /v1/files/{file_id} | Delete a file |
Upload a file
from openai import OpenAI
client = OpenAI(
base_url="https://gateway.futureagi.com/v1",
api_key="sk-prism-your-key",
)
# Upload for use with Assistants
file = client.files.create(
file=open("report.pdf", "rb"),
purpose="assistants",
)
print(f"File ID: {file.id}")
print(f"Size: {file.bytes} bytes") curl -X POST https://gateway.futureagi.com/v1/files \
-H "Authorization: Bearer sk-prism-your-key" \
-F file=@report.pdf \
-F purpose=assistants Purpose values
| Purpose | Use case |
|---|---|
assistants | Files for assistant file search and code interpreter |
fine-tune | Training data for fine-tuning |
batch | Input files for batch API calls |
List and manage files
# List all files
files = client.files.list()
for f in files.data:
print(f"{f.id}: {f.filename} ({f.bytes} bytes, purpose={f.purpose})")
# Get file metadata
file = client.files.retrieve("file-abc123")
# Download file content
content = client.files.content("file-abc123")
with open("downloaded.pdf", "wb") as f:
f.write(content.read())
# Delete a file
client.files.delete("file-abc123")
Vector stores
Vector stores index uploaded files for semantic search. They’re used with the Assistants API file_search tool.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/vector_stores | Create vector store |
| GET | /v1/vector_stores | List vector stores |
| GET | /v1/vector_stores/{id} | Get vector store |
| POST | /v1/vector_stores/{id} | Update vector store |
| DELETE | /v1/vector_stores/{id} | Delete vector store |
| POST | /v1/vector_stores/{id}/search | Search a vector store |
| POST | /v1/vector_stores/{id}/files | Add file to vector store |
| GET | /v1/vector_stores/{id}/files | List files in vector store |
| DELETE | /v1/vector_stores/{id}/files/{file_id} | Remove file from vector store |
| POST | /v1/vector_stores/{id}/file_batches | Batch add files |
Create a vector store and add files
# Create a vector store
vector_store = client.beta.vector_stores.create(
name="Product Documentation",
)
print(f"Vector store: {vector_store.id}")
# Upload and add a file
file = client.files.create(
file=open("docs.pdf", "rb"),
purpose="assistants",
)
client.beta.vector_stores.files.create(
vector_store_id=vector_store.id,
file_id=file.id,
)
Batch upload
Add multiple files at once:
# Upload several files
file_ids = []
for path in ["chapter1.pdf", "chapter2.pdf", "chapter3.pdf"]:
f = client.files.create(file=open(path, "rb"), purpose="assistants")
file_ids.append(f.id)
# Batch add to vector store
batch = client.beta.vector_stores.file_batches.create(
vector_store_id=vector_store.id,
file_ids=file_ids,
)
print(f"Batch status: {batch.status}")
Search a vector store
Search indexed files directly (outside of an assistant run):
results = client.beta.vector_stores.search(
vector_store_id=vector_store.id,
query="return policy",
)
for result in results.data:
print(f"Score: {result.score:.4f}")
print(f"Content: {result.content[0].text[:200]}")
print()
Use with an assistant
Attach a vector store to an assistant for automatic file search during runs:
assistant = client.beta.assistants.create(
name="Support Agent",
instructions="Answer questions using the product documentation.",
model="gpt-4o",
tools=[{"type": "file_search"}],
tool_resources={
"file_search": {
"vector_store_ids": [vector_store.id],
}
},
)
See Assistants API for the full assistant workflow.
Manage vector stores
# List vector stores
stores = client.beta.vector_stores.list()
for vs in stores.data:
print(f"{vs.id}: {vs.name} ({vs.file_counts.completed} files)")
# List files in a vector store
files = client.beta.vector_stores.files.list(vector_store_id=vector_store.id)
# Remove a file from a vector store
client.beta.vector_stores.files.delete(
vector_store_id=vector_store.id,
file_id="file-abc123",
)
# Delete a vector store
client.beta.vector_stores.delete(vector_store.id)
Supported file types
| Category | Formats |
|---|---|
| Documents | .pdf, .docx, .txt, .md, .html |
| Code | .py, .js, .ts, .java, .c, .cpp, .rb, .go, .rs |
| Data | .csv, .json, .jsonl |
| Presentations | .pptx |
Max file size: 512 MB. Max files per vector store: 10,000.