Skip to main content
POST
/
v1
/
vector_stores
/
{vector_store_id}
/
files
from openai import OpenAI
client = OpenAI()

# Add file to vector store
vector_store_file = client.beta.vector_stores.files.create(
    vector_store_id="vs_abc123",
    file_id="file-abc123"
)

print(vector_store_file.id, vector_store_file.status)

# List files in vector store
files = client.beta.vector_stores.files.list(
    vector_store_id="vs_abc123"
)

for file in files:
    print(file.id, file.status)

# Upload and attach file in one step
vector_store_file = client.beta.vector_stores.files.upload(
    vector_store_id="vs_abc123",
    file=open("mydata.pdf", "rb")
)
{
  "id": "file-abc123",
  "object": "vector_store.file",
  "usage_bytes": 1234,
  "created_at": 1699061776,
  "vector_store_id": "vs_abc123",
  "status": "in_progress",
  "last_error": null,
  "chunking_strategy": {
    "type": "auto"
  }
}
Create a vector store file by attaching a File to a vector store.

Path Parameters

vector_store_id
string
required
The ID of the vector store.

Request Body

file_id
string
required
A File ID that the vector store should use. Useful for tools like file_search that can access files.
chunking_strategy
object
The chunking strategy used to chunk the file(s). If not set, will use the auto strategy.
attributes
object
Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format.Keys are strings with a maximum length of 64 characters. Values can be strings (max 512 characters), booleans, or numbers.

Response

Returns a VectorStoreFile object.
id
string
The identifier of the vector store file.
object
string
The object type, always vector_store.file.
vector_store_id
string
The ID of the vector store that the file is attached to.
status
string
The status of the vector store file. One of:
  • in_progress
  • completed
  • cancelled
  • failed
created_at
integer
The Unix timestamp (in seconds) for when the vector store file was created.

List Vector Store Files

GET https://api.openai.com/v1/vector_stores/{vector_store_id}/files Returns a list of vector store files.

Query Parameters

limit
integer
default:"20"
A limit on the number of objects to be returned. Limit can range between 1 and 100.
order
string
default:"desc"
Sort order by the created_at timestamp. asc for ascending order and desc for descending order.
after
string
A cursor for use in pagination.
before
string
A cursor for use in pagination.
filter
string
Filter by file status. One of in_progress, completed, failed, cancelled.

Retrieve Vector Store File

GET https://api.openai.com/v1/vector_stores/{vector_store_id}/files/{file_id} Retrieves a vector store file.

Delete Vector Store File

DELETE https://api.openai.com/v1/vector_stores/{vector_store_id}/files/{file_id} Delete a vector store file. This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the delete file endpoint.
from openai import OpenAI
client = OpenAI()

# Add file to vector store
vector_store_file = client.beta.vector_stores.files.create(
    vector_store_id="vs_abc123",
    file_id="file-abc123"
)

print(vector_store_file.id, vector_store_file.status)

# List files in vector store
files = client.beta.vector_stores.files.list(
    vector_store_id="vs_abc123"
)

for file in files:
    print(file.id, file.status)

# Upload and attach file in one step
vector_store_file = client.beta.vector_stores.files.upload(
    vector_store_id="vs_abc123",
    file=open("mydata.pdf", "rb")
)
{
  "id": "file-abc123",
  "object": "vector_store.file",
  "usage_bytes": 1234,
  "created_at": 1699061776,
  "vector_store_id": "vs_abc123",
  "status": "in_progress",
  "last_error": null,
  "chunking_strategy": {
    "type": "auto"
  }
}

Build docs developers (and LLMs) love