betathreadmessage.go

   1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
   2
   3package openai
   4
   5import (
   6	"context"
   7	"encoding/json"
   8	"errors"
   9	"fmt"
  10	"net/http"
  11	"net/url"
  12	"reflect"
  13
  14	"github.com/openai/openai-go/internal/apijson"
  15	"github.com/openai/openai-go/internal/apiquery"
  16	"github.com/openai/openai-go/internal/requestconfig"
  17	"github.com/openai/openai-go/option"
  18	"github.com/openai/openai-go/packages/pagination"
  19	"github.com/openai/openai-go/packages/param"
  20	"github.com/openai/openai-go/packages/resp"
  21	"github.com/openai/openai-go/shared"
  22	"github.com/openai/openai-go/shared/constant"
  23	"github.com/tidwall/gjson"
  24)
  25
  26// BetaThreadMessageService contains methods and other services that help with
  27// interacting with the openai API.
  28//
  29// Note, unlike clients, this service does not read variables from the environment
  30// automatically. You should not instantiate this service directly, and instead use
  31// the [NewBetaThreadMessageService] method instead.
  32type BetaThreadMessageService struct {
  33	Options []option.RequestOption
  34}
  35
  36// NewBetaThreadMessageService generates a new service that applies the given
  37// options to each request. These options are applied after the parent client's
  38// options (if there is one), and before any request-specific options.
  39func NewBetaThreadMessageService(opts ...option.RequestOption) (r BetaThreadMessageService) {
  40	r = BetaThreadMessageService{}
  41	r.Options = opts
  42	return
  43}
  44
  45// Create a message.
  46func (r *BetaThreadMessageService) New(ctx context.Context, threadID string, body BetaThreadMessageNewParams, opts ...option.RequestOption) (res *Message, err error) {
  47	opts = append(r.Options[:], opts...)
  48	opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
  49	if threadID == "" {
  50		err = errors.New("missing required thread_id parameter")
  51		return
  52	}
  53	path := fmt.Sprintf("threads/%s/messages", threadID)
  54	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  55	return
  56}
  57
  58// Retrieve a message.
  59func (r *BetaThreadMessageService) Get(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *Message, err error) {
  60	opts = append(r.Options[:], opts...)
  61	opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
  62	if threadID == "" {
  63		err = errors.New("missing required thread_id parameter")
  64		return
  65	}
  66	if messageID == "" {
  67		err = errors.New("missing required message_id parameter")
  68		return
  69	}
  70	path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
  71	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
  72	return
  73}
  74
  75// Modifies a message.
  76func (r *BetaThreadMessageService) Update(ctx context.Context, threadID string, messageID string, body BetaThreadMessageUpdateParams, opts ...option.RequestOption) (res *Message, err error) {
  77	opts = append(r.Options[:], opts...)
  78	opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
  79	if threadID == "" {
  80		err = errors.New("missing required thread_id parameter")
  81		return
  82	}
  83	if messageID == "" {
  84		err = errors.New("missing required message_id parameter")
  85		return
  86	}
  87	path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
  88	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
  89	return
  90}
  91
  92// Returns a list of messages for a given thread.
  93func (r *BetaThreadMessageService) List(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Message], err error) {
  94	var raw *http.Response
  95	opts = append(r.Options[:], opts...)
  96	opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
  97	if threadID == "" {
  98		err = errors.New("missing required thread_id parameter")
  99		return
 100	}
 101	path := fmt.Sprintf("threads/%s/messages", threadID)
 102	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
 103	if err != nil {
 104		return nil, err
 105	}
 106	err = cfg.Execute()
 107	if err != nil {
 108		return nil, err
 109	}
 110	res.SetPageConfig(cfg, raw)
 111	return res, nil
 112}
 113
 114// Returns a list of messages for a given thread.
 115func (r *BetaThreadMessageService) ListAutoPaging(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Message] {
 116	return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, query, opts...))
 117}
 118
 119// Deletes a message.
 120func (r *BetaThreadMessageService) Delete(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *MessageDeleted, err error) {
 121	opts = append(r.Options[:], opts...)
 122	opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
 123	if threadID == "" {
 124		err = errors.New("missing required thread_id parameter")
 125		return
 126	}
 127	if messageID == "" {
 128		err = errors.New("missing required message_id parameter")
 129		return
 130	}
 131	path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
 132	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
 133	return
 134}
 135
 136// AnnotationUnion contains all possible properties and values from
 137// [FileCitationAnnotation], [FilePathAnnotation].
 138//
 139// Use the [AnnotationUnion.AsAny] method to switch on the variant.
 140//
 141// Use the methods beginning with 'As' to cast the union to one of its variants.
 142type AnnotationUnion struct {
 143	EndIndex int64 `json:"end_index"`
 144	// This field is from variant [FileCitationAnnotation].
 145	FileCitation FileCitationAnnotationFileCitation `json:"file_citation"`
 146	StartIndex   int64                              `json:"start_index"`
 147	Text         string                             `json:"text"`
 148	// Any of "file_citation", "file_path".
 149	Type string `json:"type"`
 150	// This field is from variant [FilePathAnnotation].
 151	FilePath FilePathAnnotationFilePath `json:"file_path"`
 152	JSON     struct {
 153		EndIndex     resp.Field
 154		FileCitation resp.Field
 155		StartIndex   resp.Field
 156		Text         resp.Field
 157		Type         resp.Field
 158		FilePath     resp.Field
 159		raw          string
 160	} `json:"-"`
 161}
 162
 163// Use the following switch statement to find the correct variant
 164//
 165//	switch variant := AnnotationUnion.AsAny().(type) {
 166//	case FileCitationAnnotation:
 167//	case FilePathAnnotation:
 168//	default:
 169//	  fmt.Errorf("no variant present")
 170//	}
 171func (u AnnotationUnion) AsAny() any {
 172	switch u.Type {
 173	case "file_citation":
 174		return u.AsFileCitation()
 175	case "file_path":
 176		return u.AsFilePath()
 177	}
 178	return nil
 179}
 180
 181func (u AnnotationUnion) AsFileCitation() (v FileCitationAnnotation) {
 182	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 183	return
 184}
 185
 186func (u AnnotationUnion) AsFilePath() (v FilePathAnnotation) {
 187	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 188	return
 189}
 190
 191// Returns the unmodified JSON received from the API
 192func (u AnnotationUnion) RawJSON() string { return u.JSON.raw }
 193
 194func (r *AnnotationUnion) UnmarshalJSON(data []byte) error {
 195	return apijson.UnmarshalRoot(data, r)
 196}
 197
 198// AnnotationDeltaUnion contains all possible properties and values from
 199// [FileCitationDeltaAnnotation], [FilePathDeltaAnnotation].
 200//
 201// Use the [AnnotationDeltaUnion.AsAny] method to switch on the variant.
 202//
 203// Use the methods beginning with 'As' to cast the union to one of its variants.
 204type AnnotationDeltaUnion struct {
 205	Index int64 `json:"index"`
 206	// Any of "file_citation", "file_path".
 207	Type     string `json:"type"`
 208	EndIndex int64  `json:"end_index"`
 209	// This field is from variant [FileCitationDeltaAnnotation].
 210	FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
 211	StartIndex   int64                                   `json:"start_index"`
 212	Text         string                                  `json:"text"`
 213	// This field is from variant [FilePathDeltaAnnotation].
 214	FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
 215	JSON     struct {
 216		Index        resp.Field
 217		Type         resp.Field
 218		EndIndex     resp.Field
 219		FileCitation resp.Field
 220		StartIndex   resp.Field
 221		Text         resp.Field
 222		FilePath     resp.Field
 223		raw          string
 224	} `json:"-"`
 225}
 226
 227// Use the following switch statement to find the correct variant
 228//
 229//	switch variant := AnnotationDeltaUnion.AsAny().(type) {
 230//	case FileCitationDeltaAnnotation:
 231//	case FilePathDeltaAnnotation:
 232//	default:
 233//	  fmt.Errorf("no variant present")
 234//	}
 235func (u AnnotationDeltaUnion) AsAny() any {
 236	switch u.Type {
 237	case "file_citation":
 238		return u.AsFileCitation()
 239	case "file_path":
 240		return u.AsFilePath()
 241	}
 242	return nil
 243}
 244
 245func (u AnnotationDeltaUnion) AsFileCitation() (v FileCitationDeltaAnnotation) {
 246	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 247	return
 248}
 249
 250func (u AnnotationDeltaUnion) AsFilePath() (v FilePathDeltaAnnotation) {
 251	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 252	return
 253}
 254
 255// Returns the unmodified JSON received from the API
 256func (u AnnotationDeltaUnion) RawJSON() string { return u.JSON.raw }
 257
 258func (r *AnnotationDeltaUnion) UnmarshalJSON(data []byte) error {
 259	return apijson.UnmarshalRoot(data, r)
 260}
 261
 262// A citation within the message that points to a specific quote from a specific
 263// File associated with the assistant or the message. Generated when the assistant
 264// uses the "file_search" tool to search files.
 265type FileCitationAnnotation struct {
 266	EndIndex     int64                              `json:"end_index,required"`
 267	FileCitation FileCitationAnnotationFileCitation `json:"file_citation,required"`
 268	StartIndex   int64                              `json:"start_index,required"`
 269	// The text in the message content that needs to be replaced.
 270	Text string `json:"text,required"`
 271	// Always `file_citation`.
 272	Type constant.FileCitation `json:"type,required"`
 273	// Metadata for the response, check the presence of optional fields with the
 274	// [resp.Field.IsPresent] method.
 275	JSON struct {
 276		EndIndex     resp.Field
 277		FileCitation resp.Field
 278		StartIndex   resp.Field
 279		Text         resp.Field
 280		Type         resp.Field
 281		ExtraFields  map[string]resp.Field
 282		raw          string
 283	} `json:"-"`
 284}
 285
 286// Returns the unmodified JSON received from the API
 287func (r FileCitationAnnotation) RawJSON() string { return r.JSON.raw }
 288func (r *FileCitationAnnotation) UnmarshalJSON(data []byte) error {
 289	return apijson.UnmarshalRoot(data, r)
 290}
 291
 292type FileCitationAnnotationFileCitation struct {
 293	// The ID of the specific File the citation is from.
 294	FileID string `json:"file_id,required"`
 295	// Metadata for the response, check the presence of optional fields with the
 296	// [resp.Field.IsPresent] method.
 297	JSON struct {
 298		FileID      resp.Field
 299		ExtraFields map[string]resp.Field
 300		raw         string
 301	} `json:"-"`
 302}
 303
 304// Returns the unmodified JSON received from the API
 305func (r FileCitationAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
 306func (r *FileCitationAnnotationFileCitation) UnmarshalJSON(data []byte) error {
 307	return apijson.UnmarshalRoot(data, r)
 308}
 309
 310// A citation within the message that points to a specific quote from a specific
 311// File associated with the assistant or the message. Generated when the assistant
 312// uses the "file_search" tool to search files.
 313type FileCitationDeltaAnnotation struct {
 314	// The index of the annotation in the text content part.
 315	Index int64 `json:"index,required"`
 316	// Always `file_citation`.
 317	Type         constant.FileCitation                   `json:"type,required"`
 318	EndIndex     int64                                   `json:"end_index"`
 319	FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
 320	StartIndex   int64                                   `json:"start_index"`
 321	// The text in the message content that needs to be replaced.
 322	Text string `json:"text"`
 323	// Metadata for the response, check the presence of optional fields with the
 324	// [resp.Field.IsPresent] method.
 325	JSON struct {
 326		Index        resp.Field
 327		Type         resp.Field
 328		EndIndex     resp.Field
 329		FileCitation resp.Field
 330		StartIndex   resp.Field
 331		Text         resp.Field
 332		ExtraFields  map[string]resp.Field
 333		raw          string
 334	} `json:"-"`
 335}
 336
 337// Returns the unmodified JSON received from the API
 338func (r FileCitationDeltaAnnotation) RawJSON() string { return r.JSON.raw }
 339func (r *FileCitationDeltaAnnotation) UnmarshalJSON(data []byte) error {
 340	return apijson.UnmarshalRoot(data, r)
 341}
 342
 343type FileCitationDeltaAnnotationFileCitation struct {
 344	// The ID of the specific File the citation is from.
 345	FileID string `json:"file_id"`
 346	// The specific quote in the file.
 347	Quote string `json:"quote"`
 348	// Metadata for the response, check the presence of optional fields with the
 349	// [resp.Field.IsPresent] method.
 350	JSON struct {
 351		FileID      resp.Field
 352		Quote       resp.Field
 353		ExtraFields map[string]resp.Field
 354		raw         string
 355	} `json:"-"`
 356}
 357
 358// Returns the unmodified JSON received from the API
 359func (r FileCitationDeltaAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
 360func (r *FileCitationDeltaAnnotationFileCitation) UnmarshalJSON(data []byte) error {
 361	return apijson.UnmarshalRoot(data, r)
 362}
 363
 364// A URL for the file that's generated when the assistant used the
 365// `code_interpreter` tool to generate a file.
 366type FilePathAnnotation struct {
 367	EndIndex   int64                      `json:"end_index,required"`
 368	FilePath   FilePathAnnotationFilePath `json:"file_path,required"`
 369	StartIndex int64                      `json:"start_index,required"`
 370	// The text in the message content that needs to be replaced.
 371	Text string `json:"text,required"`
 372	// Always `file_path`.
 373	Type constant.FilePath `json:"type,required"`
 374	// Metadata for the response, check the presence of optional fields with the
 375	// [resp.Field.IsPresent] method.
 376	JSON struct {
 377		EndIndex    resp.Field
 378		FilePath    resp.Field
 379		StartIndex  resp.Field
 380		Text        resp.Field
 381		Type        resp.Field
 382		ExtraFields map[string]resp.Field
 383		raw         string
 384	} `json:"-"`
 385}
 386
 387// Returns the unmodified JSON received from the API
 388func (r FilePathAnnotation) RawJSON() string { return r.JSON.raw }
 389func (r *FilePathAnnotation) UnmarshalJSON(data []byte) error {
 390	return apijson.UnmarshalRoot(data, r)
 391}
 392
 393type FilePathAnnotationFilePath struct {
 394	// The ID of the file that was generated.
 395	FileID string `json:"file_id,required"`
 396	// Metadata for the response, check the presence of optional fields with the
 397	// [resp.Field.IsPresent] method.
 398	JSON struct {
 399		FileID      resp.Field
 400		ExtraFields map[string]resp.Field
 401		raw         string
 402	} `json:"-"`
 403}
 404
 405// Returns the unmodified JSON received from the API
 406func (r FilePathAnnotationFilePath) RawJSON() string { return r.JSON.raw }
 407func (r *FilePathAnnotationFilePath) UnmarshalJSON(data []byte) error {
 408	return apijson.UnmarshalRoot(data, r)
 409}
 410
 411// A URL for the file that's generated when the assistant used the
 412// `code_interpreter` tool to generate a file.
 413type FilePathDeltaAnnotation struct {
 414	// The index of the annotation in the text content part.
 415	Index int64 `json:"index,required"`
 416	// Always `file_path`.
 417	Type       constant.FilePath               `json:"type,required"`
 418	EndIndex   int64                           `json:"end_index"`
 419	FilePath   FilePathDeltaAnnotationFilePath `json:"file_path"`
 420	StartIndex int64                           `json:"start_index"`
 421	// The text in the message content that needs to be replaced.
 422	Text string `json:"text"`
 423	// Metadata for the response, check the presence of optional fields with the
 424	// [resp.Field.IsPresent] method.
 425	JSON struct {
 426		Index       resp.Field
 427		Type        resp.Field
 428		EndIndex    resp.Field
 429		FilePath    resp.Field
 430		StartIndex  resp.Field
 431		Text        resp.Field
 432		ExtraFields map[string]resp.Field
 433		raw         string
 434	} `json:"-"`
 435}
 436
 437// Returns the unmodified JSON received from the API
 438func (r FilePathDeltaAnnotation) RawJSON() string { return r.JSON.raw }
 439func (r *FilePathDeltaAnnotation) UnmarshalJSON(data []byte) error {
 440	return apijson.UnmarshalRoot(data, r)
 441}
 442
 443type FilePathDeltaAnnotationFilePath struct {
 444	// The ID of the file that was generated.
 445	FileID string `json:"file_id"`
 446	// Metadata for the response, check the presence of optional fields with the
 447	// [resp.Field.IsPresent] method.
 448	JSON struct {
 449		FileID      resp.Field
 450		ExtraFields map[string]resp.Field
 451		raw         string
 452	} `json:"-"`
 453}
 454
 455// Returns the unmodified JSON received from the API
 456func (r FilePathDeltaAnnotationFilePath) RawJSON() string { return r.JSON.raw }
 457func (r *FilePathDeltaAnnotationFilePath) UnmarshalJSON(data []byte) error {
 458	return apijson.UnmarshalRoot(data, r)
 459}
 460
 461type ImageFile struct {
 462	// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
 463	// in the message content. Set `purpose="vision"` when uploading the File if you
 464	// need to later display the file content.
 465	FileID string `json:"file_id,required"`
 466	// Specifies the detail level of the image if specified by the user. `low` uses
 467	// fewer tokens, you can opt in to high resolution using `high`.
 468	//
 469	// Any of "auto", "low", "high".
 470	Detail ImageFileDetail `json:"detail"`
 471	// Metadata for the response, check the presence of optional fields with the
 472	// [resp.Field.IsPresent] method.
 473	JSON struct {
 474		FileID      resp.Field
 475		Detail      resp.Field
 476		ExtraFields map[string]resp.Field
 477		raw         string
 478	} `json:"-"`
 479}
 480
 481// Returns the unmodified JSON received from the API
 482func (r ImageFile) RawJSON() string { return r.JSON.raw }
 483func (r *ImageFile) UnmarshalJSON(data []byte) error {
 484	return apijson.UnmarshalRoot(data, r)
 485}
 486
 487// ToParam converts this ImageFile to a ImageFileParam.
 488//
 489// Warning: the fields of the param type will not be present. ToParam should only
 490// be used at the last possible moment before sending a request. Test for this with
 491// ImageFileParam.IsOverridden()
 492func (r ImageFile) ToParam() ImageFileParam {
 493	return param.OverrideObj[ImageFileParam](r.RawJSON())
 494}
 495
 496// Specifies the detail level of the image if specified by the user. `low` uses
 497// fewer tokens, you can opt in to high resolution using `high`.
 498type ImageFileDetail string
 499
 500const (
 501	ImageFileDetailAuto ImageFileDetail = "auto"
 502	ImageFileDetailLow  ImageFileDetail = "low"
 503	ImageFileDetailHigh ImageFileDetail = "high"
 504)
 505
 506// The property FileID is required.
 507type ImageFileParam struct {
 508	// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
 509	// in the message content. Set `purpose="vision"` when uploading the File if you
 510	// need to later display the file content.
 511	FileID string `json:"file_id,required"`
 512	// Specifies the detail level of the image if specified by the user. `low` uses
 513	// fewer tokens, you can opt in to high resolution using `high`.
 514	//
 515	// Any of "auto", "low", "high".
 516	Detail ImageFileDetail `json:"detail,omitzero"`
 517	paramObj
 518}
 519
 520// IsPresent returns true if the field's value is not omitted and not the JSON
 521// "null". To check if this field is omitted, use [param.IsOmitted].
 522func (f ImageFileParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
 523func (r ImageFileParam) MarshalJSON() (data []byte, err error) {
 524	type shadow ImageFileParam
 525	return param.MarshalObject(r, (*shadow)(&r))
 526}
 527
 528// References an image [File](https://platform.openai.com/docs/api-reference/files)
 529// in the content of a message.
 530type ImageFileContentBlock struct {
 531	ImageFile ImageFile `json:"image_file,required"`
 532	// Always `image_file`.
 533	Type constant.ImageFile `json:"type,required"`
 534	// Metadata for the response, check the presence of optional fields with the
 535	// [resp.Field.IsPresent] method.
 536	JSON struct {
 537		ImageFile   resp.Field
 538		Type        resp.Field
 539		ExtraFields map[string]resp.Field
 540		raw         string
 541	} `json:"-"`
 542}
 543
 544// Returns the unmodified JSON received from the API
 545func (r ImageFileContentBlock) RawJSON() string { return r.JSON.raw }
 546func (r *ImageFileContentBlock) UnmarshalJSON(data []byte) error {
 547	return apijson.UnmarshalRoot(data, r)
 548}
 549
 550// ToParam converts this ImageFileContentBlock to a ImageFileContentBlockParam.
 551//
 552// Warning: the fields of the param type will not be present. ToParam should only
 553// be used at the last possible moment before sending a request. Test for this with
 554// ImageFileContentBlockParam.IsOverridden()
 555func (r ImageFileContentBlock) ToParam() ImageFileContentBlockParam {
 556	return param.OverrideObj[ImageFileContentBlockParam](r.RawJSON())
 557}
 558
 559// References an image [File](https://platform.openai.com/docs/api-reference/files)
 560// in the content of a message.
 561//
 562// The properties ImageFile, Type are required.
 563type ImageFileContentBlockParam struct {
 564	ImageFile ImageFileParam `json:"image_file,omitzero,required"`
 565	// Always `image_file`.
 566	//
 567	// This field can be elided, and will marshal its zero value as "image_file".
 568	Type constant.ImageFile `json:"type,required"`
 569	paramObj
 570}
 571
 572// IsPresent returns true if the field's value is not omitted and not the JSON
 573// "null". To check if this field is omitted, use [param.IsOmitted].
 574func (f ImageFileContentBlockParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
 575func (r ImageFileContentBlockParam) MarshalJSON() (data []byte, err error) {
 576	type shadow ImageFileContentBlockParam
 577	return param.MarshalObject(r, (*shadow)(&r))
 578}
 579
 580type ImageFileDelta struct {
 581	// Specifies the detail level of the image if specified by the user. `low` uses
 582	// fewer tokens, you can opt in to high resolution using `high`.
 583	//
 584	// Any of "auto", "low", "high".
 585	Detail ImageFileDeltaDetail `json:"detail"`
 586	// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
 587	// in the message content. Set `purpose="vision"` when uploading the File if you
 588	// need to later display the file content.
 589	FileID string `json:"file_id"`
 590	// Metadata for the response, check the presence of optional fields with the
 591	// [resp.Field.IsPresent] method.
 592	JSON struct {
 593		Detail      resp.Field
 594		FileID      resp.Field
 595		ExtraFields map[string]resp.Field
 596		raw         string
 597	} `json:"-"`
 598}
 599
 600// Returns the unmodified JSON received from the API
 601func (r ImageFileDelta) RawJSON() string { return r.JSON.raw }
 602func (r *ImageFileDelta) UnmarshalJSON(data []byte) error {
 603	return apijson.UnmarshalRoot(data, r)
 604}
 605
 606// Specifies the detail level of the image if specified by the user. `low` uses
 607// fewer tokens, you can opt in to high resolution using `high`.
 608type ImageFileDeltaDetail string
 609
 610const (
 611	ImageFileDeltaDetailAuto ImageFileDeltaDetail = "auto"
 612	ImageFileDeltaDetailLow  ImageFileDeltaDetail = "low"
 613	ImageFileDeltaDetailHigh ImageFileDeltaDetail = "high"
 614)
 615
 616// References an image [File](https://platform.openai.com/docs/api-reference/files)
 617// in the content of a message.
 618type ImageFileDeltaBlock struct {
 619	// The index of the content part in the message.
 620	Index int64 `json:"index,required"`
 621	// Always `image_file`.
 622	Type      constant.ImageFile `json:"type,required"`
 623	ImageFile ImageFileDelta     `json:"image_file"`
 624	// Metadata for the response, check the presence of optional fields with the
 625	// [resp.Field.IsPresent] method.
 626	JSON struct {
 627		Index       resp.Field
 628		Type        resp.Field
 629		ImageFile   resp.Field
 630		ExtraFields map[string]resp.Field
 631		raw         string
 632	} `json:"-"`
 633}
 634
 635// Returns the unmodified JSON received from the API
 636func (r ImageFileDeltaBlock) RawJSON() string { return r.JSON.raw }
 637func (r *ImageFileDeltaBlock) UnmarshalJSON(data []byte) error {
 638	return apijson.UnmarshalRoot(data, r)
 639}
 640
 641type ImageURL struct {
 642	// The external URL of the image, must be a supported image types: jpeg, jpg, png,
 643	// gif, webp.
 644	URL string `json:"url,required" format:"uri"`
 645	// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
 646	// to high resolution using `high`. Default value is `auto`
 647	//
 648	// Any of "auto", "low", "high".
 649	Detail ImageURLDetail `json:"detail"`
 650	// Metadata for the response, check the presence of optional fields with the
 651	// [resp.Field.IsPresent] method.
 652	JSON struct {
 653		URL         resp.Field
 654		Detail      resp.Field
 655		ExtraFields map[string]resp.Field
 656		raw         string
 657	} `json:"-"`
 658}
 659
 660// Returns the unmodified JSON received from the API
 661func (r ImageURL) RawJSON() string { return r.JSON.raw }
 662func (r *ImageURL) UnmarshalJSON(data []byte) error {
 663	return apijson.UnmarshalRoot(data, r)
 664}
 665
 666// ToParam converts this ImageURL to a ImageURLParam.
 667//
 668// Warning: the fields of the param type will not be present. ToParam should only
 669// be used at the last possible moment before sending a request. Test for this with
 670// ImageURLParam.IsOverridden()
 671func (r ImageURL) ToParam() ImageURLParam {
 672	return param.OverrideObj[ImageURLParam](r.RawJSON())
 673}
 674
 675// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
 676// to high resolution using `high`. Default value is `auto`
 677type ImageURLDetail string
 678
 679const (
 680	ImageURLDetailAuto ImageURLDetail = "auto"
 681	ImageURLDetailLow  ImageURLDetail = "low"
 682	ImageURLDetailHigh ImageURLDetail = "high"
 683)
 684
 685// The property URL is required.
 686type ImageURLParam struct {
 687	// The external URL of the image, must be a supported image types: jpeg, jpg, png,
 688	// gif, webp.
 689	URL string `json:"url,required" format:"uri"`
 690	// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
 691	// to high resolution using `high`. Default value is `auto`
 692	//
 693	// Any of "auto", "low", "high".
 694	Detail ImageURLDetail `json:"detail,omitzero"`
 695	paramObj
 696}
 697
 698// IsPresent returns true if the field's value is not omitted and not the JSON
 699// "null". To check if this field is omitted, use [param.IsOmitted].
 700func (f ImageURLParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
 701func (r ImageURLParam) MarshalJSON() (data []byte, err error) {
 702	type shadow ImageURLParam
 703	return param.MarshalObject(r, (*shadow)(&r))
 704}
 705
 706// References an image URL in the content of a message.
 707type ImageURLContentBlock struct {
 708	ImageURL ImageURL `json:"image_url,required"`
 709	// The type of the content part.
 710	Type constant.ImageURL `json:"type,required"`
 711	// Metadata for the response, check the presence of optional fields with the
 712	// [resp.Field.IsPresent] method.
 713	JSON struct {
 714		ImageURL    resp.Field
 715		Type        resp.Field
 716		ExtraFields map[string]resp.Field
 717		raw         string
 718	} `json:"-"`
 719}
 720
 721// Returns the unmodified JSON received from the API
 722func (r ImageURLContentBlock) RawJSON() string { return r.JSON.raw }
 723func (r *ImageURLContentBlock) UnmarshalJSON(data []byte) error {
 724	return apijson.UnmarshalRoot(data, r)
 725}
 726
 727// ToParam converts this ImageURLContentBlock to a ImageURLContentBlockParam.
 728//
 729// Warning: the fields of the param type will not be present. ToParam should only
 730// be used at the last possible moment before sending a request. Test for this with
 731// ImageURLContentBlockParam.IsOverridden()
 732func (r ImageURLContentBlock) ToParam() ImageURLContentBlockParam {
 733	return param.OverrideObj[ImageURLContentBlockParam](r.RawJSON())
 734}
 735
 736// References an image URL in the content of a message.
 737//
 738// The properties ImageURL, Type are required.
 739type ImageURLContentBlockParam struct {
 740	ImageURL ImageURLParam `json:"image_url,omitzero,required"`
 741	// The type of the content part.
 742	//
 743	// This field can be elided, and will marshal its zero value as "image_url".
 744	Type constant.ImageURL `json:"type,required"`
 745	paramObj
 746}
 747
 748// IsPresent returns true if the field's value is not omitted and not the JSON
 749// "null". To check if this field is omitted, use [param.IsOmitted].
 750func (f ImageURLContentBlockParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
 751func (r ImageURLContentBlockParam) MarshalJSON() (data []byte, err error) {
 752	type shadow ImageURLContentBlockParam
 753	return param.MarshalObject(r, (*shadow)(&r))
 754}
 755
 756type ImageURLDelta struct {
 757	// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
 758	// to high resolution using `high`.
 759	//
 760	// Any of "auto", "low", "high".
 761	Detail ImageURLDeltaDetail `json:"detail"`
 762	// The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
 763	// webp.
 764	URL string `json:"url"`
 765	// Metadata for the response, check the presence of optional fields with the
 766	// [resp.Field.IsPresent] method.
 767	JSON struct {
 768		Detail      resp.Field
 769		URL         resp.Field
 770		ExtraFields map[string]resp.Field
 771		raw         string
 772	} `json:"-"`
 773}
 774
 775// Returns the unmodified JSON received from the API
 776func (r ImageURLDelta) RawJSON() string { return r.JSON.raw }
 777func (r *ImageURLDelta) UnmarshalJSON(data []byte) error {
 778	return apijson.UnmarshalRoot(data, r)
 779}
 780
 781// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
 782// to high resolution using `high`.
 783type ImageURLDeltaDetail string
 784
 785const (
 786	ImageURLDeltaDetailAuto ImageURLDeltaDetail = "auto"
 787	ImageURLDeltaDetailLow  ImageURLDeltaDetail = "low"
 788	ImageURLDeltaDetailHigh ImageURLDeltaDetail = "high"
 789)
 790
 791// References an image URL in the content of a message.
 792type ImageURLDeltaBlock struct {
 793	// The index of the content part in the message.
 794	Index int64 `json:"index,required"`
 795	// Always `image_url`.
 796	Type     constant.ImageURL `json:"type,required"`
 797	ImageURL ImageURLDelta     `json:"image_url"`
 798	// Metadata for the response, check the presence of optional fields with the
 799	// [resp.Field.IsPresent] method.
 800	JSON struct {
 801		Index       resp.Field
 802		Type        resp.Field
 803		ImageURL    resp.Field
 804		ExtraFields map[string]resp.Field
 805		raw         string
 806	} `json:"-"`
 807}
 808
 809// Returns the unmodified JSON received from the API
 810func (r ImageURLDeltaBlock) RawJSON() string { return r.JSON.raw }
 811func (r *ImageURLDeltaBlock) UnmarshalJSON(data []byte) error {
 812	return apijson.UnmarshalRoot(data, r)
 813}
 814
 815// Represents a message within a
 816// [thread](https://platform.openai.com/docs/api-reference/threads).
 817type Message struct {
 818	// The identifier, which can be referenced in API endpoints.
 819	ID string `json:"id,required"`
 820	// If applicable, the ID of the
 821	// [assistant](https://platform.openai.com/docs/api-reference/assistants) that
 822	// authored this message.
 823	AssistantID string `json:"assistant_id,required"`
 824	// A list of files attached to the message, and the tools they were added to.
 825	Attachments []MessageAttachment `json:"attachments,required"`
 826	// The Unix timestamp (in seconds) for when the message was completed.
 827	CompletedAt int64 `json:"completed_at,required"`
 828	// The content of the message in array of text and/or images.
 829	Content []MessageContentUnion `json:"content,required"`
 830	// The Unix timestamp (in seconds) for when the message was created.
 831	CreatedAt int64 `json:"created_at,required"`
 832	// The Unix timestamp (in seconds) for when the message was marked as incomplete.
 833	IncompleteAt int64 `json:"incomplete_at,required"`
 834	// On an incomplete message, details about why the message is incomplete.
 835	IncompleteDetails MessageIncompleteDetails `json:"incomplete_details,required"`
 836	// Set of 16 key-value pairs that can be attached to an object. This can be useful
 837	// for storing additional information about the object in a structured format, and
 838	// querying for objects via API or the dashboard.
 839	//
 840	// Keys are strings with a maximum length of 64 characters. Values are strings with
 841	// a maximum length of 512 characters.
 842	Metadata shared.Metadata `json:"metadata,required"`
 843	// The object type, which is always `thread.message`.
 844	Object constant.ThreadMessage `json:"object,required"`
 845	// The entity that produced the message. One of `user` or `assistant`.
 846	//
 847	// Any of "user", "assistant".
 848	Role MessageRole `json:"role,required"`
 849	// The ID of the [run](https://platform.openai.com/docs/api-reference/runs)
 850	// associated with the creation of this message. Value is `null` when messages are
 851	// created manually using the create message or create thread endpoints.
 852	RunID string `json:"run_id,required"`
 853	// The status of the message, which can be either `in_progress`, `incomplete`, or
 854	// `completed`.
 855	//
 856	// Any of "in_progress", "incomplete", "completed".
 857	Status MessageStatus `json:"status,required"`
 858	// The [thread](https://platform.openai.com/docs/api-reference/threads) ID that
 859	// this message belongs to.
 860	ThreadID string `json:"thread_id,required"`
 861	// Metadata for the response, check the presence of optional fields with the
 862	// [resp.Field.IsPresent] method.
 863	JSON struct {
 864		ID                resp.Field
 865		AssistantID       resp.Field
 866		Attachments       resp.Field
 867		CompletedAt       resp.Field
 868		Content           resp.Field
 869		CreatedAt         resp.Field
 870		IncompleteAt      resp.Field
 871		IncompleteDetails resp.Field
 872		Metadata          resp.Field
 873		Object            resp.Field
 874		Role              resp.Field
 875		RunID             resp.Field
 876		Status            resp.Field
 877		ThreadID          resp.Field
 878		ExtraFields       map[string]resp.Field
 879		raw               string
 880	} `json:"-"`
 881}
 882
 883// Returns the unmodified JSON received from the API
 884func (r Message) RawJSON() string { return r.JSON.raw }
 885func (r *Message) UnmarshalJSON(data []byte) error {
 886	return apijson.UnmarshalRoot(data, r)
 887}
 888
 889type MessageAttachment struct {
 890	// The ID of the file to attach to the message.
 891	FileID string `json:"file_id"`
 892	// The tools to add this file to.
 893	Tools []MessageAttachmentToolUnion `json:"tools"`
 894	// Metadata for the response, check the presence of optional fields with the
 895	// [resp.Field.IsPresent] method.
 896	JSON struct {
 897		FileID      resp.Field
 898		Tools       resp.Field
 899		ExtraFields map[string]resp.Field
 900		raw         string
 901	} `json:"-"`
 902}
 903
 904// Returns the unmodified JSON received from the API
 905func (r MessageAttachment) RawJSON() string { return r.JSON.raw }
 906func (r *MessageAttachment) UnmarshalJSON(data []byte) error {
 907	return apijson.UnmarshalRoot(data, r)
 908}
 909
 910// MessageAttachmentToolUnion contains all possible properties and values from
 911// [CodeInterpreterTool], [MessageAttachmentToolAssistantToolsFileSearchTypeOnly].
 912//
 913// Use the methods beginning with 'As' to cast the union to one of its variants.
 914type MessageAttachmentToolUnion struct {
 915	Type string `json:"type"`
 916	JSON struct {
 917		Type resp.Field
 918		raw  string
 919	} `json:"-"`
 920}
 921
 922func (u MessageAttachmentToolUnion) AsCodeInterpreterTool() (v CodeInterpreterTool) {
 923	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 924	return
 925}
 926
 927func (u MessageAttachmentToolUnion) AsFileSearchTool() (v MessageAttachmentToolAssistantToolsFileSearchTypeOnly) {
 928	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
 929	return
 930}
 931
 932// Returns the unmodified JSON received from the API
 933func (u MessageAttachmentToolUnion) RawJSON() string { return u.JSON.raw }
 934
 935func (r *MessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
 936	return apijson.UnmarshalRoot(data, r)
 937}
 938
 939type MessageAttachmentToolAssistantToolsFileSearchTypeOnly struct {
 940	// The type of tool being defined: `file_search`
 941	Type constant.FileSearch `json:"type,required"`
 942	// Metadata for the response, check the presence of optional fields with the
 943	// [resp.Field.IsPresent] method.
 944	JSON struct {
 945		Type        resp.Field
 946		ExtraFields map[string]resp.Field
 947		raw         string
 948	} `json:"-"`
 949}
 950
 951// Returns the unmodified JSON received from the API
 952func (r MessageAttachmentToolAssistantToolsFileSearchTypeOnly) RawJSON() string { return r.JSON.raw }
 953func (r *MessageAttachmentToolAssistantToolsFileSearchTypeOnly) UnmarshalJSON(data []byte) error {
 954	return apijson.UnmarshalRoot(data, r)
 955}
 956
 957// On an incomplete message, details about why the message is incomplete.
 958type MessageIncompleteDetails struct {
 959	// The reason the message is incomplete.
 960	//
 961	// Any of "content_filter", "max_tokens", "run_cancelled", "run_expired",
 962	// "run_failed".
 963	Reason string `json:"reason,required"`
 964	// Metadata for the response, check the presence of optional fields with the
 965	// [resp.Field.IsPresent] method.
 966	JSON struct {
 967		Reason      resp.Field
 968		ExtraFields map[string]resp.Field
 969		raw         string
 970	} `json:"-"`
 971}
 972
 973// Returns the unmodified JSON received from the API
 974func (r MessageIncompleteDetails) RawJSON() string { return r.JSON.raw }
 975func (r *MessageIncompleteDetails) UnmarshalJSON(data []byte) error {
 976	return apijson.UnmarshalRoot(data, r)
 977}
 978
 979// The entity that produced the message. One of `user` or `assistant`.
 980type MessageRole string
 981
 982const (
 983	MessageRoleUser      MessageRole = "user"
 984	MessageRoleAssistant MessageRole = "assistant"
 985)
 986
 987// The status of the message, which can be either `in_progress`, `incomplete`, or
 988// `completed`.
 989type MessageStatus string
 990
 991const (
 992	MessageStatusInProgress MessageStatus = "in_progress"
 993	MessageStatusIncomplete MessageStatus = "incomplete"
 994	MessageStatusCompleted  MessageStatus = "completed"
 995)
 996
 997// MessageContentUnion contains all possible properties and values from
 998// [ImageFileContentBlock], [ImageURLContentBlock], [TextContentBlock],
 999// [RefusalContentBlock].
1000//
1001// Use the [MessageContentUnion.AsAny] method to switch on the variant.
1002//
1003// Use the methods beginning with 'As' to cast the union to one of its variants.
1004type MessageContentUnion struct {
1005	// This field is from variant [ImageFileContentBlock].
1006	ImageFile ImageFile `json:"image_file"`
1007	// Any of "image_file", "image_url", "text", "refusal".
1008	Type string `json:"type"`
1009	// This field is from variant [ImageURLContentBlock].
1010	ImageURL ImageURL `json:"image_url"`
1011	// This field is from variant [TextContentBlock].
1012	Text Text `json:"text"`
1013	// This field is from variant [RefusalContentBlock].
1014	Refusal string `json:"refusal"`
1015	JSON    struct {
1016		ImageFile resp.Field
1017		Type      resp.Field
1018		ImageURL  resp.Field
1019		Text      resp.Field
1020		Refusal   resp.Field
1021		raw       string
1022	} `json:"-"`
1023}
1024
1025// Use the following switch statement to find the correct variant
1026//
1027//	switch variant := MessageContentUnion.AsAny().(type) {
1028//	case ImageFileContentBlock:
1029//	case ImageURLContentBlock:
1030//	case TextContentBlock:
1031//	case RefusalContentBlock:
1032//	default:
1033//	  fmt.Errorf("no variant present")
1034//	}
1035func (u MessageContentUnion) AsAny() any {
1036	switch u.Type {
1037	case "image_file":
1038		return u.AsImageFile()
1039	case "image_url":
1040		return u.AsImageURL()
1041	case "text":
1042		return u.AsText()
1043	case "refusal":
1044		return u.AsRefusal()
1045	}
1046	return nil
1047}
1048
1049func (u MessageContentUnion) AsImageFile() (v ImageFileContentBlock) {
1050	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1051	return
1052}
1053
1054func (u MessageContentUnion) AsImageURL() (v ImageURLContentBlock) {
1055	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1056	return
1057}
1058
1059func (u MessageContentUnion) AsText() (v TextContentBlock) {
1060	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1061	return
1062}
1063
1064func (u MessageContentUnion) AsRefusal() (v RefusalContentBlock) {
1065	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1066	return
1067}
1068
1069// Returns the unmodified JSON received from the API
1070func (u MessageContentUnion) RawJSON() string { return u.JSON.raw }
1071
1072func (r *MessageContentUnion) UnmarshalJSON(data []byte) error {
1073	return apijson.UnmarshalRoot(data, r)
1074}
1075
1076// MessageContentDeltaUnion contains all possible properties and values from
1077// [ImageFileDeltaBlock], [TextDeltaBlock], [RefusalDeltaBlock],
1078// [ImageURLDeltaBlock].
1079//
1080// Use the [MessageContentDeltaUnion.AsAny] method to switch on the variant.
1081//
1082// Use the methods beginning with 'As' to cast the union to one of its variants.
1083type MessageContentDeltaUnion struct {
1084	Index int64 `json:"index"`
1085	// Any of "image_file", "text", "refusal", "image_url".
1086	Type string `json:"type"`
1087	// This field is from variant [ImageFileDeltaBlock].
1088	ImageFile ImageFileDelta `json:"image_file"`
1089	// This field is from variant [TextDeltaBlock].
1090	Text TextDelta `json:"text"`
1091	// This field is from variant [RefusalDeltaBlock].
1092	Refusal string `json:"refusal"`
1093	// This field is from variant [ImageURLDeltaBlock].
1094	ImageURL ImageURLDelta `json:"image_url"`
1095	JSON     struct {
1096		Index     resp.Field
1097		Type      resp.Field
1098		ImageFile resp.Field
1099		Text      resp.Field
1100		Refusal   resp.Field
1101		ImageURL  resp.Field
1102		raw       string
1103	} `json:"-"`
1104}
1105
1106// Use the following switch statement to find the correct variant
1107//
1108//	switch variant := MessageContentDeltaUnion.AsAny().(type) {
1109//	case ImageFileDeltaBlock:
1110//	case TextDeltaBlock:
1111//	case RefusalDeltaBlock:
1112//	case ImageURLDeltaBlock:
1113//	default:
1114//	  fmt.Errorf("no variant present")
1115//	}
1116func (u MessageContentDeltaUnion) AsAny() any {
1117	switch u.Type {
1118	case "image_file":
1119		return u.AsImageFile()
1120	case "text":
1121		return u.AsText()
1122	case "refusal":
1123		return u.AsRefusal()
1124	case "image_url":
1125		return u.AsImageURL()
1126	}
1127	return nil
1128}
1129
1130func (u MessageContentDeltaUnion) AsImageFile() (v ImageFileDeltaBlock) {
1131	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1132	return
1133}
1134
1135func (u MessageContentDeltaUnion) AsText() (v TextDeltaBlock) {
1136	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1137	return
1138}
1139
1140func (u MessageContentDeltaUnion) AsRefusal() (v RefusalDeltaBlock) {
1141	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1142	return
1143}
1144
1145func (u MessageContentDeltaUnion) AsImageURL() (v ImageURLDeltaBlock) {
1146	apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1147	return
1148}
1149
1150// Returns the unmodified JSON received from the API
1151func (u MessageContentDeltaUnion) RawJSON() string { return u.JSON.raw }
1152
1153func (r *MessageContentDeltaUnion) UnmarshalJSON(data []byte) error {
1154	return apijson.UnmarshalRoot(data, r)
1155}
1156
1157func MessageContentPartParamOfImageFile(imageFile ImageFileParam) MessageContentPartParamUnion {
1158	var variant ImageFileContentBlockParam
1159	variant.ImageFile = imageFile
1160	return MessageContentPartParamUnion{OfImageFile: &variant}
1161}
1162
1163func MessageContentPartParamOfImageURL(imageURL ImageURLParam) MessageContentPartParamUnion {
1164	var variant ImageURLContentBlockParam
1165	variant.ImageURL = imageURL
1166	return MessageContentPartParamUnion{OfImageURL: &variant}
1167}
1168
1169func MessageContentPartParamOfText(text string) MessageContentPartParamUnion {
1170	var variant TextContentBlockParam
1171	variant.Text = text
1172	return MessageContentPartParamUnion{OfText: &variant}
1173}
1174
1175// Only one field can be non-zero.
1176//
1177// Use [param.IsOmitted] to confirm if a field is set.
1178type MessageContentPartParamUnion struct {
1179	OfImageFile *ImageFileContentBlockParam `json:",omitzero,inline"`
1180	OfImageURL  *ImageURLContentBlockParam  `json:",omitzero,inline"`
1181	OfText      *TextContentBlockParam      `json:",omitzero,inline"`
1182	paramUnion
1183}
1184
1185// IsPresent returns true if the field's value is not omitted and not the JSON
1186// "null". To check if this field is omitted, use [param.IsOmitted].
1187func (u MessageContentPartParamUnion) IsPresent() bool { return !param.IsOmitted(u) && !u.IsNull() }
1188func (u MessageContentPartParamUnion) MarshalJSON() ([]byte, error) {
1189	return param.MarshalUnion[MessageContentPartParamUnion](u.OfImageFile, u.OfImageURL, u.OfText)
1190}
1191
1192func (u *MessageContentPartParamUnion) asAny() any {
1193	if !param.IsOmitted(u.OfImageFile) {
1194		return u.OfImageFile
1195	} else if !param.IsOmitted(u.OfImageURL) {
1196		return u.OfImageURL
1197	} else if !param.IsOmitted(u.OfText) {
1198		return u.OfText
1199	}
1200	return nil
1201}
1202
1203// Returns a pointer to the underlying variant's property, if present.
1204func (u MessageContentPartParamUnion) GetImageFile() *ImageFileParam {
1205	if vt := u.OfImageFile; vt != nil {
1206		return &vt.ImageFile
1207	}
1208	return nil
1209}
1210
1211// Returns a pointer to the underlying variant's property, if present.
1212func (u MessageContentPartParamUnion) GetImageURL() *ImageURLParam {
1213	if vt := u.OfImageURL; vt != nil {
1214		return &vt.ImageURL
1215	}
1216	return nil
1217}
1218
1219// Returns a pointer to the underlying variant's property, if present.
1220func (u MessageContentPartParamUnion) GetText() *string {
1221	if vt := u.OfText; vt != nil {
1222		return &vt.Text
1223	}
1224	return nil
1225}
1226
1227// Returns a pointer to the underlying variant's property, if present.
1228func (u MessageContentPartParamUnion) GetType() *string {
1229	if vt := u.OfImageFile; vt != nil {
1230		return (*string)(&vt.Type)
1231	} else if vt := u.OfImageURL; vt != nil {
1232		return (*string)(&vt.Type)
1233	} else if vt := u.OfText; vt != nil {
1234		return (*string)(&vt.Type)
1235	}
1236	return nil
1237}
1238
1239func init() {
1240	apijson.RegisterUnion[MessageContentPartParamUnion](
1241		"type",
1242		apijson.UnionVariant{
1243			TypeFilter:         gjson.JSON,
1244			Type:               reflect.TypeOf(ImageFileContentBlockParam{}),
1245			DiscriminatorValue: "image_file",
1246		},
1247		apijson.UnionVariant{
1248			TypeFilter:         gjson.JSON,
1249			Type:               reflect.TypeOf(ImageURLContentBlockParam{}),
1250			DiscriminatorValue: "image_url",
1251		},
1252		apijson.UnionVariant{
1253			TypeFilter:         gjson.JSON,
1254			Type:               reflect.TypeOf(TextContentBlockParam{}),
1255			DiscriminatorValue: "text",
1256		},
1257	)
1258}
1259
1260type MessageDeleted struct {
1261	ID      string                        `json:"id,required"`
1262	Deleted bool                          `json:"deleted,required"`
1263	Object  constant.ThreadMessageDeleted `json:"object,required"`
1264	// Metadata for the response, check the presence of optional fields with the
1265	// [resp.Field.IsPresent] method.
1266	JSON struct {
1267		ID          resp.Field
1268		Deleted     resp.Field
1269		Object      resp.Field
1270		ExtraFields map[string]resp.Field
1271		raw         string
1272	} `json:"-"`
1273}
1274
1275// Returns the unmodified JSON received from the API
1276func (r MessageDeleted) RawJSON() string { return r.JSON.raw }
1277func (r *MessageDeleted) UnmarshalJSON(data []byte) error {
1278	return apijson.UnmarshalRoot(data, r)
1279}
1280
1281// The delta containing the fields that have changed on the Message.
1282type MessageDelta struct {
1283	// The content of the message in array of text and/or images.
1284	Content []MessageContentDeltaUnion `json:"content"`
1285	// The entity that produced the message. One of `user` or `assistant`.
1286	//
1287	// Any of "user", "assistant".
1288	Role MessageDeltaRole `json:"role"`
1289	// Metadata for the response, check the presence of optional fields with the
1290	// [resp.Field.IsPresent] method.
1291	JSON struct {
1292		Content     resp.Field
1293		Role        resp.Field
1294		ExtraFields map[string]resp.Field
1295		raw         string
1296	} `json:"-"`
1297}
1298
1299// Returns the unmodified JSON received from the API
1300func (r MessageDelta) RawJSON() string { return r.JSON.raw }
1301func (r *MessageDelta) UnmarshalJSON(data []byte) error {
1302	return apijson.UnmarshalRoot(data, r)
1303}
1304
1305// The entity that produced the message. One of `user` or `assistant`.
1306type MessageDeltaRole string
1307
1308const (
1309	MessageDeltaRoleUser      MessageDeltaRole = "user"
1310	MessageDeltaRoleAssistant MessageDeltaRole = "assistant"
1311)
1312
1313// Represents a message delta i.e. any changed fields on a message during
1314// streaming.
1315type MessageDeltaEvent struct {
1316	// The identifier of the message, which can be referenced in API endpoints.
1317	ID string `json:"id,required"`
1318	// The delta containing the fields that have changed on the Message.
1319	Delta MessageDelta `json:"delta,required"`
1320	// The object type, which is always `thread.message.delta`.
1321	Object constant.ThreadMessageDelta `json:"object,required"`
1322	// Metadata for the response, check the presence of optional fields with the
1323	// [resp.Field.IsPresent] method.
1324	JSON struct {
1325		ID          resp.Field
1326		Delta       resp.Field
1327		Object      resp.Field
1328		ExtraFields map[string]resp.Field
1329		raw         string
1330	} `json:"-"`
1331}
1332
1333// Returns the unmodified JSON received from the API
1334func (r MessageDeltaEvent) RawJSON() string { return r.JSON.raw }
1335func (r *MessageDeltaEvent) UnmarshalJSON(data []byte) error {
1336	return apijson.UnmarshalRoot(data, r)
1337}
1338
1339// The refusal content generated by the assistant.
1340type RefusalContentBlock struct {
1341	Refusal string `json:"refusal,required"`
1342	// Always `refusal`.
1343	Type constant.Refusal `json:"type,required"`
1344	// Metadata for the response, check the presence of optional fields with the
1345	// [resp.Field.IsPresent] method.
1346	JSON struct {
1347		Refusal     resp.Field
1348		Type        resp.Field
1349		ExtraFields map[string]resp.Field
1350		raw         string
1351	} `json:"-"`
1352}
1353
1354// Returns the unmodified JSON received from the API
1355func (r RefusalContentBlock) RawJSON() string { return r.JSON.raw }
1356func (r *RefusalContentBlock) UnmarshalJSON(data []byte) error {
1357	return apijson.UnmarshalRoot(data, r)
1358}
1359
1360// The refusal content that is part of a message.
1361type RefusalDeltaBlock struct {
1362	// The index of the refusal part in the message.
1363	Index int64 `json:"index,required"`
1364	// Always `refusal`.
1365	Type    constant.Refusal `json:"type,required"`
1366	Refusal string           `json:"refusal"`
1367	// Metadata for the response, check the presence of optional fields with the
1368	// [resp.Field.IsPresent] method.
1369	JSON struct {
1370		Index       resp.Field
1371		Type        resp.Field
1372		Refusal     resp.Field
1373		ExtraFields map[string]resp.Field
1374		raw         string
1375	} `json:"-"`
1376}
1377
1378// Returns the unmodified JSON received from the API
1379func (r RefusalDeltaBlock) RawJSON() string { return r.JSON.raw }
1380func (r *RefusalDeltaBlock) UnmarshalJSON(data []byte) error {
1381	return apijson.UnmarshalRoot(data, r)
1382}
1383
1384type Text struct {
1385	Annotations []AnnotationUnion `json:"annotations,required"`
1386	// The data that makes up the text.
1387	Value string `json:"value,required"`
1388	// Metadata for the response, check the presence of optional fields with the
1389	// [resp.Field.IsPresent] method.
1390	JSON struct {
1391		Annotations resp.Field
1392		Value       resp.Field
1393		ExtraFields map[string]resp.Field
1394		raw         string
1395	} `json:"-"`
1396}
1397
1398// Returns the unmodified JSON received from the API
1399func (r Text) RawJSON() string { return r.JSON.raw }
1400func (r *Text) UnmarshalJSON(data []byte) error {
1401	return apijson.UnmarshalRoot(data, r)
1402}
1403
1404// The text content that is part of a message.
1405type TextContentBlock struct {
1406	Text Text `json:"text,required"`
1407	// Always `text`.
1408	Type constant.Text `json:"type,required"`
1409	// Metadata for the response, check the presence of optional fields with the
1410	// [resp.Field.IsPresent] method.
1411	JSON struct {
1412		Text        resp.Field
1413		Type        resp.Field
1414		ExtraFields map[string]resp.Field
1415		raw         string
1416	} `json:"-"`
1417}
1418
1419// Returns the unmodified JSON received from the API
1420func (r TextContentBlock) RawJSON() string { return r.JSON.raw }
1421func (r *TextContentBlock) UnmarshalJSON(data []byte) error {
1422	return apijson.UnmarshalRoot(data, r)
1423}
1424
1425// The text content that is part of a message.
1426//
1427// The properties Text, Type are required.
1428type TextContentBlockParam struct {
1429	// Text content to be sent to the model
1430	Text string `json:"text,required"`
1431	// Always `text`.
1432	//
1433	// This field can be elided, and will marshal its zero value as "text".
1434	Type constant.Text `json:"type,required"`
1435	paramObj
1436}
1437
1438// IsPresent returns true if the field's value is not omitted and not the JSON
1439// "null". To check if this field is omitted, use [param.IsOmitted].
1440func (f TextContentBlockParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1441func (r TextContentBlockParam) MarshalJSON() (data []byte, err error) {
1442	type shadow TextContentBlockParam
1443	return param.MarshalObject(r, (*shadow)(&r))
1444}
1445
1446type TextDelta struct {
1447	Annotations []AnnotationDeltaUnion `json:"annotations"`
1448	// The data that makes up the text.
1449	Value string `json:"value"`
1450	// Metadata for the response, check the presence of optional fields with the
1451	// [resp.Field.IsPresent] method.
1452	JSON struct {
1453		Annotations resp.Field
1454		Value       resp.Field
1455		ExtraFields map[string]resp.Field
1456		raw         string
1457	} `json:"-"`
1458}
1459
1460// Returns the unmodified JSON received from the API
1461func (r TextDelta) RawJSON() string { return r.JSON.raw }
1462func (r *TextDelta) UnmarshalJSON(data []byte) error {
1463	return apijson.UnmarshalRoot(data, r)
1464}
1465
1466// The text content that is part of a message.
1467type TextDeltaBlock struct {
1468	// The index of the content part in the message.
1469	Index int64 `json:"index,required"`
1470	// Always `text`.
1471	Type constant.Text `json:"type,required"`
1472	Text TextDelta     `json:"text"`
1473	// Metadata for the response, check the presence of optional fields with the
1474	// [resp.Field.IsPresent] method.
1475	JSON struct {
1476		Index       resp.Field
1477		Type        resp.Field
1478		Text        resp.Field
1479		ExtraFields map[string]resp.Field
1480		raw         string
1481	} `json:"-"`
1482}
1483
1484// Returns the unmodified JSON received from the API
1485func (r TextDeltaBlock) RawJSON() string { return r.JSON.raw }
1486func (r *TextDeltaBlock) UnmarshalJSON(data []byte) error {
1487	return apijson.UnmarshalRoot(data, r)
1488}
1489
1490type BetaThreadMessageNewParams struct {
1491	// The text contents of the message.
1492	Content BetaThreadMessageNewParamsContentUnion `json:"content,omitzero,required"`
1493	// The role of the entity that is creating the message. Allowed values include:
1494	//
1495	//   - `user`: Indicates the message is sent by an actual user and should be used in
1496	//     most cases to represent user-generated messages.
1497	//   - `assistant`: Indicates the message is generated by the assistant. Use this
1498	//     value to insert messages from the assistant into the conversation.
1499	//
1500	// Any of "user", "assistant".
1501	Role BetaThreadMessageNewParamsRole `json:"role,omitzero,required"`
1502	// A list of files attached to the message, and the tools they should be added to.
1503	Attachments []BetaThreadMessageNewParamsAttachment `json:"attachments,omitzero"`
1504	// Set of 16 key-value pairs that can be attached to an object. This can be useful
1505	// for storing additional information about the object in a structured format, and
1506	// querying for objects via API or the dashboard.
1507	//
1508	// Keys are strings with a maximum length of 64 characters. Values are strings with
1509	// a maximum length of 512 characters.
1510	Metadata shared.MetadataParam `json:"metadata,omitzero"`
1511	paramObj
1512}
1513
1514// IsPresent returns true if the field's value is not omitted and not the JSON
1515// "null". To check if this field is omitted, use [param.IsOmitted].
1516func (f BetaThreadMessageNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1517
1518func (r BetaThreadMessageNewParams) MarshalJSON() (data []byte, err error) {
1519	type shadow BetaThreadMessageNewParams
1520	return param.MarshalObject(r, (*shadow)(&r))
1521}
1522
1523// Only one field can be non-zero.
1524//
1525// Use [param.IsOmitted] to confirm if a field is set.
1526type BetaThreadMessageNewParamsContentUnion struct {
1527	OfString              param.Opt[string]              `json:",omitzero,inline"`
1528	OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
1529	paramUnion
1530}
1531
1532// IsPresent returns true if the field's value is not omitted and not the JSON
1533// "null". To check if this field is omitted, use [param.IsOmitted].
1534func (u BetaThreadMessageNewParamsContentUnion) IsPresent() bool {
1535	return !param.IsOmitted(u) && !u.IsNull()
1536}
1537func (u BetaThreadMessageNewParamsContentUnion) MarshalJSON() ([]byte, error) {
1538	return param.MarshalUnion[BetaThreadMessageNewParamsContentUnion](u.OfString, u.OfArrayOfContentParts)
1539}
1540
1541func (u *BetaThreadMessageNewParamsContentUnion) asAny() any {
1542	if !param.IsOmitted(u.OfString) {
1543		return &u.OfString.Value
1544	} else if !param.IsOmitted(u.OfArrayOfContentParts) {
1545		return &u.OfArrayOfContentParts
1546	}
1547	return nil
1548}
1549
1550// The role of the entity that is creating the message. Allowed values include:
1551//
1552//   - `user`: Indicates the message is sent by an actual user and should be used in
1553//     most cases to represent user-generated messages.
1554//   - `assistant`: Indicates the message is generated by the assistant. Use this
1555//     value to insert messages from the assistant into the conversation.
1556type BetaThreadMessageNewParamsRole string
1557
1558const (
1559	BetaThreadMessageNewParamsRoleUser      BetaThreadMessageNewParamsRole = "user"
1560	BetaThreadMessageNewParamsRoleAssistant BetaThreadMessageNewParamsRole = "assistant"
1561)
1562
1563type BetaThreadMessageNewParamsAttachment struct {
1564	// The ID of the file to attach to the message.
1565	FileID param.Opt[string] `json:"file_id,omitzero"`
1566	// The tools to add this file to.
1567	Tools []BetaThreadMessageNewParamsAttachmentToolUnion `json:"tools,omitzero"`
1568	paramObj
1569}
1570
1571// IsPresent returns true if the field's value is not omitted and not the JSON
1572// "null". To check if this field is omitted, use [param.IsOmitted].
1573func (f BetaThreadMessageNewParamsAttachment) IsPresent() bool {
1574	return !param.IsOmitted(f) && !f.IsNull()
1575}
1576func (r BetaThreadMessageNewParamsAttachment) MarshalJSON() (data []byte, err error) {
1577	type shadow BetaThreadMessageNewParamsAttachment
1578	return param.MarshalObject(r, (*shadow)(&r))
1579}
1580
1581// Only one field can be non-zero.
1582//
1583// Use [param.IsOmitted] to confirm if a field is set.
1584type BetaThreadMessageNewParamsAttachmentToolUnion struct {
1585	OfCodeInterpreter *CodeInterpreterToolParam                           `json:",omitzero,inline"`
1586	OfFileSearch      *BetaThreadMessageNewParamsAttachmentToolFileSearch `json:",omitzero,inline"`
1587	paramUnion
1588}
1589
1590// IsPresent returns true if the field's value is not omitted and not the JSON
1591// "null". To check if this field is omitted, use [param.IsOmitted].
1592func (u BetaThreadMessageNewParamsAttachmentToolUnion) IsPresent() bool {
1593	return !param.IsOmitted(u) && !u.IsNull()
1594}
1595func (u BetaThreadMessageNewParamsAttachmentToolUnion) MarshalJSON() ([]byte, error) {
1596	return param.MarshalUnion[BetaThreadMessageNewParamsAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
1597}
1598
1599func (u *BetaThreadMessageNewParamsAttachmentToolUnion) asAny() any {
1600	if !param.IsOmitted(u.OfCodeInterpreter) {
1601		return u.OfCodeInterpreter
1602	} else if !param.IsOmitted(u.OfFileSearch) {
1603		return u.OfFileSearch
1604	}
1605	return nil
1606}
1607
1608// Returns a pointer to the underlying variant's property, if present.
1609func (u BetaThreadMessageNewParamsAttachmentToolUnion) GetType() *string {
1610	if vt := u.OfCodeInterpreter; vt != nil {
1611		return (*string)(&vt.Type)
1612	} else if vt := u.OfFileSearch; vt != nil {
1613		return (*string)(&vt.Type)
1614	}
1615	return nil
1616}
1617
1618func init() {
1619	apijson.RegisterUnion[BetaThreadMessageNewParamsAttachmentToolUnion](
1620		"type",
1621		apijson.UnionVariant{
1622			TypeFilter:         gjson.JSON,
1623			Type:               reflect.TypeOf(CodeInterpreterToolParam{}),
1624			DiscriminatorValue: "code_interpreter",
1625		},
1626		apijson.UnionVariant{
1627			TypeFilter:         gjson.JSON,
1628			Type:               reflect.TypeOf(BetaThreadMessageNewParamsAttachmentToolFileSearch{}),
1629			DiscriminatorValue: "file_search",
1630		},
1631	)
1632}
1633
1634// The property Type is required.
1635type BetaThreadMessageNewParamsAttachmentToolFileSearch struct {
1636	// The type of tool being defined: `file_search`
1637	//
1638	// This field can be elided, and will marshal its zero value as "file_search".
1639	Type constant.FileSearch `json:"type,required"`
1640	paramObj
1641}
1642
1643// IsPresent returns true if the field's value is not omitted and not the JSON
1644// "null". To check if this field is omitted, use [param.IsOmitted].
1645func (f BetaThreadMessageNewParamsAttachmentToolFileSearch) IsPresent() bool {
1646	return !param.IsOmitted(f) && !f.IsNull()
1647}
1648func (r BetaThreadMessageNewParamsAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
1649	type shadow BetaThreadMessageNewParamsAttachmentToolFileSearch
1650	return param.MarshalObject(r, (*shadow)(&r))
1651}
1652
1653type BetaThreadMessageUpdateParams struct {
1654	// Set of 16 key-value pairs that can be attached to an object. This can be useful
1655	// for storing additional information about the object in a structured format, and
1656	// querying for objects via API or the dashboard.
1657	//
1658	// Keys are strings with a maximum length of 64 characters. Values are strings with
1659	// a maximum length of 512 characters.
1660	Metadata shared.MetadataParam `json:"metadata,omitzero"`
1661	paramObj
1662}
1663
1664// IsPresent returns true if the field's value is not omitted and not the JSON
1665// "null". To check if this field is omitted, use [param.IsOmitted].
1666func (f BetaThreadMessageUpdateParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1667
1668func (r BetaThreadMessageUpdateParams) MarshalJSON() (data []byte, err error) {
1669	type shadow BetaThreadMessageUpdateParams
1670	return param.MarshalObject(r, (*shadow)(&r))
1671}
1672
1673type BetaThreadMessageListParams struct {
1674	// A cursor for use in pagination. `after` is an object ID that defines your place
1675	// in the list. For instance, if you make a list request and receive 100 objects,
1676	// ending with obj_foo, your subsequent call can include after=obj_foo in order to
1677	// fetch the next page of the list.
1678	After param.Opt[string] `query:"after,omitzero" json:"-"`
1679	// A cursor for use in pagination. `before` is an object ID that defines your place
1680	// in the list. For instance, if you make a list request and receive 100 objects,
1681	// starting with obj_foo, your subsequent call can include before=obj_foo in order
1682	// to fetch the previous page of the list.
1683	Before param.Opt[string] `query:"before,omitzero" json:"-"`
1684	// A limit on the number of objects to be returned. Limit can range between 1 and
1685	// 100, and the default is 20.
1686	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
1687	// Filter messages by the run ID that generated them.
1688	RunID param.Opt[string] `query:"run_id,omitzero" json:"-"`
1689	// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1690	// order and `desc` for descending order.
1691	//
1692	// Any of "asc", "desc".
1693	Order BetaThreadMessageListParamsOrder `query:"order,omitzero" json:"-"`
1694	paramObj
1695}
1696
1697// IsPresent returns true if the field's value is not omitted and not the JSON
1698// "null". To check if this field is omitted, use [param.IsOmitted].
1699func (f BetaThreadMessageListParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1700
1701// URLQuery serializes [BetaThreadMessageListParams]'s query parameters as
1702// `url.Values`.
1703func (r BetaThreadMessageListParams) URLQuery() (v url.Values) {
1704	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
1705		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
1706		NestedFormat: apiquery.NestedQueryFormatBrackets,
1707	})
1708}
1709
1710// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1711// order and `desc` for descending order.
1712type BetaThreadMessageListParamsOrder string
1713
1714const (
1715	BetaThreadMessageListParamsOrderAsc  BetaThreadMessageListParamsOrder = "asc"
1716	BetaThreadMessageListParamsOrderDesc BetaThreadMessageListParamsOrder = "desc"
1717)