@@ -389,6 +389,68 @@ func TestResponsesRequestJSON_PreservesUnknownFields(t *testing.T) {
389389 }
390390}
391391
392+ func TestResponsesResponseJSON_AcceptsStructuredAnnotations (t * testing.T ) {
393+ var resp ResponsesResponse
394+ if err := json .Unmarshal ([]byte (`{
395+ "id":"resp_123",
396+ "object":"response",
397+ "created_at":1677652288,
398+ "model":"gpt-4o-mini",
399+ "status":"completed",
400+ "output":[{
401+ "id":"msg_123",
402+ "type":"message",
403+ "role":"assistant",
404+ "status":"completed",
405+ "content":[{
406+ "type":"output_text",
407+ "text":"Found a result.",
408+ "annotations":[{
409+ "type":"url_citation",
410+ "title":"Example Domain",
411+ "url":"https://example.com"
412+ }]
413+ }]
414+ }]
415+ }` ), & resp ); err != nil {
416+ t .Fatalf ("json.Unmarshal() error = %v" , err )
417+ }
418+
419+ if len (resp .Output ) != 1 || len (resp .Output [0 ].Content ) != 1 {
420+ t .Fatalf ("unexpected output shape: %+v" , resp .Output )
421+ }
422+ annotations := resp .Output [0 ].Content [0 ].Annotations
423+ if len (annotations ) != 1 {
424+ t .Fatalf ("len(Annotations) = %d, want 1" , len (annotations ))
425+ }
426+
427+ var annotation map [string ]any
428+ if err := json .Unmarshal (annotations [0 ], & annotation ); err != nil {
429+ t .Fatalf ("json.Unmarshal(annotation) error = %v" , err )
430+ }
431+ if annotation ["type" ] != "url_citation" {
432+ t .Fatalf ("annotation.type = %#v, want url_citation" , annotation ["type" ])
433+ }
434+
435+ body , err := json .Marshal (resp )
436+ if err != nil {
437+ t .Fatalf ("json.Marshal() error = %v" , err )
438+ }
439+
440+ var decoded map [string ]any
441+ if err := json .Unmarshal (body , & decoded ); err != nil {
442+ t .Fatalf ("json.Unmarshal(roundTrip) error = %v" , err )
443+ }
444+
445+ output := decoded ["output" ].([]any )
446+ content := output [0 ].(map [string ]any )["content" ].([]any )
447+ roundTripAnnotations := content [0 ].(map [string ]any )["annotations" ].([]any )
448+ firstAnnotation := roundTripAnnotations [0 ].(map [string ]any )
449+ if firstAnnotation ["url" ] != "https://example.com" {
450+ t .Fatalf ("roundTrip annotation.url = %#v, want https://example.com" , firstAnnotation ["url" ])
451+ }
452+ }
453+
392454func TestResponsesInputElementMarshalJSON_FunctionCall (t * testing.T ) {
393455 elem := ResponsesInputElement {
394456 Type : "function_call" ,
0 commit comments