Implementation:Openai Openai node VectorStore Files
| Knowledge Sources | |
|---|---|
| Domains | SDK, Vector_Stores, File_Management |
| Last Updated | 2026-02-15 12:00 GMT |
Overview
The Files resource class provides methods for managing individual files within an OpenAI vector store, including creating, retrieving, updating, listing, deleting, uploading, polling, and reading file content.
Description
The Files class extends APIResource and represents the individual file management layer within a vector store. Each file attached to a vector store is asynchronously processed for embedding and indexing, and this class provides both the low-level CRUD endpoints and higher-level convenience methods for common workflows.
The core API methods (create, retrieve, update, list, delete, content) map directly to the OpenAI REST API endpoints under /vector_stores/{id}/files. The update method allows modifying file attributes after attachment, and the content method retrieves the parsed text content of a processed file.
The convenience methods (createAndPoll, poll, upload, uploadAndPoll) simplify asynchronous workflows. The poll method loops until a file reaches a terminal status (completed or failed), respecting a configurable or server-suggested polling interval. The upload method first uploads a file to the Files API with purpose assistants and then attaches it to the vector store. All endpoints include the OpenAI-Beta: assistants=v2 header.
Usage
Use this resource when you need to manage individual files within a vector store -- attaching new files, checking their processing status, reading their parsed content, or removing them. For bulk file operations, use the related FileBatches resource instead.
Code Reference
Source Location
- Repository: openai-node
- File: src/resources/vector-stores/files.ts
Signature
class Files extends APIResource {
create(vectorStoreID: string, body: FileCreateParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
retrieve(fileID: string, params: FileRetrieveParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
update(fileID: string, params: FileUpdateParams, options?: RequestOptions): APIPromise<VectorStoreFile>;
list(vectorStoreID: string, query?: FileListParams, options?: RequestOptions): PagePromise<VectorStoreFilesPage, VectorStoreFile>;
delete(fileID: string, params: FileDeleteParams, options?: RequestOptions): APIPromise<VectorStoreFileDeleted>;
createAndPoll(vectorStoreId: string, body: FileCreateParams, options?: RequestOptions & { pollIntervalMs?: number }): Promise<VectorStoreFile>;
poll(vectorStoreID: string, fileID: string, options?: RequestOptions & { pollIntervalMs?: number }): Promise<VectorStoreFile>;
upload(vectorStoreId: string, file: Uploadable, options?: RequestOptions): Promise<VectorStoreFile>;
uploadAndPoll(vectorStoreId: string, file: Uploadable, options?: RequestOptions & { pollIntervalMs?: number }): Promise<VectorStoreFile>;
content(fileID: string, params: FileContentParams, options?: RequestOptions): PagePromise<FileContentResponsesPage, FileContentResponse>;
}
Import
import OpenAI from 'openai';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| vectorStoreID | string |
Yes | The ID of the vector store. |
| body.file_id | string |
Yes | The File ID to attach to the vector store. |
| body.attributes | number | boolean> | null | No | Up to 16 key-value metadata pairs. |
| body.chunking_strategy | FileChunkingStrategyParam |
No | Chunking strategy: auto or static.
|
| params.vector_store_id | string |
Yes | Vector store ID (used for retrieve, update, delete, content). |
| query.filter | 'completed' | 'failed' | 'cancelled' | No | Filter files by processing status. |
| query.order | 'desc' | No | Sort order by created_at.
|
| options.pollIntervalMs | number |
No | Custom poll interval in ms (default: 5000 or server-suggested). |
Outputs
| Name | Type | Description |
|---|---|---|
| id | string |
The vector store file identifier. |
| created_at | number |
Unix timestamp (seconds) when the file was created. |
| status | 'completed' | 'cancelled' | 'failed' | Processing status. |
| usage_bytes | number |
Total bytes used by the file in the vector store. |
| vector_store_id | string |
The parent vector store ID. |
| last_error | null | Error details if processing failed. |
| attributes | number | boolean> | null | Metadata key-value pairs. |
| chunking_strategy | FileChunkingStrategy |
The chunking strategy used for the file. |
Usage Examples
import OpenAI from 'openai';
import fs from 'fs';
const client = new OpenAI();
// Upload a file and poll until it is fully processed
const file = await client.vectorStores.files.uploadAndPoll(
'vs_abc123',
fs.createReadStream('knowledge-base.pdf'),
);
console.log(file.status); // 'completed'
// Retrieve file details
const fileInfo = await client.vectorStores.files.retrieve(
'vsfile_abc123',
{ vector_store_id: 'vs_abc123' },
);
// Update file attributes
await client.vectorStores.files.update(
'vsfile_abc123',
{ vector_store_id: 'vs_abc123', attributes: { category: 'legal', priority: 1 } },
);
// List all completed files in a vector store
const completedFiles = await client.vectorStores.files.list(
'vs_abc123',
{ filter: 'completed', order: 'desc' },
);
// Read parsed content of a processed file
const content = await client.vectorStores.files.content(
'vsfile_abc123',
{ vector_store_id: 'vs_abc123' },
);
// Delete a file from the vector store (does not delete the underlying file)
await client.vectorStores.files.delete(
'vsfile_abc123',
{ vector_store_id: 'vs_abc123' },
);