diff --git a/README.md b/README.md index b7428cc4..2cad8595 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ If you or your business relies on this package, it's important to support the de - [FineTuning Resource](#finetuning-resource) - [Moderations Resource](#moderations-resource) - [Images Resource](#images-resource) - - [Assistants Resource](#assistants-resource) - - [Threads Resource](#threads-resource) - - [Threads Messages Resource](#threads-messages-resource) - - [Threads Runs Resource](#threads-runs-resource) - - [Threads Runs Steps Resource](#threads-runs-steps-resource) - [Vector Stores Resource](#vector-stores-resource) - [Vector Stores Files Resource](#vector-store-files-resource) - [Vector Stores File Batches Resource](#vector-store-file-batches-resource) - [Batches Resource](#batches-resource) - [Realtime Ephemeral Keys](#realtime-ephemeral-keys) + - [Assistants Resource (deprecated)](#assistants-resource-deprecated) + - [Thread Resource (deprecated)](#threads-resource-deprecated) + - [Thread Messages Resource (deprecated)](#threads-messages-resource-deprecated) + - [Thread Runs Resource (deprecated)](#threads-runs-resource-deprecated) + - [Thread Runs Steps Resource (deprecated)](#threads-runs-steps-resource-deprecated) - [FineTunes Resource (deprecated)](#finetunes-resource-deprecated) - [Edits Resource (deprecated)](#edits-resource-deprecated) - [Meta Information](#meta-information) @@ -1049,646 +1049,686 @@ foreach ($response->data as $data) { $response->toArray(); // ['created' => 1589478378, data => ['url' => 'https://oaidalleapiprodscus...', ...]] ``` -### `Assistants` Resource - -> **Note:** If you are creating the client manually from the factory. Make sure you provide the necessary header: -> ```php -> $factory->withHttpHeader('OpenAI-Beta', 'assistants=v2') -> ``` +### `Batches` Resource #### `create` -Create an assistant with a model and instructions. +Creates a batch. ```php -$response = $client->assistants()->create([ - 'instructions' => 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.', - 'name' => 'Math Tutor', - 'tools' => [ - [ - 'type' => 'code_interpreter', - ], - ], - 'model' => 'gpt-4o', -]); - -$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->object; // 'assistant' -$response->createdAt; // 1623936000 -$response->name; // 'Math Tutor' -$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' -$response->model; // 'gpt-4o' -$response->description; // null -$response->tools[0]->type; // 'code_interpreter' -$response->toolResources; // [] -$response->metadata; // [] -$response->temperature: // null -$response->topP: // null -$response->format: // 'auto' - -$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] -``` -#### `retrieve` +$fileResponse = $client->files()->upload( + parameters: [ + 'purpose' => 'batch', + 'file' => fopen('commands.jsonl', 'r'), + ] +); -Retrieves an assistant. +$fileId = $fileResponse->id; -```php -$response = $client->assistants()->retrieve('asst_gxzBkD1wkKEloYqZ410pT5pd'); +$response = $client->batches()->create( + parameters: [ + 'input_file_id' => $fileId, + 'endpoint' => '/v1/chat/completions', + 'completion_window' => '24h' + ] + ); -$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->object; // 'assistant' -$response->createdAt; // 1623936000 -$response->name; // 'Math Tutor' -$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' -$response->model; // 'gpt-4o' -$response->description; // null -$response->tools[0]->type; // 'code_interpreter' -$response->toolResources; // [] -$response->metadata; // [] -$response->temperature: // null -$response->topP: // null -$response->format: // 'auto' +$response->id; // 'batch_abc123' +$response->object; // 'batch' +$response->endpoint; // /v1/chat/completions +$response->errors; // null +$response->completionWindow; // '24h' +$response->status; // 'validating' +$response->outputFileId; // null +$response->errorFileId; // null +$response->createdAt; // 1714508499 +$response->inProgressAt; // null +$response->expiresAt; // 1714536634 +$response->completedAt; // null +$response->failedAt; // null +$response->expiredAt; // null +$response->requestCounts; // null +$response->metadata; // ['name' => 'My batch name'] -$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] +$response->toArray(); // ['id' => 'batch_abc123', ...] ``` -#### `modify` +#### `retrieve` -Modifies an assistant. +Retrieves a batch. ```php -$response = $client->assistants()->modify('asst_gxzBkD1wkKEloYqZ410pT5pd', [ - 'name' => 'New Math Tutor', - ]); +$response = $client->batches()->retrieve(id: 'batch_abc123'); -$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->object; // 'assistant' -$response->createdAt; // 1623936000 -$response->name; // 'New Math Tutor' -$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' -$response->model; // 'gpt-4o' -$response->description; // null -$response->tools[0]->type; // 'code_interpreter' -$response->toolResources; // [] -$response->metadata; // [] -$response->temperature: // null -$response->topP: // null -$response->format: // 'auto' +$response->id; // 'batch_abc123' +$response->object; // 'batch' +$response->endpoint; // /v1/chat/completions +$response->errors; // null +$response->completionWindow; // '24h' +$response->status; // 'validating' +$response->outputFileId; // null +$response->errorFileId; // null +$response->createdAt; // 1714508499 +$response->inProgressAt; // null +$response->expiresAt; // 1714536634 +$response->completedAt; // null +$response->failedAt; // null +$response->expiredAt; // null +$response->requestCounts->total; // 100 +$response->requestCounts->completed; // 95 +$response->requestCounts->failed; // 5 +$response->metadata; // ['name' => 'My batch name'] -$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] +$response->toArray(); // ['id' => 'batch_abc123', ...] ``` -#### `delete` +#### `cancel` -Delete an assistant. +Cancels a batch. ```php -$response = $client->assistants()->delete('asst_gxzBkD1wkKEloYqZ410pT5pd'); +$response = $client->batches()->cancel(id: 'batch_abc123'); -$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->object; // 'assistant.deleted' -$response->deleted; // true +$response->id; // 'batch_abc123' +$response->object; // 'batch' +$response->endpoint; // /v1/chat/completions +$response->errors; // null +$response->completionWindow; // '24h' +$response->status; // 'cancelling' +$response->outputFileId; // null +$response->errorFileId; // null +$response->createdAt; // 1711471533 +$response->inProgressAt; // 1711471538 +$response->expiresAt; // 1711557933 +$response->cancellingAt; // 1711475133 +$response->cancelledAt; // null +$response->requestCounts->total; // 100 +$response->requestCounts->completed; // 23 +$response->requestCounts->failed; // 1 +$response->metadata; // ['name' => 'My batch name'] -$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] +$response->toArray(); // ['id' => 'batch_abc123', ...] ``` #### `list` -Returns a list of assistants. +Returns a list of batches. ```php -$response = $client->assistants()->list([ - 'limit' => 10, -]); +$response = $client->batches()->list( + parameters: [ + 'limit' => 10, + ], +); $response->object; // 'list' -$response->firstId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->lastId; // 'asst_reHHtAM0jKLDIxanM6gP6DaR' +$response->firstId; // 'batch_abc123' +$response->lastId; // 'batch_abc456' $response->hasMore; // true foreach ($response->data as $result) { - $result->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' + $result->id; // 'batch_abc123' // ... } $response->toArray(); // ['object' => 'list', ...]] ``` -### `Threads` Resource +### `Vector Stores` Resource #### `create` -Create a thread. - -```php -$response = $client->threads()->create([]); - -$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->object; // 'thread' -$response->createdAt; // 1623936000 -$response->toolResources; // null -$response->metadata; // [] - -$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] -``` - -#### `createAndRun` - -Create a thread and run it in one request. +Create a vector store. ```php -$response = $client->threads()->createAndRun( - [ - 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', - 'thread' => [ - 'messages' => - [ - [ - 'role' => 'user', - 'content' => 'Explain deep learning to a 5 year old.', - ], - ], - ], +$response = $client->vectorStores()->create([ + 'file_ids' => [ + 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ], -); + 'name' => 'My first Vector Store', +]); -$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->object; // 'thread.run' -$response->createdAt; // 1623936000 -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'queued' -$response->requiredAction; // null -$response->lastError; // null -$response->startedAt; // null -$response->expiresAt; // 1699622335 -$response->cancelledAt; // null -$response->failedAt; // null -$response->completedAt; // null -$response->incompleteDetails; // null -$response->lastError; // null -$response->model; // 'gpt-4o' -$response->instructions; // null -$response->tools; // [] -$response->metadata; // [] -$response->usage->total_tokens; // 579 -$response->temperature; // null -$response->topP; // null -$response->maxPromptTokens; // 1000 -$response->maxCompletionTokens; // 1000 -$response->truncationStrategy->type; // 'auto' -$response->responseFormat; // 'auto' -$response->toolChoice; // 'auto' +$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->object; // 'vector_store' +$response->createdAt; // 1717703267 +$response->name; // 'My first Vector Store' +$response->usageBytes; // 0 +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 +$response->status; // 'in_progress' +$response->expiresAfter; // null +$response->expiresAt; // null +$response->lastActiveAt; // 1717703267 -$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] +$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] ``` #### `retrieve` -Retrieves a thread. +Retrieves a vector store. ```php -$response = $client->threads()->retrieve('thread_tKFLqzRN9n7MnyKKvc1Q7868'); +$response = $client->vectorStores()->retrieve( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', +); -$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->object; // 'thread' -$response->createdAt; // 1623936000 -$response->toolResources; // null -$response->metadata; // [] +$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->object; // 'vector_store' +$response->createdAt; // 1717703267 +$response->name; // 'My first Vector Store' +$response->usageBytes; // 0 +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 +$response->status; // 'in_progress' +$response->expiresAfter; // null +$response->expiresAt; // null +$response->lastActiveAt; // 1717703267 -$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] +$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] ``` #### `modify` -Modifies a thread. +Modifies a vector store. ```php -$response = $client->threads()->modify('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ - 'metadata' => [ - 'name' => 'My new thread name', - ], - ]); +$response = $client->vectorStores()->modify( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + parameters: [ + 'name' => 'New name', + ], +); -$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->object; // 'thread' -$response->createdAt; // 1623936000 -$response->toolResources; // null -$response->metadata; // ['name' => 'My new thread name'] +$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->object; // 'vector_store' +$response->createdAt; // 1717703267 +$response->name; // 'New name' +$response->usageBytes; // 0 +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 +$response->status; // 'in_progress' +$response->expiresAfter; // null +$response->expiresAt; // null +$response->lastActiveAt; // 1717703267 -$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] +$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] ``` #### `delete` -Delete a thread. +Delete a vector store. ```php -$response = $client->threads()->delete('thread_tKFLqzRN9n7MnyKKvc1Q7868'); +$response = $client->vectorStores()->delete( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', +); -$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->object; // 'thread.deleted' +$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->object; // 'vector_store.deleted' $response->deleted; // true -$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] +$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] ``` -### `Threads Messages` Resource - -#### `create` +#### `list` -Create a message. +Returns a list of vector stores. ```php -$response = $client->threads()->messages()->create('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ - 'role' => 'user', - 'content' => 'What is the sum of 5 and 7?', -]); +$response = $client->vectorStores()->list( + parameters: [ + 'limit' => 10, + ], +); -$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->object; // 'thread.message' -$response->createdAt; // 1623936000 -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'in_progress -$response->incompleteDetails; // null -$response->completedAt; // null -$response->incompleteAt; // null -$response->role; // 'user' -$response->content[0]->type; // 'text' -$response->content[0]->text->value; // 'What is the sum of 5 and 7?' -$response->content[0]->text->annotations; // [] -$response->assistantId; // null -$response->runId; // null -$response->attachments; // [] -$response->metadata; // [] +$response->object; // 'list' +$response->firstId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->lastId; // 'vs_D5DPOgBxSoEBTmYBgUESdPpa' +$response->hasMore; // true -$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] +foreach ($response->data as $result) { + $result->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' + // ... +} + +$response->toArray(); // ['object' => 'list', ...]] ``` -#### `retrieve` +### `Vector Store Files` Resource -Retrieve a message. +#### `create` + +Create a vector store file by attaching a File to a vector store. ```php -$response = $client->threads()->messages()->retrieve( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU', +$response = $client->vectorStores()->files()->create( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + parameters: [ + 'file_id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', + ] ); -$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->object; // 'thread.message' -$response->createdAt; // 1623936000 -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'in_progress -$response->incompleteDetails; // null -$response->completedAt; // null -$response->incompleteAt; // null -$response->role; // 'user' -$response->content[0]->type; // 'text' -$response->content[0]->text->value; // 'What is the sum of 5 and 7?' -$response->content[0]->text->annotations; // [] -$response->assistantId; // null -$response->runId; // null -$response->attachments; // [] -$response->metadata; // [] +$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' +$response->object; // 'vector_store.file' +$response->usageBytes; // 4553 +$response->createdAt; // 1717703267 +$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->status; // 'completed' +$response->lastError; // null +$response->chunkingStrategy->type; // 'static' +$response->chunkingStrategy->maxChunkSizeTokens; // 800 +$response->chunkingStrategy->chunkOverlapTokens; // 400 -$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] +$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] ``` -#### `modify` +#### `retrieve` -Modifies a message. +Retrieves a vector store file. ```php -$response = $client->threads()->messages()->modify( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU', - parameters: [ - 'metadata' => [ - 'name' => 'My new message name', - ], - ], +$response = $client->vectorStores()->files()->retrieve( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + fileId: 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ); -$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->object; // 'thread.message' -$response->createdAt; // 1623936000 -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'in_progress -$response->incompleteDetails; // null -$response->completedAt; // null -$response->incompleteAt; // null -$response->role; // 'user' -$response->content[0]->type; // 'text' -$response->content[0]->text->value; // 'What is the sum of 5 and 7?' -$response->content[0]->text->annotations; // [] -$response->assistantId; // null -$response->runId; // null -$response->attachments; // [] -$response->metadata; // ['name' => 'My new message name'] +$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' +$response->object; // 'vector_store.file' +$response->usageBytes; // 4553 +$response->createdAt; // 1717703267 +$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->status; // 'completed' +$response->lastError; // null +$response->chunkingStrategy->type; // 'static' +$response->chunkingStrategy->maxChunkSizeTokens; // 800 +$response->chunkingStrategy->chunkOverlapTokens; // 400 -$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] +$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] ``` #### `delete` -Deletes a message. +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. ```php -$response = $client->threads()->messages()->delete( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response = $client->vectorStores()->files()->delete( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + fileId: 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ); -$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->object; // 'thread.message.deleted' +$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' +$response->object; // 'vector_store.file.deleted' $response->deleted; // true -$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] +$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] ``` #### `list` -Returns a list of messages for a given thread. +Returns a list of vector store files. ```php -$response = $client->threads()->messages()->list('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ - 'limit' => 10, -]); +$response = $client->vectorStores()->files()->list( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + parameters: [ + 'limit' => 10, + ], +); $response->object; // 'list' -$response->firstId; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->lastId; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' -$response->hasMore; // false +$response->firstId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' +$response->lastId; // 'file-D5DPOgBxSoEBTmYBgUESdPpa' +$response->hasMore; // true foreach ($response->data as $result) { - $result->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' + $result->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' // ... } $response->toArray(); // ['object' => 'list', ...]] ``` -### `Threads Runs` Resource - -#### `create` +#### `search` -Create a run. +Search a vector store for relevant chunks based on a query and file attributes filter. ```php -$response = $client->threads()->runs()->create( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', +$response = $client->vectorStores()->search( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', parameters: [ - 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', - ], + 'query' => 'What is the return policy?', + 'max_num_results' => 5, + 'filters' => [], + 'rewrite_query' => false + ] ); -$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->object; // 'thread.run' -$response->createdAt; // 1623936000 -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'queued' -$response->startedAt; // null -$response->expiresAt; // 1699622335 -$response->cancelledAt; // null -$response->failedAt; // null -$response->completedAt; // null -$response->incompleteDetails; // null -$response->lastError; // null -$response->model; // 'gpt-4o' -$response->instructions; // null -$response->tools; // [] -$response->metadata; // [] -$response->usage->total_tokens; // 579 -$response->temperature; // null -$response->topP; // null -$response->maxPromptTokens; // 1000 -$response->maxCompletionTokens; // 1000 -$response->truncationStrategy->type; // 'auto' -$response->toolChoice; // 'auto' -$response->responseFormat; // 'auto' +$response->object; // 'vector_store.search_results.page' +$response->searchQuery; // 'What is the return policy?' +$response->hasMore; // false +$response->nextPage; // null +foreach ($response->data as $file) { + $result->fileId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' + $result->filename; // 'return_policy.pdf' + $result->score; // 0.95 + $result->attributes; // ['category' => 'customer_service'] -$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] + foreach ($result->content as $content) { + $content->type; // 'text' + $content->text; // 'Our return policy allows customers to return items within 30 days...' + } +} + +$response->toArray(); // ['object' => 'vector_store.search_results.page', ...] ``` -#### `create streamed` +### `Vector Store File Batches` Resource -Creates a streamed run. +#### `create` -[OpenAI Assistant Events](https://platform.openai.com/docs/api-reference/assistants-streaming/events) +Create a vector store file batch. ```php -$stream = $client->threads()->runs()->createStreamed( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', +$response = $client->vectorStores()->batches()->create( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', parameters: [ - 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', - ], + 'file_ids' => [ + 'file-fUU0hFRuQ1GzhOweTNeJlCXG', + ], + ] ); -foreach($stream as $response){ - $response->event // 'thread.run.created' | 'thread.run.in_progress' | ..... - $response->response // ThreadResponse | ThreadRunResponse | ThreadRunStepResponse | ThreadRunStepDeltaResponse | ThreadMessageResponse | ThreadMessageDeltaResponse -} +$response->id; // 'vsfb_123' +$response->object; // 'vector_store.files_batch' +$response->createdAt; // 1698107661 +$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->status; // 'completed' +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 -// ... +$response->toArray(); // ['id' => 'vsfb_123', ...] ``` -#### `create streamed with function calls` +#### `retrieve` -Creates a streamed run with function calls +Retrieves a vector store file batch. -[OpenAI Assistant Events](https://platform.openai.com/docs/api-reference/assistants-streaming/events) +```php +$response = $client->vectorStores()->batches()->retrieve( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + fileBatchId: 'vsfb_123', +); + +$response->id; // 'vsfb_123' +$response->object; // 'vector_store.files_batch' +$response->createdAt; // 1698107661 +$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->status; // 'completed' +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 + +$response->toArray(); // ['id' => 'vsfb_123', ...] +``` + +#### `cancel` + +Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. ```php -$stream = $client->threads()->runs()->createStreamed( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', +$response = $client->vectorStores()->batches()->cancel( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + fileBatchId: 'vsfb_123', +); + +$response->id; // 'vsfb_123' +$response->object; // 'vector_store.files_batch' +$response->createdAt; // 1698107661 +$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->status; // 'cancelling' +$response->fileCounts->inProgress; // 1 +$response->fileCounts->completed; // 0 +$response->fileCounts->failed; // 0 +$response->fileCounts->cancelled; // 0 +$response->fileCounts->total; // 1 + +$response->toArray(); // ['id' => 'vsfb_123', ...] +``` + +#### `list` + +Returns a list of vector store files. + +```php +$response = $client->vectorStores()->batches()->listFiles( + vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', + fileBatchId: 'vsfb_123', parameters: [ - 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', + 'limit' => 10, ], ); +$response->object; // 'list' +$response->firstId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' +$response->lastId; // 'file-D5DPOgBxSoEBTmYBgUESdPpa' +$response->hasMore; // true -do{ - foreach($stream as $response){ - $response->event // 'thread.run.created' | 'thread.run.in_progress' | ..... - $response->response // ThreadResponse | ThreadRunResponse | ThreadRunStepResponse | ThreadRunStepDeltaResponse | ThreadMessageResponse | ThreadMessageDeltaResponse +foreach ($response->data as $result) { + $result->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' + // ... +} - switch($response->event){ - case 'thread.run.created': - case 'thread.run.queued': - case 'thread.run.completed': - case 'thread.run.cancelling': - $run = $response->response; - break; - case 'thread.run.expired': - case 'thread.run.cancelled': - case 'thread.run.failed': - $run = $response->response; - break 3; - case 'thread.run.requires_action': - // Overwrite the stream with the new stream started by submitting the tool outputs - $stream = $client->threads()->runs()->submitToolOutputsStreamed( - threadId: $run->threadId, - runId: $run->id, - parameters: [ - 'tool_outputs' => [ - [ - 'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj', - 'output' => '12', - ] - ], - ] - ); - break; - } - } -} while ($run->status != "completed") +$response->toArray(); // ['object' => 'list', ...]] +``` -// ... +### Realtime Ephemeral Keys + +#### `token` + +Create an ephemeral API token for real time sessions. + +```php +$response = $client->realtime()->token(); + +$response->clientSecret->value // 'ek-1234567890abcdefg' +$response->clientSecret->expiresAt // 1717703267 +``` + +#### `transcribeToken` + +Create an ephemeral API token for real time transcription sessions. + +```php +$response = $client->realtime()->transcribeToken(); + +$response->clientSecret->value // 'et-1234567890abcdefg' +$response->clientSecret->expiresAt // 1717703267 +``` + +### `Assistants` Resource (deprecated) + +> [!WARNING] +> OpenAI has deprecated the Assistants API and will stop working by first half of 2026. https://platform.openai.com/docs/guides/responses-vs-chat-completions#assistants + +> [!NOTE] +> If you are creating the client manually from the factory. Make sure you provide the necessary header: +> ```php +> $factory->withHttpHeader('OpenAI-Beta', 'assistants=v2') +> ``` + +#### `create` + +Create an assistant with a model and instructions. + +```php +$response = $client->assistants()->create([ + 'instructions' => 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.', + 'name' => 'Math Tutor', + 'tools' => [ + [ + 'type' => 'code_interpreter', + ], + ], + 'model' => 'gpt-4o', +]); + +$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->object; // 'assistant' +$response->createdAt; // 1623936000 +$response->name; // 'Math Tutor' +$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' +$response->model; // 'gpt-4o' +$response->description; // null +$response->tools[0]->type; // 'code_interpreter' +$response->toolResources; // [] +$response->metadata; // [] +$response->temperature: // null +$response->topP: // null +$response->format: // 'auto' + +$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] ``` #### `retrieve` -Retrieves a run. +Retrieves an assistant. ```php -$response = $client->threads()->runs()->retrieve( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', -); +$response = $client->assistants()->retrieve('asst_gxzBkD1wkKEloYqZ410pT5pd'); -$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->object; // 'thread.run' +$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->object; // 'assistant' $response->createdAt; // 1623936000 -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'queued' -$response->startedAt; // null -$response->expiresAt; // 1699622335 -$response->cancelledAt; // null -$response->failedAt; // null -$response->completedAt; // null -$response->incompleteDetails; // null -$response->lastError; // null +$response->name; // 'Math Tutor' +$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' $response->model; // 'gpt-4o' -$response->instructions; // null -$response->tools; // [] +$response->description; // null +$response->tools[0]->type; // 'code_interpreter' +$response->toolResources; // [] $response->metadata; // [] -$response->usage->promptTokens; // 25, -$response->usage->completionTokens; // 32, -$response->usage->totalTokens; // 57 -$response->temperature; // null -$response->topP; // null -$response->maxPromptTokens; // 1000 -$response->maxCompletionTokens; // 1000 -$response->truncationStrategy->type; // 'auto' -$response->toolChoice; // 'auto' -$response->responseFormat; // 'auto' +$response->temperature: // null +$response->topP: // null +$response->format: // 'auto' -$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] +$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] ``` #### `modify` -Modifies a run. +Modifies an assistant. ```php -$response = $client->threads()->runs()->modify( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', - parameters: [ - 'metadata' => [ - 'name' => 'My new run name', - ], - ], -); +$response = $client->assistants()->modify('asst_gxzBkD1wkKEloYqZ410pT5pd', [ + 'name' => 'New Math Tutor', + ]); -$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->object; // 'thread.run' +$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->object; // 'assistant' $response->createdAt; // 1623936000 -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'queued' -$response->startedAt; // null -$response->expiresAt; // 1699622335 -$response->cancelledAt; // null -$response->failedAt; // null -$response->completedAt; // null -$response->incompleteDetails; // null -$response->lastError; // null +$response->name; // 'New Math Tutor' +$response->instructions; // 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.' $response->model; // 'gpt-4o' -$response->instructions; // null -$response->tools; // [] -$response->usage->total_tokens; // 579 -$response->temperature; // null -$response->topP; // null -$response->maxPromptTokens; // 1000 -$response->maxCompletionTokens; // 1000 -$response->truncationStrategy->type; // 'auto' -$response->toolChoice; // 'auto' -$response->responseFormat; // 'auto' -$response->metadata; // ['name' => 'My new run name'] +$response->description; // null +$response->tools[0]->type; // 'code_interpreter' +$response->toolResources; // [] +$response->metadata; // [] +$response->temperature: // null +$response->topP: // null +$response->format: // 'auto' -$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] +$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] ``` -#### `cancel` +#### `delete` -Cancels a run that is `in_progress`. +Delete an assistant. ```php -$response = $client->threads()->runs()->cancel( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', -); +$response = $client->assistants()->delete('asst_gxzBkD1wkKEloYqZ410pT5pd'); -$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->object; // 'thread.run' +$response->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->object; // 'assistant.deleted' +$response->deleted; // true + +$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...] +``` + +#### `list` + +Returns a list of assistants. + +```php +$response = $client->assistants()->list([ + 'limit' => 10, +]); + +$response->object; // 'list' +$response->firstId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->lastId; // 'asst_reHHtAM0jKLDIxanM6gP6DaR' +$response->hasMore; // true + +foreach ($response->data as $result) { + $result->id; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' + // ... +} + +$response->toArray(); // ['object' => 'list', ...]] +``` + +### `Threads` Resource (deprecated) + +> [!WARNING] +> OpenAI has deprecated the Assistants API and will stop working by first half of 2026. https://platform.openai.com/docs/guides/responses-vs-chat-completions#assistants + +#### `create` + +Create a thread. + +```php +$response = $client->threads()->create([]); + +$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->object; // 'thread' $response->createdAt; // 1623936000 -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'cancelling' -$response->startedAt; // null -$response->expiresAt; // 1699622335 -$response->cancelledAt; // null -$response->failedAt; // null -$response->completedAt; // null -$response->incompleteDetails; // null -$response->lastError; // null -$response->model; // 'gpt-4o' -$response->instructions; // null -$response->tools; // [] -$response->usage?->total_tokens; // 579 -$response->temperature; // null -$response->topP; // null -$response->maxPromptTokens; // 1000 -$response->maxCompletionTokens; // 1000 -$response->truncationStrategy->type; // 'auto' -$response->toolChoice; // 'auto' -$response->responseFormat; // 'auto' +$response->toolResources; // null $response->metadata; // [] -$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] +$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] ``` -#### `submitToolOutputs` +#### `createAndRun` -When a run has the status: `requires_action` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. +Create a thread and run it in one request. ```php -$response = $client->threads()->runs()->submitToolOutputs( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', - parameters: [ - 'tool_outputs' => [ - [ - 'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj', - 'output' => '12', - ], +$response = $client->threads()->createAndRun( + [ + 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', + 'thread' => [ + 'messages' => + [ + [ + 'role' => 'user', + 'content' => 'Explain deep learning to a 5 year old.', + ], + ], ], - ] + ], ); $response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' @@ -1696,7 +1736,9 @@ $response->object; // 'thread.run' $response->createdAt; // 1623936000 $response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' $response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->status; // 'in_progress' +$response->status; // 'queued' +$response->requiredAction; // null +$response->lastError; // null $response->startedAt; // null $response->expiresAt; // 1699622335 $response->cancelledAt; // null @@ -1706,6 +1748,8 @@ $response->incompleteDetails; // null $response->lastError; // null $response->model; // 'gpt-4o' $response->instructions; // null +$response->tools; // [] +$response->metadata; // [] $response->usage->total_tokens; // 579 $response->temperature; // null $response->topP; // null @@ -1713,607 +1757,579 @@ $response->maxPromptTokens; // 1000 $response->maxCompletionTokens; // 1000 $response->truncationStrategy->type; // 'auto' $response->responseFormat; // 'auto' -$response->tools[0]->type; // 'function' $response->toolChoice; // 'auto' -$response->metadata; // [] $response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `list` - -Returns a list of runs belonging to a thread. - -```php -$response = $client->threads()->runs()->list( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - parameters: [ - 'limit' => 10, - ], -); - -$response->object; // 'list' -$response->firstId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->lastId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->hasMore; // false - -foreach ($response->data as $result) { - $result->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' - // ... -} - -$response->toArray(); // ['object' => 'list', ...]] -``` - -### `Threads Runs Steps` Resource - #### `retrieve` -Retrieves a run step. +Retrieves a thread. ```php -$response = $client->threads()->runs()->steps()->retrieve( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', - stepId: 'step_1spQXgbAabXFm1YXrwiGIMUz', -); +$response = $client->threads()->retrieve('thread_tKFLqzRN9n7MnyKKvc1Q7868'); -$response->id; // 'step_1spQXgbAabXFm1YXrwiGIMUz' -$response->object; // 'thread.run.step' -$response->createdAt; // 1699564106 -$response->runId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' -$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' -$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' -$response->type; // 'message_creation' -$response->status; // 'completed' -$response->cancelledAt; // null -$response->completedAt; // 1699564119 -$response->expiresAt; // null -$response->failedAt; // null -$response->lastError; // null -$response->stepDetails->type; // 'message_creation' -$response->stepDetails->messageCreation->messageId; // 'msg_i404PxKbB92d0JAmdOIcX7vA' +$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->object; // 'thread' +$response->createdAt; // 1623936000 +$response->toolResources; // null +$response->metadata; // [] -$response->toArray(); // ['id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', ...] +$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] ``` -#### `list` +#### `modify` -Returns a list of run steps belonging to a run. +Modifies a thread. ```php -$response = $client->threads()->runs()->steps()->list( - threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', - runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', - parameters: [ - 'limit' => 10, - ], -); - -$response->object; // 'list' -$response->firstId; // 'step_1spQXgbAabXFm1YXrwiGIMUz' -$response->lastId; // 'step_1spQXgbAabXFm1YXrwiGIMUz' -$response->hasMore; // false +$response = $client->threads()->modify('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ + 'metadata' => [ + 'name' => 'My new thread name', + ], + ]); -foreach ($response->data as $result) { - $result->id; // 'step_1spQXgbAabXFm1YXrwiGIMUz' - // ... -} +$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->object; // 'thread' +$response->createdAt; // 1623936000 +$response->toolResources; // null +$response->metadata; // ['name' => 'My new thread name'] -$response->toArray(); // ['object' => 'list', ...]] +$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] ``` -### `Batches` Resource - -#### `create` +#### `delete` -Creates a batch. +Delete a thread. ```php +$response = $client->threads()->delete('thread_tKFLqzRN9n7MnyKKvc1Q7868'); -$fileResponse = $client->files()->upload( - parameters: [ - 'purpose' => 'batch', - 'file' => fopen('commands.jsonl', 'r'), - ] -); - -$fileId = $fileResponse->id; +$response->id; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->object; // 'thread.deleted' +$response->deleted; // true -$response = $client->batches()->create( - parameters: [ - 'input_file_id' => $fileId, - 'endpoint' => '/v1/chat/completions', - 'completion_window' => '24h' - ] - ); +$response->toArray(); // ['id' => 'thread_tKFLqzRN9n7MnyKKvc1Q7868', ...] +``` -$response->id; // 'batch_abc123' -$response->object; // 'batch' -$response->endpoint; // /v1/chat/completions -$response->errors; // null -$response->completionWindow; // '24h' -$response->status; // 'validating' -$response->outputFileId; // null -$response->errorFileId; // null -$response->createdAt; // 1714508499 -$response->inProgressAt; // null -$response->expiresAt; // 1714536634 -$response->completedAt; // null -$response->failedAt; // null -$response->expiredAt; // null -$response->requestCounts; // null -$response->metadata; // ['name' => 'My batch name'] +### `Thread Messages` Resource (deprecated) -$response->toArray(); // ['id' => 'batch_abc123', ...] -``` +> [!WARNING] +> OpenAI has deprecated the Assistants API and will stop working by first half of 2026. https://platform.openai.com/docs/guides/responses-vs-chat-completions#assistants -#### `retrieve` +#### `create` -Retrieves a batch. +Create a message. ```php -$response = $client->batches()->retrieve(id: 'batch_abc123'); +$response = $client->threads()->messages()->create('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ + 'role' => 'user', + 'content' => 'What is the sum of 5 and 7?', +]); -$response->id; // 'batch_abc123' -$response->object; // 'batch' -$response->endpoint; // /v1/chat/completions -$response->errors; // null -$response->completionWindow; // '24h' -$response->status; // 'validating' -$response->outputFileId; // null -$response->errorFileId; // null -$response->createdAt; // 1714508499 -$response->inProgressAt; // null -$response->expiresAt; // 1714536634 +$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->object; // 'thread.message' +$response->createdAt; // 1623936000 +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'in_progress +$response->incompleteDetails; // null $response->completedAt; // null -$response->failedAt; // null -$response->expiredAt; // null -$response->requestCounts->total; // 100 -$response->requestCounts->completed; // 95 -$response->requestCounts->failed; // 5 -$response->metadata; // ['name' => 'My batch name'] +$response->incompleteAt; // null +$response->role; // 'user' +$response->content[0]->type; // 'text' +$response->content[0]->text->value; // 'What is the sum of 5 and 7?' +$response->content[0]->text->annotations; // [] +$response->assistantId; // null +$response->runId; // null +$response->attachments; // [] +$response->metadata; // [] -$response->toArray(); // ['id' => 'batch_abc123', ...] +$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] ``` -#### `cancel` +#### `retrieve` -Cancels a batch. +Retrieve a message. ```php -$response = $client->batches()->cancel(id: 'batch_abc123'); +$response = $client->threads()->messages()->retrieve( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU', +); -$response->id; // 'batch_abc123' -$response->object; // 'batch' -$response->endpoint; // /v1/chat/completions -$response->errors; // null -$response->completionWindow; // '24h' -$response->status; // 'cancelling' -$response->outputFileId; // null -$response->errorFileId; // null -$response->createdAt; // 1711471533 -$response->inProgressAt; // 1711471538 -$response->expiresAt; // 1711557933 -$response->cancellingAt; // 1711475133 -$response->cancelledAt; // null -$response->requestCounts->total; // 100 -$response->requestCounts->completed; // 23 -$response->requestCounts->failed; // 1 -$response->metadata; // ['name' => 'My batch name'] +$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->object; // 'thread.message' +$response->createdAt; // 1623936000 +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'in_progress +$response->incompleteDetails; // null +$response->completedAt; // null +$response->incompleteAt; // null +$response->role; // 'user' +$response->content[0]->type; // 'text' +$response->content[0]->text->value; // 'What is the sum of 5 and 7?' +$response->content[0]->text->annotations; // [] +$response->assistantId; // null +$response->runId; // null +$response->attachments; // [] +$response->metadata; // [] -$response->toArray(); // ['id' => 'batch_abc123', ...] +$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] ``` -#### `list` +#### `modify` -Returns a list of batches. +Modifies a message. ```php -$response = $client->batches()->list( - parameters: [ - 'limit' => 10, +$response = $client->threads()->messages()->modify( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU', + parameters: [ + 'metadata' => [ + 'name' => 'My new message name', + ], ], ); -$response->object; // 'list' -$response->firstId; // 'batch_abc123' -$response->lastId; // 'batch_abc456' -$response->hasMore; // true - -foreach ($response->data as $result) { - $result->id; // 'batch_abc123' - // ... -} +$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->object; // 'thread.message' +$response->createdAt; // 1623936000 +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'in_progress +$response->incompleteDetails; // null +$response->completedAt; // null +$response->incompleteAt; // null +$response->role; // 'user' +$response->content[0]->type; // 'text' +$response->content[0]->text->value; // 'What is the sum of 5 and 7?' +$response->content[0]->text->annotations; // [] +$response->assistantId; // null +$response->runId; // null +$response->attachments; // [] +$response->metadata; // ['name' => 'My new message name'] -$response->toArray(); // ['object' => 'list', ...]] +$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] ``` -### `Vector Stores` Resource - -#### `create` +#### `delete` -Create a vector store. +Deletes a message. ```php -$response = $client->vectorStores()->create([ - 'file_ids' => [ - 'file-fUU0hFRuQ1GzhOweTNeJlCXG', - ], - 'name' => 'My first Vector Store', -]); +$response = $client->threads()->messages()->delete( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + messageId: 'msg_SKYwvF3zcigxthfn6F4hnpdU' +); -$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->object; // 'vector_store' -$response->createdAt; // 1717703267 -$response->name; // 'My first Vector Store' -$response->usageBytes; // 0 -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 -$response->status; // 'in_progress' -$response->expiresAfter; // null -$response->expiresAt; // null -$response->lastActiveAt; // 1717703267 +$response->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->object; // 'thread.message.deleted' +$response->deleted; // true -$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] +$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...] ``` -#### `retrieve` +#### `list` -Retrieves a vector store. +Returns a list of messages for a given thread. ```php -$response = $client->vectorStores()->retrieve( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', -); +$response = $client->threads()->messages()->list('thread_tKFLqzRN9n7MnyKKvc1Q7868', [ + 'limit' => 10, +]); + +$response->object; // 'list' +$response->firstId; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->lastId; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' +$response->hasMore; // false -$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->object; // 'vector_store' -$response->createdAt; // 1717703267 -$response->name; // 'My first Vector Store' -$response->usageBytes; // 0 -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 -$response->status; // 'in_progress' -$response->expiresAfter; // null -$response->expiresAt; // null -$response->lastActiveAt; // 1717703267 +foreach ($response->data as $result) { + $result->id; // 'msg_SKYwvF3zcigxthfn6F4hnpdU' + // ... +} -$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] +$response->toArray(); // ['object' => 'list', ...]] ``` -#### `modify` +### `Thread Runs` Resource (deprecated) -Modifies a vector store. +> [!WARNING] +> OpenAI has deprecated the Assistants API and will stop working by first half of 2026. https://platform.openai.com/docs/guides/responses-vs-chat-completions#assistants + +#### `create` + +Create a run. ```php -$response = $client->vectorStores()->modify( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - parameters: [ - 'name' => 'New name', +$response = $client->threads()->runs()->create( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + parameters: [ + 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ], ); -$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->object; // 'vector_store' -$response->createdAt; // 1717703267 -$response->name; // 'New name' -$response->usageBytes; // 0 -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 -$response->status; // 'in_progress' -$response->expiresAfter; // null -$response->expiresAt; // null -$response->lastActiveAt; // 1717703267 +$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->object; // 'thread.run' +$response->createdAt; // 1623936000 +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'queued' +$response->startedAt; // null +$response->expiresAt; // 1699622335 +$response->cancelledAt; // null +$response->failedAt; // null +$response->completedAt; // null +$response->incompleteDetails; // null +$response->lastError; // null +$response->model; // 'gpt-4o' +$response->instructions; // null +$response->tools; // [] +$response->metadata; // [] +$response->usage->total_tokens; // 579 +$response->temperature; // null +$response->topP; // null +$response->maxPromptTokens; // 1000 +$response->maxCompletionTokens; // 1000 +$response->truncationStrategy->type; // 'auto' +$response->toolChoice; // 'auto' +$response->responseFormat; // 'auto' -$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] +$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `delete` +#### `create streamed` -Delete a vector store. +Creates a streamed run. + +[OpenAI Assistant Events](https://platform.openai.com/docs/api-reference/assistants-streaming/events) ```php -$response = $client->vectorStores()->delete( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', +$stream = $client->threads()->runs()->createStreamed( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + parameters: [ + 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', + ], ); -$response->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->object; // 'vector_store.deleted' -$response->deleted; // true +foreach($stream as $response){ + $response->event // 'thread.run.created' | 'thread.run.in_progress' | ..... + $response->response // ThreadResponse | ThreadRunResponse | ThreadRunStepResponse | ThreadRunStepDeltaResponse | ThreadMessageResponse | ThreadMessageDeltaResponse +} -$response->toArray(); // ['id' => 'vs_vzfQhlTWVUl38QGqQAoQjeDF', ...] +// ... ``` -#### `list` +#### `create streamed with function calls` -Returns a list of vector stores. +Creates a streamed run with function calls + +[OpenAI Assistant Events](https://platform.openai.com/docs/api-reference/assistants-streaming/events) ```php -$response = $client->vectorStores()->list( +$stream = $client->threads()->runs()->createStreamed( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', parameters: [ - 'limit' => 10, + 'assistant_id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ], ); -$response->object; // 'list' -$response->firstId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->lastId; // 'vs_D5DPOgBxSoEBTmYBgUESdPpa' -$response->hasMore; // true -foreach ($response->data as $result) { - $result->id; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' - // ... -} +do{ + foreach($stream as $response){ + $response->event // 'thread.run.created' | 'thread.run.in_progress' | ..... + $response->response // ThreadResponse | ThreadRunResponse | ThreadRunStepResponse | ThreadRunStepDeltaResponse | ThreadMessageResponse | ThreadMessageDeltaResponse -$response->toArray(); // ['object' => 'list', ...]] -``` + switch($response->event){ + case 'thread.run.created': + case 'thread.run.queued': + case 'thread.run.completed': + case 'thread.run.cancelling': + $run = $response->response; + break; + case 'thread.run.expired': + case 'thread.run.cancelled': + case 'thread.run.failed': + $run = $response->response; + break 3; + case 'thread.run.requires_action': + // Overwrite the stream with the new stream started by submitting the tool outputs + $stream = $client->threads()->runs()->submitToolOutputsStreamed( + threadId: $run->threadId, + runId: $run->id, + parameters: [ + 'tool_outputs' => [ + [ + 'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj', + 'output' => '12', + ] + ], + ] + ); + break; + } + } +} while ($run->status != "completed") -### `Vector Store Files` Resource +// ... +``` -#### `create` +#### `retrieve` -Create a vector store file by attaching a File to a vector store. +Retrieves a run. ```php -$response = $client->vectorStores()->files()->create( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - parameters: [ - 'file_id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', - ] +$response = $client->threads()->runs()->retrieve( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', ); -$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' -$response->object; // 'vector_store.file' -$response->usageBytes; // 4553 -$response->createdAt; // 1717703267 -$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->status; // 'completed' +$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->object; // 'thread.run' +$response->createdAt; // 1623936000 +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'queued' +$response->startedAt; // null +$response->expiresAt; // 1699622335 +$response->cancelledAt; // null +$response->failedAt; // null +$response->completedAt; // null +$response->incompleteDetails; // null $response->lastError; // null -$response->chunkingStrategy->type; // 'static' -$response->chunkingStrategy->maxChunkSizeTokens; // 800 -$response->chunkingStrategy->chunkOverlapTokens; // 400 +$response->model; // 'gpt-4o' +$response->instructions; // null +$response->tools; // [] +$response->metadata; // [] +$response->usage->promptTokens; // 25, +$response->usage->completionTokens; // 32, +$response->usage->totalTokens; // 57 +$response->temperature; // null +$response->topP; // null +$response->maxPromptTokens; // 1000 +$response->maxCompletionTokens; // 1000 +$response->truncationStrategy->type; // 'auto' +$response->toolChoice; // 'auto' +$response->responseFormat; // 'auto' -$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] +$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `retrieve` +#### `modify` -Retrieves a vector store file. +Modifies a run. ```php -$response = $client->vectorStores()->files()->retrieve( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - fileId: 'file-fUU0hFRuQ1GzhOweTNeJlCXG', +$response = $client->threads()->runs()->modify( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', + parameters: [ + 'metadata' => [ + 'name' => 'My new run name', + ], + ], ); -$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' -$response->object; // 'vector_store.file' -$response->usageBytes; // 4553 -$response->createdAt; // 1717703267 -$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->status; // 'completed' +$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->object; // 'thread.run' +$response->createdAt; // 1623936000 +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'queued' +$response->startedAt; // null +$response->expiresAt; // 1699622335 +$response->cancelledAt; // null +$response->failedAt; // null +$response->completedAt; // null +$response->incompleteDetails; // null $response->lastError; // null -$response->chunkingStrategy->type; // 'static' -$response->chunkingStrategy->maxChunkSizeTokens; // 800 -$response->chunkingStrategy->chunkOverlapTokens; // 400 +$response->model; // 'gpt-4o' +$response->instructions; // null +$response->tools; // [] +$response->usage->total_tokens; // 579 +$response->temperature; // null +$response->topP; // null +$response->maxPromptTokens; // 1000 +$response->maxCompletionTokens; // 1000 +$response->truncationStrategy->type; // 'auto' +$response->toolChoice; // 'auto' +$response->responseFormat; // 'auto' +$response->metadata; // ['name' => 'My new run name'] -$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] +$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `delete` +#### `cancel` -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. +Cancels a run that is `in_progress`. ```php -$response = $client->vectorStores()->files()->delete( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - fileId: 'file-fUU0hFRuQ1GzhOweTNeJlCXG', +$response = $client->threads()->runs()->cancel( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', ); -$response->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' -$response->object; // 'vector_store.file.deleted' -$response->deleted; // true +$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->object; // 'thread.run' +$response->createdAt; // 1623936000 +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'cancelling' +$response->startedAt; // null +$response->expiresAt; // 1699622335 +$response->cancelledAt; // null +$response->failedAt; // null +$response->completedAt; // null +$response->incompleteDetails; // null +$response->lastError; // null +$response->model; // 'gpt-4o' +$response->instructions; // null +$response->tools; // [] +$response->usage?->total_tokens; // 579 +$response->temperature; // null +$response->topP; // null +$response->maxPromptTokens; // 1000 +$response->maxCompletionTokens; // 1000 +$response->truncationStrategy->type; // 'auto' +$response->toolChoice; // 'auto' +$response->responseFormat; // 'auto' +$response->metadata; // [] -$response->toArray(); // ['id' => 'file-fUU0hFRuQ1GzhOweTNeJlCXG', ...] +$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `list` +#### `submitToolOutputs` -Returns a list of vector store files. +When a run has the status: `requires_action` and `required_action.type` is `submit_tool_outputs`, this endpoint can be used to submit the outputs from the tool calls once they're all completed. All outputs must be submitted in a single request. ```php -$response = $client->vectorStores()->files()->list( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', +$response = $client->threads()->runs()->submitToolOutputs( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', parameters: [ - 'limit' => 10, - ], + 'tool_outputs' => [ + [ + 'tool_call_id' => 'call_KSg14X7kZF2WDzlPhpQ168Mj', + 'output' => '12', + ], + ], + ] ); -$response->object; // 'list' -$response->firstId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' -$response->lastId; // 'file-D5DPOgBxSoEBTmYBgUESdPpa' -$response->hasMore; // true - -foreach ($response->data as $result) { - $result->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' - // ... -} +$response->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->object; // 'thread.run' +$response->createdAt; // 1623936000 +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->status; // 'in_progress' +$response->startedAt; // null +$response->expiresAt; // 1699622335 +$response->cancelledAt; // null +$response->failedAt; // null +$response->completedAt; // null +$response->incompleteDetails; // null +$response->lastError; // null +$response->model; // 'gpt-4o' +$response->instructions; // null +$response->usage->total_tokens; // 579 +$response->temperature; // null +$response->topP; // null +$response->maxPromptTokens; // 1000 +$response->maxCompletionTokens; // 1000 +$response->truncationStrategy->type; // 'auto' +$response->responseFormat; // 'auto' +$response->tools[0]->type; // 'function' +$response->toolChoice; // 'auto' +$response->metadata; // [] -$response->toArray(); // ['object' => 'list', ...]] +$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...] ``` -#### `search` +#### `list` -Search a vector store for relevant chunks based on a query and file attributes filter. +Returns a list of runs belonging to a thread. ```php -$response = $client->vectorStores()->search( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', +$response = $client->threads()->runs()->list( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', parameters: [ - 'query' => 'What is the return policy?', - 'max_num_results' => 5, - 'filters' => [], - 'rewrite_query' => false - ] + 'limit' => 10, + ], ); -$response->object; // 'vector_store.search_results.page' -$response->searchQuery; // 'What is the return policy?' +$response->object; // 'list' +$response->firstId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->lastId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' $response->hasMore; // false -$response->nextPage; // null -foreach ($response->data as $file) { - $result->fileId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' - $result->filename; // 'return_policy.pdf' - $result->score; // 0.95 - $result->attributes; // ['category' => 'customer_service'] - foreach ($result->content as $content) { - $content->type; // 'text' - $content->text; // 'Our return policy allows customers to return items within 30 days...' - } +foreach ($response->data as $result) { + $result->id; // 'run_4RCYyYzX9m41WQicoJtUQAb8' + // ... } -$response->toArray(); // ['object' => 'vector_store.search_results.page', ...] +$response->toArray(); // ['object' => 'list', ...]] ``` -### `Vector Store File Batches` Resource - -#### `create` - -Create a vector store file batch. - -```php -$response = $client->vectorStores()->batches()->create( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - parameters: [ - 'file_ids' => [ - 'file-fUU0hFRuQ1GzhOweTNeJlCXG', - ], - ] -); - -$response->id; // 'vsfb_123' -$response->object; // 'vector_store.files_batch' -$response->createdAt; // 1698107661 -$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->status; // 'completed' -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 +### `Thread Run Steps` Resource (deprecated) -$response->toArray(); // ['id' => 'vsfb_123', ...] -``` +> [!WARNING] +> OpenAI has deprecated the Assistants API and will stop working by first half of 2026. https://platform.openai.com/docs/guides/responses-vs-chat-completions#assistants #### `retrieve` -Retrieves a vector store file batch. +Retrieves a run step. ```php -$response = $client->vectorStores()->batches()->retrieve( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - fileBatchId: 'vsfb_123', +$response = $client->threads()->runs()->steps()->retrieve( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', + stepId: 'step_1spQXgbAabXFm1YXrwiGIMUz', ); -$response->id; // 'vsfb_123' -$response->object; // 'vector_store.files_batch' -$response->createdAt; // 1698107661 -$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' +$response->id; // 'step_1spQXgbAabXFm1YXrwiGIMUz' +$response->object; // 'thread.run.step' +$response->createdAt; // 1699564106 +$response->runId; // 'run_4RCYyYzX9m41WQicoJtUQAb8' +$response->assistantId; // 'asst_gxzBkD1wkKEloYqZ410pT5pd' +$response->threadId; // 'thread_tKFLqzRN9n7MnyKKvc1Q7868' +$response->type; // 'message_creation' $response->status; // 'completed' -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 - -$response->toArray(); // ['id' => 'vsfb_123', ...] -``` - -#### `cancel` - -Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible. - -```php -$response = $client->vectorStores()->batches()->cancel( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - fileBatchId: 'vsfb_123', -); - -$response->id; // 'vsfb_123' -$response->object; // 'vector_store.files_batch' -$response->createdAt; // 1698107661 -$response->vectorStoreId; // 'vs_vzfQhlTWVUl38QGqQAoQjeDF' -$response->status; // 'cancelling' -$response->fileCounts->inProgress; // 1 -$response->fileCounts->completed; // 0 -$response->fileCounts->failed; // 0 -$response->fileCounts->cancelled; // 0 -$response->fileCounts->total; // 1 +$response->cancelledAt; // null +$response->completedAt; // 1699564119 +$response->expiresAt; // null +$response->failedAt; // null +$response->lastError; // null +$response->stepDetails->type; // 'message_creation' +$response->stepDetails->messageCreation->messageId; // 'msg_i404PxKbB92d0JAmdOIcX7vA' -$response->toArray(); // ['id' => 'vsfb_123', ...] +$response->toArray(); // ['id' => 'step_1spQXgbAabXFm1YXrwiGIMUz', ...] ``` #### `list` -Returns a list of vector store files. +Returns a list of run steps belonging to a run. ```php -$response = $client->vectorStores()->batches()->listFiles( - vectorStoreId: 'vs_vzfQhlTWVUl38QGqQAoQjeDF', - fileBatchId: 'vsfb_123', +$response = $client->threads()->runs()->steps()->list( + threadId: 'thread_tKFLqzRN9n7MnyKKvc1Q7868', + runId: 'run_4RCYyYzX9m41WQicoJtUQAb8', parameters: [ 'limit' => 10, ], ); $response->object; // 'list' -$response->firstId; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' -$response->lastId; // 'file-D5DPOgBxSoEBTmYBgUESdPpa' -$response->hasMore; // true +$response->firstId; // 'step_1spQXgbAabXFm1YXrwiGIMUz' +$response->lastId; // 'step_1spQXgbAabXFm1YXrwiGIMUz' +$response->hasMore; // false foreach ($response->data as $result) { - $result->id; // 'file-fUU0hFRuQ1GzhOweTNeJlCXG' + $result->id; // 'step_1spQXgbAabXFm1YXrwiGIMUz' // ... } $response->toArray(); // ['object' => 'list', ...]] ``` -### Realtime Ephemeral Keys - -#### `token` - -Create an ephemeral API token for real time sessions. - -```php -$response = $client->realtime()->token(); - -$response->clientSecret->value // 'ek-1234567890abcdefg' -$response->clientSecret->expiresAt // 1717703267 -``` - -#### `transcribeToken` - -Create an ephemeral API token for real time transcription sessions. - -```php -$response = $client->realtime()->transcribeToken(); - -$response->clientSecret->value // 'et-1234567890abcdefg' -$response->clientSecret->expiresAt // 1717703267 -``` - ### `Edits` Resource (deprecated) > [!WARNING]