@@ -8,34 +8,42 @@ final class CreateResponseUsageCompletionTokensDetails
8
8
{
9
9
private function __construct (
10
10
public readonly ?int $ audioTokens ,
11
- public readonly int $ reasoningTokens ,
12
- public readonly int $ acceptedPredictionTokens ,
13
- public readonly int $ rejectedPredictionTokens
11
+ public readonly ? int $ reasoningTokens ,
12
+ public readonly ? int $ acceptedPredictionTokens ,
13
+ public readonly ? int $ rejectedPredictionTokens
14
14
) {}
15
15
16
16
/**
17
- * @param array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int} $attributes
17
+ * @param array{audio_tokens?:int|null , reasoning_tokens? :int|null , accepted_prediction_tokens? :int|null , rejected_prediction_tokens? :int|null } $attributes
18
18
*/
19
19
public static function from (array $ attributes ): self
20
20
{
21
21
return new self (
22
22
$ attributes ['audio_tokens ' ] ?? null ,
23
- $ attributes ['reasoning_tokens ' ],
24
- $ attributes ['accepted_prediction_tokens ' ],
25
- $ attributes ['rejected_prediction_tokens ' ],
23
+ $ attributes ['reasoning_tokens ' ] ?? null ,
24
+ $ attributes ['accepted_prediction_tokens ' ] ?? null ,
25
+ $ attributes ['rejected_prediction_tokens ' ] ?? null ,
26
26
);
27
27
}
28
28
29
29
/**
30
- * @return array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}
30
+ * @return array{audio_tokens?:int, reasoning_tokens? :int, accepted_prediction_tokens? :int, rejected_prediction_tokens? :int}
31
31
*/
32
32
public function toArray (): array
33
33
{
34
- $ result = [
35
- 'reasoning_tokens ' => $ this ->reasoningTokens ,
36
- 'accepted_prediction_tokens ' => $ this ->acceptedPredictionTokens ,
37
- 'rejected_prediction_tokens ' => $ this ->rejectedPredictionTokens ,
38
- ];
34
+ $ result = [];
35
+
36
+ if (! is_null ($ this ->reasoningTokens )) {
37
+ $ result ['reasoning_tokens ' ] = $ this ->reasoningTokens ;
38
+ }
39
+
40
+ if (! is_null ($ this ->acceptedPredictionTokens )) {
41
+ $ result ['accepted_prediction_tokens ' ] = $ this ->acceptedPredictionTokens ;
42
+ }
43
+
44
+ if (! is_null ($ this ->rejectedPredictionTokens )) {
45
+ $ result ['rejected_prediction_tokens ' ] = $ this ->rejectedPredictionTokens ;
46
+ }
39
47
40
48
if (! is_null ($ this ->audioTokens )) {
41
49
$ result ['audio_tokens ' ] = $ this ->audioTokens ;
0 commit comments