File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Original file line number Diff line number Diff line change @@ -254,6 +254,19 @@ $response->truncation; // 'disabled'
254
254
$response->toArray(); // ['id' => 'resp_67ccd2bed1ec8190b14f964abc054267', ...]
255
255
```
256
256
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
+
257
270
### ` delete `
258
271
259
272
Deletes a model response with the given ID.
Original file line number Diff line number Diff line change @@ -80,6 +80,21 @@ public function retrieve(string $id): RetrieveResponse
80
80
return RetrieveResponse::from ($ response ->data (), $ response ->meta ());
81
81
}
82
82
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
+
83
98
/**
84
99
* Deletes a model response with the given ID.
85
100
*
Original file line number Diff line number Diff line change 201
201
expect ($ result ->meta ())
202
202
->toBeInstanceOf (MetaInformation::class);
203
203
});
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
+ });
You can’t perform that action at this time.
0 commit comments