@@ -45,6 +45,7 @@ package main
45
45
46
46
import (
47
47
" context"
48
+ " fmt"
48
49
49
50
" github.com/openai/openai-go"
50
51
" github.com/openai/openai-go/option"
@@ -525,6 +526,34 @@ client.Chat.Completions.New(
525
526
)
526
527
```
527
528
529
+ ### Accessing raw response data (e.g. response headers)
530
+
531
+ You can access the raw HTTP response data by using the ` option.WithResponseInto() ` request option. This is useful when
532
+ you need to examine response headers, status codes, or other details.
533
+
534
+ ``` go
535
+ // Create a variable to store the HTTP response
536
+ var response *http.Response
537
+ chatCompletion , err := client.Chat .Completions .New (
538
+ context.TODO (),
539
+ openai.ChatCompletionNewParams {
540
+ Messages : openai.F ([]openai.ChatCompletionMessageParamUnion {openai.ChatCompletionUserMessageParam {
541
+ Role: openai.F (openai.ChatCompletionUserMessageParamRoleUser ),
542
+ Content: openai.F ([]openai.ChatCompletionContentPartUnionParam {openai.ChatCompletionContentPartTextParam {Text: openai.F (" text" ), Type: openai.F (openai.ChatCompletionContentPartTextTypeText )}}),
543
+ }}),
544
+ Model : openai.F (openai.ChatModelO3Mini ),
545
+ },
546
+ option.WithResponseInto (&response),
547
+ )
548
+ if err != nil {
549
+ // handle error
550
+ }
551
+ fmt.Printf (" %+v \n " , chatCompletion)
552
+
553
+ fmt.Printf (" Status Code: %d \n " , response.StatusCode )
554
+ fmt.Printf (" Headers: %+#v \n " , response.Header )
555
+ ```
556
+
528
557
### Making custom/undocumented requests
529
558
530
559
This library is typed for convenient access to the documented API. If you need to access undocumented
0 commit comments