Skip to content

Commit 9eb77a6

Browse files
authored
[openai] Include ResponseInfo in response (#571)
## Summary Populates `ResponseInfo` in the response object for openai calls. ## How was it tested? CICD ## Community Contribution License All community contributions in this pull request are licensed to the project maintainers under the terms of the [Apache 2 License](https://www.apache.org/licenses/LICENSE-2.0). By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the [Community Contribution License](https://github.com/jetify-com/opensource/blob/main/CONTRIBUTING.md#community-contribution-license).
1 parent 0e8451b commit 9eb77a6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

aisdk/ai/provider/openai/internal/codec/decode.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"strings"
7+
"time"
78

89
"github.com/openai/openai-go/v2/responses"
910
"go.jetify.com/ai/api"
@@ -31,6 +32,11 @@ func DecodeResponse(msg *responses.Response) (*api.Response, error) {
3132

3233
// Create the response with the extracted fields
3334
resp := &api.Response{
35+
ResponseInfo: &api.ResponseInfo{
36+
ID: msg.ID,
37+
ModelID: msg.Model,
38+
Timestamp: time.Unix(int64(msg.CreatedAt), 0).UTC(),
39+
},
3440
Content: content.Content,
3541
Usage: decodeUsage(msg.Usage),
3642
ProviderMetadata: decodeProviderMetadata(msg),

aisdk/ai/provider/openai/internal/codec/decode_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package codec
33
import (
44
"encoding/json"
55
"testing"
6+
"time"
67

78
"github.com/openai/openai-go/v2/responses"
89
"github.com/stretchr/testify/assert"
@@ -20,6 +21,9 @@ func TestDecodeResponse(t *testing.T) {
2021
{
2122
name: "simple message",
2223
input: `{
24+
"id": "resp_123",
25+
"created_at": 1741269019,
26+
"model": "gpt-4",
2327
"output": [
2428
{
2529
"type": "message",
@@ -37,6 +41,11 @@ func TestDecodeResponse(t *testing.T) {
3741
}
3842
}`,
3943
want: &api.Response{
44+
ResponseInfo: &api.ResponseInfo{
45+
ID: "resp_123",
46+
ModelID: "gpt-4",
47+
Timestamp: time.Date(2025, 3, 6, 13, 50, 19, 0, time.UTC),
48+
},
4049
Content: []api.ContentBlock{
4150
&api.TextBlock{Text: "Hello world"},
4251
},

0 commit comments

Comments
 (0)