Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59e27ca

Browse filesBrowse files
authored
feat(OpenAI): add support for response cancel (#588)
1 parent 68fd99c commit 59e27ca
Copy full SHA for 59e27ca

File tree

Expand file treeCollapse file tree

3 files changed

+45
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+45
-0
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ $response->truncation; // 'disabled'
254254
$response->toArray(); // ['id' => 'resp_67ccd2bed1ec8190b14f964abc054267', ...]
255255
```
256256

257+
### `cancel`
258+
259+
Cancel a model response (background request) with the given ID.
260+
261+
```php
262+
$response = $client->responses()->cancel('resp_67ccd2bed1ec8190b14f964abc054267');
263+
264+
$response->id; // 'resp_67ccd2bed1ec8190b14f964abc054267'
265+
$response->status; // 'canceled'
266+
267+
$response->toArray(); // ['id' => 'resp_67ccd2bed1ec8190b14f964abc054267', 'status' => 'canceled', ...]
268+
```
269+
257270
### `delete`
258271

259272
Deletes a model response with the given ID.

‎src/Resources/Responses.php

Copy file name to clipboardExpand all lines: src/Resources/Responses.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ public function retrieve(string $id): RetrieveResponse
8080
return RetrieveResponse::from($response->data(), $response->meta());
8181
}
8282

83+
/**
84+
* Cancels a model response with the given ID. Must be marked as 'background' to be cancellable.
85+
*
86+
* @see https://platform.openai.com/docs/api-reference/responses/cancel
87+
*/
88+
public function cancel(string $id): RetrieveResponse
89+
{
90+
$payload = Payload::cancel('responses', $id);
91+
92+
/** @var Response<RetrieveResponseType> $response */
93+
$response = $this->transporter->requestObject($payload);
94+
95+
return RetrieveResponse::from($response->data(), $response->meta());
96+
}
97+
8398
/**
8499
* Deletes a model response with the given ID.
85100
*

‎tests/Resources/Responses.php

Copy file name to clipboardExpand all lines: tests/Resources/Responses.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,20 @@
201201
expect($result->meta())
202202
->toBeInstanceOf(MetaInformation::class);
203203
});
204+
205+
test('cancel', function () {
206+
$client = mockClient('POST', 'responses/resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c/cancel', [
207+
], \OpenAI\ValueObjects\Transporter\Response::from(retrieveResponseResource(), metaHeaders()));
208+
209+
$result = $client->responses()->cancel('resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c');
210+
211+
expect($result)
212+
->toBeInstanceOf(RetrieveResponse::class)
213+
->id->toBe('resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c')
214+
->object->toBe('response')
215+
->createdAt->toBe(1741484430)
216+
->status->toBe('completed');
217+
218+
expect($result->meta())
219+
->toBeInstanceOf(MetaInformation::class);
220+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.