File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
259272Deletes 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
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 *
Original file line number Diff line number Diff line change 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+ });
You can’t perform that action at this time.
0 commit comments