From 2bd777d6813b5dfcd3a2d339047a944c478dcd64 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 18:37:05 +0000 Subject: [PATCH] feat(api): add container endpoint --- .stats.yml | 8 +- api.md | 37 +++ client.go | 2 + container.go | 352 ++++++++++++++++++++ container_test.go | 113 +++++++ containerfile.go | 286 ++++++++++++++++ containerfile_test.go | 127 +++++++ containerfilecontent.go | 49 +++ containerfilecontent_test.go | 40 +++ responses/response.go | 627 ++++++++++++++++++++++------------- responses/response_test.go | 22 ++ shared/constant/constants.go | 3 + 12 files changed, 1428 insertions(+), 238 deletions(-) create mode 100644 container.go create mode 100644 container_test.go create mode 100644 containerfile.go create mode 100644 containerfile_test.go create mode 100644 containerfilecontent.go create mode 100644 containerfilecontent_test.go diff --git a/.stats.yml b/.stats.yml index 1f7ac8c..8eb8867 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 87 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-a5651cb97f86d1e2531af6aef8c5230f1ea350560fbae790ca2e481b30a6c217.yml -openapi_spec_hash: 66a5104fd3bb43383cf919225df7a6fd -config_hash: bb657c3fed232a56930035de3aaed936 +configured_endpoints: 97 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai%2Fopenai-6af14840a810139bf407013167ce1c8fb21b6ef8eb0cc3db58b51af7d52c4b5a.yml +openapi_spec_hash: 3241bde6b273cfec0035e522bd07985d +config_hash: 7367b68a4e7db36885c1a886f57b17f6 diff --git a/api.md b/api.md index 5815e2e..9ce4672 100644 --- a/api.md +++ b/api.md @@ -702,6 +702,7 @@ Methods: - client.Responses.New(ctx context.Context, body responses.ResponseNewParams) (responses.Response, error) - client.Responses.Get(ctx context.Context, responseID string, query responses.ResponseGetParams) (responses.Response, error) - client.Responses.Delete(ctx context.Context, responseID string) error +- client.Responses.Cancel(ctx context.Context, responseID string) error ## InputItems @@ -712,3 +713,39 @@ Response Types: Methods: - client.Responses.InputItems.List(ctx context.Context, responseID string, query responses.InputItemListParams) (pagination.CursorPage[responses.ResponseItemUnion], error) + +# Containers + +Response Types: + +- openai.ContainerNewResponse +- openai.ContainerGetResponse +- openai.ContainerListResponse + +Methods: + +- client.Containers.New(ctx context.Context, body openai.ContainerNewParams) (openai.ContainerNewResponse, error) +- client.Containers.Get(ctx context.Context, containerID string) (openai.ContainerGetResponse, error) +- client.Containers.List(ctx context.Context, query openai.ContainerListParams) (pagination.CursorPage[openai.ContainerListResponse], error) +- client.Containers.Delete(ctx context.Context, containerID string) error + +## Files + +Response Types: + +- openai.ContainerFileNewResponse +- openai.ContainerFileGetResponse +- openai.ContainerFileListResponse + +Methods: + +- client.Containers.Files.New(ctx context.Context, containerID string, body openai.ContainerFileNewParams) (openai.ContainerFileNewResponse, error) +- client.Containers.Files.Get(ctx context.Context, containerID string, fileID string) (openai.ContainerFileGetResponse, error) +- client.Containers.Files.List(ctx context.Context, containerID string, query openai.ContainerFileListParams) (pagination.CursorPage[openai.ContainerFileListResponse], error) +- client.Containers.Files.Delete(ctx context.Context, containerID string, fileID string) error + +### Content + +Methods: + +- client.Containers.Files.Content.Get(ctx context.Context, containerID string, fileID string) error diff --git a/client.go b/client.go index ce08e8e..e212fd6 100644 --- a/client.go +++ b/client.go @@ -32,6 +32,7 @@ type Client struct { Batches BatchService Uploads UploadService Responses responses.ResponseService + Containers ContainerService } // DefaultClientOptions read from the environment (OPENAI_API_KEY, OPENAI_ORG_ID, @@ -79,6 +80,7 @@ func NewClient(opts ...option.RequestOption) (r Client) { r.Batches = NewBatchService(opts...) r.Uploads = NewUploadService(opts...) r.Responses = responses.NewResponseService(opts...) + r.Containers = NewContainerService(opts...) return } diff --git a/container.go b/container.go new file mode 100644 index 0000000..357bb98 --- /dev/null +++ b/container.go @@ -0,0 +1,352 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "errors" + "fmt" + "net/http" + "net/url" + + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/respjson" +) + +// ContainerService contains methods and other services that help with interacting +// with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewContainerService] method instead. +type ContainerService struct { + Options []option.RequestOption + Files ContainerFileService +} + +// NewContainerService generates a new service that applies the given options to +// each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewContainerService(opts ...option.RequestOption) (r ContainerService) { + r = ContainerService{} + r.Options = opts + r.Files = NewContainerFileService(opts...) + return +} + +// Create Container +func (r *ContainerService) New(ctx context.Context, body ContainerNewParams, opts ...option.RequestOption) (res *ContainerNewResponse, err error) { + opts = append(r.Options[:], opts...) + path := "containers" + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Retrieve Container +func (r *ContainerService) Get(ctx context.Context, containerID string, opts ...option.RequestOption) (res *ContainerGetResponse, err error) { + opts = append(r.Options[:], opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + path := fmt.Sprintf("containers/%s", containerID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + +// List Containers +func (r *ContainerService) List(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ContainerListResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + path := "containers" + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// List Containers +func (r *ContainerService) ListAutoPaging(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ContainerListResponse] { + return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...)) +} + +// Delete Container +func (r *ContainerService) Delete(ctx context.Context, containerID string, opts ...option.RequestOption) (err error) { + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + path := fmt.Sprintf("containers/%s", containerID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...) + return +} + +type ContainerNewResponse struct { + // Unique identifier for the container. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the container was created. + CreatedAt int64 `json:"created_at,required"` + // Name of the container. + Name string `json:"name,required"` + // The type of this object. + Object string `json:"object,required"` + // Status of the container (e.g., active, deleted). + Status string `json:"status,required"` + // The container will expire after this time period. The anchor is the reference + // point for the expiration. The minutes is the number of minutes after the anchor + // before the container expires. + ExpiresAfter ContainerNewResponseExpiresAfter `json:"expires_after"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + CreatedAt respjson.Field + Name respjson.Field + Object respjson.Field + Status respjson.Field + ExpiresAfter respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerNewResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerNewResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The container will expire after this time period. The anchor is the reference +// point for the expiration. The minutes is the number of minutes after the anchor +// before the container expires. +type ContainerNewResponseExpiresAfter struct { + // The reference point for the expiration. + // + // Any of "last_active_at". + Anchor string `json:"anchor"` + // The number of minutes after the anchor before the container expires. + Minutes int64 `json:"minutes"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Anchor respjson.Field + Minutes respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerNewResponseExpiresAfter) RawJSON() string { return r.JSON.raw } +func (r *ContainerNewResponseExpiresAfter) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerGetResponse struct { + // Unique identifier for the container. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the container was created. + CreatedAt int64 `json:"created_at,required"` + // Name of the container. + Name string `json:"name,required"` + // The type of this object. + Object string `json:"object,required"` + // Status of the container (e.g., active, deleted). + Status string `json:"status,required"` + // The container will expire after this time period. The anchor is the reference + // point for the expiration. The minutes is the number of minutes after the anchor + // before the container expires. + ExpiresAfter ContainerGetResponseExpiresAfter `json:"expires_after"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + CreatedAt respjson.Field + Name respjson.Field + Object respjson.Field + Status respjson.Field + ExpiresAfter respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerGetResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The container will expire after this time period. The anchor is the reference +// point for the expiration. The minutes is the number of minutes after the anchor +// before the container expires. +type ContainerGetResponseExpiresAfter struct { + // The reference point for the expiration. + // + // Any of "last_active_at". + Anchor string `json:"anchor"` + // The number of minutes after the anchor before the container expires. + Minutes int64 `json:"minutes"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Anchor respjson.Field + Minutes respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerGetResponseExpiresAfter) RawJSON() string { return r.JSON.raw } +func (r *ContainerGetResponseExpiresAfter) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerListResponse struct { + // Unique identifier for the container. + ID string `json:"id,required"` + // Unix timestamp (in seconds) when the container was created. + CreatedAt int64 `json:"created_at,required"` + // Name of the container. + Name string `json:"name,required"` + // The type of this object. + Object string `json:"object,required"` + // Status of the container (e.g., active, deleted). + Status string `json:"status,required"` + // The container will expire after this time period. The anchor is the reference + // point for the expiration. The minutes is the number of minutes after the anchor + // before the container expires. + ExpiresAfter ContainerListResponseExpiresAfter `json:"expires_after"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + CreatedAt respjson.Field + Name respjson.Field + Object respjson.Field + Status respjson.Field + ExpiresAfter respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerListResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerListResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// The container will expire after this time period. The anchor is the reference +// point for the expiration. The minutes is the number of minutes after the anchor +// before the container expires. +type ContainerListResponseExpiresAfter struct { + // The reference point for the expiration. + // + // Any of "last_active_at". + Anchor string `json:"anchor"` + // The number of minutes after the anchor before the container expires. + Minutes int64 `json:"minutes"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + Anchor respjson.Field + Minutes respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerListResponseExpiresAfter) RawJSON() string { return r.JSON.raw } +func (r *ContainerListResponseExpiresAfter) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerNewParams struct { + // Name of the container to create. + Name string `json:"name,required"` + // Container expiration time in seconds relative to the 'anchor' time. + ExpiresAfter ContainerNewParamsExpiresAfter `json:"expires_after,omitzero"` + // IDs of files to copy to the container. + FileIDs []string `json:"file_ids,omitzero"` + paramObj +} + +func (r ContainerNewParams) MarshalJSON() (data []byte, err error) { + type shadow ContainerNewParams + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *ContainerNewParams) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +// Container expiration time in seconds relative to the 'anchor' time. +// +// The properties Anchor, Minutes are required. +type ContainerNewParamsExpiresAfter struct { + // Time anchor for the expiration time. Currently only 'last_active_at' is + // supported. + // + // Any of "last_active_at". + Anchor string `json:"anchor,omitzero,required"` + Minutes int64 `json:"minutes,required"` + paramObj +} + +func (r ContainerNewParamsExpiresAfter) MarshalJSON() (data []byte, err error) { + type shadow ContainerNewParamsExpiresAfter + return param.MarshalObject(r, (*shadow)(&r)) +} +func (r *ContainerNewParamsExpiresAfter) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +func init() { + apijson.RegisterFieldValidator[ContainerNewParamsExpiresAfter]( + "anchor", "last_active_at", + ) +} + +type ContainerListParams struct { + // A cursor for use in pagination. `after` is an object ID that defines your place + // in the list. For instance, if you make a list request and receive 100 objects, + // ending with obj_foo, your subsequent call can include after=obj_foo in order to + // fetch the next page of the list. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // A limit on the number of objects to be returned. Limit can range between 1 and + // 100, and the default is 20. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Sort order by the `created_at` timestamp of the objects. `asc` for ascending + // order and `desc` for descending order. + // + // Any of "asc", "desc". + Order ContainerListParamsOrder `query:"order,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [ContainerListParams]'s query parameters as `url.Values`. +func (r ContainerListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Sort order by the `created_at` timestamp of the objects. `asc` for ascending +// order and `desc` for descending order. +type ContainerListParamsOrder string + +const ( + ContainerListParamsOrderAsc ContainerListParamsOrder = "asc" + ContainerListParamsOrderDesc ContainerListParamsOrder = "desc" +) diff --git a/container_test.go b/container_test.go new file mode 100644 index 0000000..f5cf81f --- /dev/null +++ b/container_test.go @@ -0,0 +1,113 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" +) + +func TestContainerNewWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.New(context.TODO(), openai.ContainerNewParams{ + Name: "name", + ExpiresAfter: openai.ContainerNewParamsExpiresAfter{ + Anchor: "last_active_at", + Minutes: 0, + }, + FileIDs: []string{"string"}, + }) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.Get(context.TODO(), "container_id") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerListWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.List(context.TODO(), openai.ContainerListParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.ContainerListParamsOrderAsc, + }) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.Containers.Delete(context.TODO(), "container_id") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/containerfile.go b/containerfile.go new file mode 100644 index 0000000..bd50b52 --- /dev/null +++ b/containerfile.go @@ -0,0 +1,286 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "bytes" + "context" + "errors" + "fmt" + "io" + "mime/multipart" + "net/http" + "net/url" + + "github.com/openai/openai-go/internal/apiform" + "github.com/openai/openai-go/internal/apijson" + "github.com/openai/openai-go/internal/apiquery" + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" + "github.com/openai/openai-go/packages/pagination" + "github.com/openai/openai-go/packages/param" + "github.com/openai/openai-go/packages/respjson" + "github.com/openai/openai-go/shared/constant" +) + +// ContainerFileService contains methods and other services that help with +// interacting with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewContainerFileService] method instead. +type ContainerFileService struct { + Options []option.RequestOption + Content ContainerFileContentService +} + +// NewContainerFileService generates a new service that applies the given options +// to each request. These options are applied after the parent client's options (if +// there is one), and before any request-specific options. +func NewContainerFileService(opts ...option.RequestOption) (r ContainerFileService) { + r = ContainerFileService{} + r.Options = opts + r.Content = NewContainerFileContentService(opts...) + return +} + +// Create a Container File +// +// You can send either a multipart/form-data request with the raw file content, or +// a JSON request with a file ID. +func (r *ContainerFileService) New(ctx context.Context, containerID string, body ContainerFileNewParams, opts ...option.RequestOption) (res *ContainerFileNewResponse, err error) { + opts = append(r.Options[:], opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + path := fmt.Sprintf("containers/%s/files", containerID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...) + return +} + +// Retrieve Container File +func (r *ContainerFileService) Get(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (res *ContainerFileGetResponse, err error) { + opts = append(r.Options[:], opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + if fileID == "" { + err = errors.New("missing required file_id parameter") + return + } + path := fmt.Sprintf("containers/%s/files/%s", containerID, fileID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) + return +} + +// List Container files +func (r *ContainerFileService) List(ctx context.Context, containerID string, query ContainerFileListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ContainerFileListResponse], err error) { + var raw *http.Response + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + path := fmt.Sprintf("containers/%s/files", containerID) + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + if err != nil { + return nil, err + } + err = cfg.Execute() + if err != nil { + return nil, err + } + res.SetPageConfig(cfg, raw) + return res, nil +} + +// List Container files +func (r *ContainerFileService) ListAutoPaging(ctx context.Context, containerID string, query ContainerFileListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ContainerFileListResponse] { + return pagination.NewCursorPageAutoPager(r.List(ctx, containerID, query, opts...)) +} + +// Delete Container File +func (r *ContainerFileService) Delete(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (err error) { + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + if fileID == "" { + err = errors.New("missing required file_id parameter") + return + } + path := fmt.Sprintf("containers/%s/files/%s", containerID, fileID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...) + return +} + +type ContainerFileNewResponse struct { + // Unique identifier for the file. + ID string `json:"id,required"` + // Size of the file in bytes. + Bytes int64 `json:"bytes,required"` + // The container this file belongs to. + ContainerID string `json:"container_id,required"` + // Unix timestamp (in seconds) when the file was created. + CreatedAt int64 `json:"created_at,required"` + // The type of this object (`container.file`). + Object constant.ContainerFile `json:"object,required"` + // Path of the file in the container. + Path string `json:"path,required"` + // Source of the file (e.g., `user`, `assistant`). + Source string `json:"source,required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + Bytes respjson.Field + ContainerID respjson.Field + CreatedAt respjson.Field + Object respjson.Field + Path respjson.Field + Source respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerFileNewResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerFileNewResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerFileGetResponse struct { + // Unique identifier for the file. + ID string `json:"id,required"` + // Size of the file in bytes. + Bytes int64 `json:"bytes,required"` + // The container this file belongs to. + ContainerID string `json:"container_id,required"` + // Unix timestamp (in seconds) when the file was created. + CreatedAt int64 `json:"created_at,required"` + // The type of this object (`container.file`). + Object constant.ContainerFile `json:"object,required"` + // Path of the file in the container. + Path string `json:"path,required"` + // Source of the file (e.g., `user`, `assistant`). + Source string `json:"source,required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + Bytes respjson.Field + ContainerID respjson.Field + CreatedAt respjson.Field + Object respjson.Field + Path respjson.Field + Source respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerFileGetResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerFileGetResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerFileListResponse struct { + // Unique identifier for the file. + ID string `json:"id,required"` + // Size of the file in bytes. + Bytes int64 `json:"bytes,required"` + // The container this file belongs to. + ContainerID string `json:"container_id,required"` + // Unix timestamp (in seconds) when the file was created. + CreatedAt int64 `json:"created_at,required"` + // The type of this object (`container.file`). + Object constant.ContainerFile `json:"object,required"` + // Path of the file in the container. + Path string `json:"path,required"` + // Source of the file (e.g., `user`, `assistant`). + Source string `json:"source,required"` + // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. + JSON struct { + ID respjson.Field + Bytes respjson.Field + ContainerID respjson.Field + CreatedAt respjson.Field + Object respjson.Field + Path respjson.Field + Source respjson.Field + ExtraFields map[string]respjson.Field + raw string + } `json:"-"` +} + +// Returns the unmodified JSON received from the API +func (r ContainerFileListResponse) RawJSON() string { return r.JSON.raw } +func (r *ContainerFileListResponse) UnmarshalJSON(data []byte) error { + return apijson.UnmarshalRoot(data, r) +} + +type ContainerFileNewParams struct { + // Name of the file to create. + FileID param.Opt[string] `json:"file_id,omitzero"` + // The File object (not file name) to be uploaded. + File io.Reader `json:"file,omitzero" format:"binary"` + paramObj +} + +func (r ContainerFileNewParams) MarshalMultipart() (data []byte, contentType string, err error) { + buf := bytes.NewBuffer(nil) + writer := multipart.NewWriter(buf) + err = apiform.MarshalRoot(r, writer) + if err == nil { + err = apiform.WriteExtras(writer, r.ExtraFields()) + } + if err != nil { + writer.Close() + return nil, "", err + } + err = writer.Close() + if err != nil { + return nil, "", err + } + return buf.Bytes(), writer.FormDataContentType(), nil +} + +type ContainerFileListParams struct { + // A cursor for use in pagination. `after` is an object ID that defines your place + // in the list. For instance, if you make a list request and receive 100 objects, + // ending with obj_foo, your subsequent call can include after=obj_foo in order to + // fetch the next page of the list. + After param.Opt[string] `query:"after,omitzero" json:"-"` + // A limit on the number of objects to be returned. Limit can range between 1 and + // 100, and the default is 20. + Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` + // Sort order by the `created_at` timestamp of the objects. `asc` for ascending + // order and `desc` for descending order. + // + // Any of "asc", "desc". + Order ContainerFileListParamsOrder `query:"order,omitzero" json:"-"` + paramObj +} + +// URLQuery serializes [ContainerFileListParams]'s query parameters as +// `url.Values`. +func (r ContainerFileListParams) URLQuery() (v url.Values, err error) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatBrackets, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) +} + +// Sort order by the `created_at` timestamp of the objects. `asc` for ascending +// order and `desc` for descending order. +type ContainerFileListParamsOrder string + +const ( + ContainerFileListParamsOrderAsc ContainerFileListParamsOrder = "asc" + ContainerFileListParamsOrderDesc ContainerFileListParamsOrder = "desc" +) diff --git a/containerfile_test.go b/containerfile_test.go new file mode 100644 index 0000000..d9480d2 --- /dev/null +++ b/containerfile_test.go @@ -0,0 +1,127 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "bytes" + "context" + "errors" + "io" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" +) + +func TestContainerFileNewWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.Files.New( + context.TODO(), + "container_id", + openai.ContainerFileNewParams{ + File: io.Reader(bytes.NewBuffer([]byte("some file contents"))), + FileID: openai.String("file_id"), + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerFileGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.Files.Get( + context.TODO(), + "container_id", + "file_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerFileListWithOptionalParams(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + _, err := client.Containers.Files.List( + context.TODO(), + "container_id", + openai.ContainerFileListParams{ + After: openai.String("after"), + Limit: openai.Int(0), + Order: openai.ContainerFileListParamsOrderAsc, + }, + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} + +func TestContainerFileDelete(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.Containers.Files.Delete( + context.TODO(), + "container_id", + "file_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/containerfilecontent.go b/containerfilecontent.go new file mode 100644 index 0000000..1580538 --- /dev/null +++ b/containerfilecontent.go @@ -0,0 +1,49 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai + +import ( + "context" + "errors" + "fmt" + "net/http" + + "github.com/openai/openai-go/internal/requestconfig" + "github.com/openai/openai-go/option" +) + +// ContainerFileContentService contains methods and other services that help with +// interacting with the openai API. +// +// Note, unlike clients, this service does not read variables from the environment +// automatically. You should not instantiate this service directly, and instead use +// the [NewContainerFileContentService] method instead. +type ContainerFileContentService struct { + Options []option.RequestOption +} + +// NewContainerFileContentService generates a new service that applies the given +// options to each request. These options are applied after the parent client's +// options (if there is one), and before any request-specific options. +func NewContainerFileContentService(opts ...option.RequestOption) (r ContainerFileContentService) { + r = ContainerFileContentService{} + r.Options = opts + return +} + +// Retrieve Container File Content +func (r *ContainerFileContentService) Get(ctx context.Context, containerID string, fileID string, opts ...option.RequestOption) (err error) { + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...) + if containerID == "" { + err = errors.New("missing required container_id parameter") + return + } + if fileID == "" { + err = errors.New("missing required file_id parameter") + return + } + path := fmt.Sprintf("containers/%s/files/%s/content", containerID, fileID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, nil, opts...) + return +} diff --git a/containerfilecontent_test.go b/containerfilecontent_test.go new file mode 100644 index 0000000..3f43bce --- /dev/null +++ b/containerfilecontent_test.go @@ -0,0 +1,40 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package openai_test + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/openai/openai-go" + "github.com/openai/openai-go/internal/testutil" + "github.com/openai/openai-go/option" +) + +func TestContainerFileContentGet(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.Containers.Files.Content.Get( + context.TODO(), + "container_id", + "file_id", + ) + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/responses/response.go b/responses/response.go index 81b5992..9c71fce 100644 --- a/responses/response.go +++ b/responses/response.go @@ -110,6 +110,21 @@ func (r *ResponseService) Delete(ctx context.Context, responseID string, opts .. return } +// Cancels a model response with the given ID. Only responses created with the +// `background` parameter set to `true` can be cancelled. +// [Learn more](https://platform.openai.com/docs/guides/background). +func (r *ResponseService) Cancel(ctx context.Context, responseID string, opts ...option.RequestOption) (err error) { + opts = append(r.Options[:], opts...) + opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...) + if responseID == "" { + err = errors.New("missing required response_id parameter") + return + } + path := fmt.Sprintf("responses/%s/cancel", responseID) + err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, nil, opts...) + return +} + // A tool that controls a virtual computer. Learn more about the // [computer tool](https://platform.openai.com/docs/guides/tools-computer-use). type ComputerTool struct { @@ -848,14 +863,17 @@ const ( type ResponseAudioDeltaEvent struct { // A chunk of Base64 encoded response audio bytes. Delta string `json:"delta,required"` + // A sequence number for this chunk of the stream response. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.audio.delta`. Type constant.ResponseAudioDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -867,13 +885,16 @@ func (r *ResponseAudioDeltaEvent) UnmarshalJSON(data []byte) error { // Emitted when the audio response is complete. type ResponseAudioDoneEvent struct { + // The sequence number of the delta. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.audio.done`. Type constant.ResponseAudioDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -887,14 +908,17 @@ func (r *ResponseAudioDoneEvent) UnmarshalJSON(data []byte) error { type ResponseAudioTranscriptDeltaEvent struct { // The partial transcript of the audio response. Delta string `json:"delta,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.audio.transcript.delta`. Type constant.ResponseAudioTranscriptDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -906,13 +930,16 @@ func (r *ResponseAudioTranscriptDeltaEvent) UnmarshalJSON(data []byte) error { // Emitted when the full audio transcript is completed. type ResponseAudioTranscriptDoneEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.audio.transcript.done`. Type constant.ResponseAudioTranscriptDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -928,15 +955,18 @@ type ResponseCodeInterpreterCallCodeDeltaEvent struct { Delta string `json:"delta,required"` // The index of the output item that the code interpreter call is in progress. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.code_interpreter_call.code.delta`. Type constant.ResponseCodeInterpreterCallCodeDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -952,15 +982,18 @@ type ResponseCodeInterpreterCallCodeDoneEvent struct { Code string `json:"code,required"` // The index of the output item that the code interpreter call is in progress. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.code_interpreter_call.code.done`. Type constant.ResponseCodeInterpreterCallCodeDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Code respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Code respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -976,12 +1009,15 @@ type ResponseCodeInterpreterCallCompletedEvent struct { CodeInterpreterCall ResponseCodeInterpreterToolCall `json:"code_interpreter_call,required"` // The index of the output item that the code interpreter call is in progress. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.code_interpreter_call.completed`. Type constant.ResponseCodeInterpreterCallCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { CodeInterpreterCall respjson.Field OutputIndex respjson.Field + SequenceNumber respjson.Field Type respjson.Field ExtraFields map[string]respjson.Field raw string @@ -1000,12 +1036,15 @@ type ResponseCodeInterpreterCallInProgressEvent struct { CodeInterpreterCall ResponseCodeInterpreterToolCall `json:"code_interpreter_call,required"` // The index of the output item that the code interpreter call is in progress. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.code_interpreter_call.in_progress`. Type constant.ResponseCodeInterpreterCallInProgress `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { CodeInterpreterCall respjson.Field OutputIndex respjson.Field + SequenceNumber respjson.Field Type respjson.Field ExtraFields map[string]respjson.Field raw string @@ -1024,12 +1063,15 @@ type ResponseCodeInterpreterCallInterpretingEvent struct { CodeInterpreterCall ResponseCodeInterpreterToolCall `json:"code_interpreter_call,required"` // The index of the output item that the code interpreter call is in progress. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.code_interpreter_call.interpreting`. Type constant.ResponseCodeInterpreterCallInterpreting `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { CodeInterpreterCall respjson.Field OutputIndex respjson.Field + SequenceNumber respjson.Field Type respjson.Field ExtraFields map[string]respjson.Field raw string @@ -1378,14 +1420,17 @@ func (r *ResponseCodeInterpreterToolCallResultFilesFileParam) UnmarshalJSON(data type ResponseCompletedEvent struct { // Properties of the completed response. Response Response `json:"response,required"` + // The sequence number for this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.completed`. Type constant.ResponseCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2511,17 +2556,20 @@ type ResponseContentPartAddedEvent struct { OutputIndex int64 `json:"output_index,required"` // The content part that was added. Part ResponseContentPartAddedEventPartUnion `json:"part,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.content_part.added`. Type constant.ResponseContentPartAdded `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Part respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + Part respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2611,17 +2659,20 @@ type ResponseContentPartDoneEvent struct { OutputIndex int64 `json:"output_index,required"` // The content part that is done. Part ResponseContentPartDoneEventPartUnion `json:"part,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.content_part.done`. Type constant.ResponseContentPartDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Part respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + Part respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2705,14 +2756,17 @@ func (r *ResponseContentPartDoneEventPartUnion) UnmarshalJSON(data []byte) error type ResponseCreatedEvent struct { // The response that was created. Response Response `json:"response,required"` + // The sequence number for this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.created`. Type constant.ResponseCreated `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2782,16 +2836,19 @@ type ResponseErrorEvent struct { Message string `json:"message,required"` // The error parameter. Param string `json:"param,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `error`. Type constant.Error `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Code respjson.Field - Message respjson.Field - Param respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Code respjson.Field + Message respjson.Field + Param respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2805,14 +2862,17 @@ func (r *ResponseErrorEvent) UnmarshalJSON(data []byte) error { type ResponseFailedEvent struct { // The response that failed. Response Response `json:"response,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.failed`. Type constant.ResponseFailed `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2828,15 +2888,18 @@ type ResponseFileSearchCallCompletedEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the file search call is initiated. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.file_search_call.completed`. Type constant.ResponseFileSearchCallCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2852,15 +2915,18 @@ type ResponseFileSearchCallInProgressEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the file search call is initiated. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.file_search_call.in_progress`. Type constant.ResponseFileSearchCallInProgress `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -2876,15 +2942,18 @@ type ResponseFileSearchCallSearchingEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the file search call is searching. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.file_search_call.searching`. Type constant.ResponseFileSearchCallSearching `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -3385,16 +3454,19 @@ type ResponseFunctionCallArgumentsDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the function-call arguments delta is added to. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.function_call_arguments.delta`. Type constant.ResponseFunctionCallArgumentsDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -3411,16 +3483,19 @@ type ResponseFunctionCallArgumentsDoneEvent struct { // The ID of the item. ItemID string `json:"item_id,required"` // The index of the output item. - OutputIndex int64 `json:"output_index,required"` - Type constant.ResponseFunctionCallArgumentsDone `json:"type,required"` + OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` + Type constant.ResponseFunctionCallArgumentsDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Arguments respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Arguments respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -3667,15 +3742,18 @@ type ResponseImageGenCallCompletedEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.image_generation_call.completed'. Type constant.ResponseImageGenerationCallCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -3692,16 +3770,16 @@ type ResponseImageGenCallGeneratingEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of the image generation item being processed. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.image_generation_call.generating'. Type constant.ResponseImageGenerationCallGenerating `json:"type,required"` - // The sequence number of the image generation item being processed. - SequenceNumber int64 `json:"sequence_number"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { ItemID respjson.Field OutputIndex respjson.Field - Type respjson.Field SequenceNumber respjson.Field + Type respjson.Field ExtraFields map[string]respjson.Field raw string } `json:"-"` @@ -3778,14 +3856,17 @@ func (r *ResponseImageGenCallPartialImageEvent) UnmarshalJSON(data []byte) error type ResponseInProgressEvent struct { // The response that is in progress. Response Response `json:"response,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.in_progress`. Type constant.ResponseInProgress `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -3821,14 +3902,17 @@ const ( type ResponseIncompleteEvent struct { // The response that was incomplete. Response Response `json:"response,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.incomplete`. Type constant.ResponseIncomplete `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6196,16 +6280,19 @@ type ResponseMcpCallArgumentsDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_call.arguments_delta'. Type constant.ResponseMcpCallArgumentsDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6223,16 +6310,19 @@ type ResponseMcpCallArgumentsDoneEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_call.arguments_done'. Type constant.ResponseMcpCallArgumentsDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Arguments respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Arguments respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6244,13 +6334,16 @@ func (r *ResponseMcpCallArgumentsDoneEvent) UnmarshalJSON(data []byte) error { // Emitted when an MCP tool call has completed successfully. type ResponseMcpCallCompletedEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_call.completed'. Type constant.ResponseMcpCallCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6262,13 +6355,16 @@ func (r *ResponseMcpCallCompletedEvent) UnmarshalJSON(data []byte) error { // Emitted when an MCP tool call has failed. type ResponseMcpCallFailedEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_call.failed'. Type constant.ResponseMcpCallFailed `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6284,15 +6380,18 @@ type ResponseMcpCallInProgressEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_call.in_progress'. Type constant.ResponseMcpCallInProgress `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6304,13 +6403,16 @@ func (r *ResponseMcpCallInProgressEvent) UnmarshalJSON(data []byte) error { // Emitted when the list of available MCP tools has been successfully retrieved. type ResponseMcpListToolsCompletedEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_list_tools.completed'. Type constant.ResponseMcpListToolsCompleted `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6322,13 +6424,16 @@ func (r *ResponseMcpListToolsCompletedEvent) UnmarshalJSON(data []byte) error { // Emitted when the attempt to list available MCP tools has failed. type ResponseMcpListToolsFailedEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_list_tools.failed'. Type constant.ResponseMcpListToolsFailed `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6341,13 +6446,16 @@ func (r *ResponseMcpListToolsFailedEvent) UnmarshalJSON(data []byte) error { // Emitted when the system is in the process of retrieving the list of available // MCP tools. type ResponseMcpListToolsInProgressEvent struct { + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.mcp_list_tools.in_progress'. Type constant.ResponseMcpListToolsInProgress `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6875,15 +6983,18 @@ type ResponseOutputItemAddedEvent struct { Item ResponseOutputItemUnion `json:"item,required"` // The index of the output item that was added. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.output_item.added`. Type constant.ResponseOutputItemAdded `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Item respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Item respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -6899,15 +7010,18 @@ type ResponseOutputItemDoneEvent struct { Item ResponseOutputItemUnion `json:"item,required"` // The index of the output item that was marked done. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.output_item.done`. Type constant.ResponseOutputItemDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Item respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Item respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7597,6 +7711,8 @@ type ResponseOutputTextAnnotationAddedEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.output_text_annotation.added'. Type constant.ResponseOutputTextAnnotationAdded `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. @@ -7606,6 +7722,7 @@ type ResponseOutputTextAnnotationAddedEvent struct { ContentIndex respjson.Field ItemID respjson.Field OutputIndex respjson.Field + SequenceNumber respjson.Field Type respjson.Field ExtraFields map[string]respjson.Field raw string @@ -7622,14 +7739,17 @@ func (r *ResponseOutputTextAnnotationAddedEvent) UnmarshalJSON(data []byte) erro type ResponseQueuedEvent struct { // The full response object that is queued. Response Response `json:"response,required"` + // The sequence number for this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.queued'. Type constant.ResponseQueued `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Response respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Response respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7649,17 +7769,20 @@ type ResponseReasoningDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always 'response.reasoning.delta'. Type constant.ResponseReasoningDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7677,19 +7800,22 @@ type ResponseReasoningDoneEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The finalized reasoning text. Text string `json:"text,required"` // The type of the event. Always 'response.reasoning.done'. Type constant.ResponseReasoningDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Text respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Text respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7837,19 +7963,22 @@ type ResponseReasoningSummaryDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the output item. SummaryIndex int64 `json:"summary_index,required"` // The type of the event. Always 'response.reasoning_summary.delta'. Type constant.ResponseReasoningSummaryDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - SummaryIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7865,6 +7994,8 @@ type ResponseReasoningSummaryDoneEvent struct { ItemID string `json:"item_id,required"` // The index of the output item in the response's output array. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the output item. SummaryIndex int64 `json:"summary_index,required"` // The finalized reasoning summary text. @@ -7873,13 +8004,14 @@ type ResponseReasoningSummaryDoneEvent struct { Type constant.ResponseReasoningSummaryDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - SummaryIndex respjson.Field - Text respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Text respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7897,19 +8029,22 @@ type ResponseReasoningSummaryPartAddedEvent struct { OutputIndex int64 `json:"output_index,required"` // The summary part that was added. Part ResponseReasoningSummaryPartAddedEventPart `json:"part,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the reasoning summary. SummaryIndex int64 `json:"summary_index,required"` // The type of the event. Always `response.reasoning_summary_part.added`. Type constant.ResponseReasoningSummaryPartAdded `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Part respjson.Field - SummaryIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + Part respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7948,19 +8083,22 @@ type ResponseReasoningSummaryPartDoneEvent struct { OutputIndex int64 `json:"output_index,required"` // The completed summary part. Part ResponseReasoningSummaryPartDoneEventPart `json:"part,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the reasoning summary. SummaryIndex int64 `json:"summary_index,required"` // The type of the event. Always `response.reasoning_summary_part.done`. Type constant.ResponseReasoningSummaryPartDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - Part respjson.Field - SummaryIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + Part respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -7999,19 +8137,22 @@ type ResponseReasoningSummaryTextDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item this summary text delta is associated with. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the reasoning summary. SummaryIndex int64 `json:"summary_index,required"` // The type of the event. Always `response.reasoning_summary_text.delta`. Type constant.ResponseReasoningSummaryTextDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - SummaryIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -8027,6 +8168,8 @@ type ResponseReasoningSummaryTextDoneEvent struct { ItemID string `json:"item_id,required"` // The index of the output item this summary text is associated with. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The index of the summary part within the reasoning summary. SummaryIndex int64 `json:"summary_index,required"` // The full text of the completed reasoning summary. @@ -8035,13 +8178,14 @@ type ResponseReasoningSummaryTextDoneEvent struct { Type constant.ResponseReasoningSummaryTextDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ItemID respjson.Field - OutputIndex respjson.Field - SummaryIndex respjson.Field - Text respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + SummaryIndex respjson.Field + Text respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -8061,17 +8205,20 @@ type ResponseRefusalDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the refusal text is added to. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.refusal.delta`. Type constant.ResponseRefusalDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -8091,17 +8238,20 @@ type ResponseRefusalDoneEvent struct { OutputIndex int64 `json:"output_index,required"` // The refusal text that is finalized. Refusal string `json:"refusal,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.refusal.done`. Type constant.ResponseRefusalDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Refusal respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + Refusal respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -8164,7 +8314,8 @@ const ( type ResponseStreamEventUnion struct { // This field is a union of [string], [string], [string], [string], [string], // [string], [string], [any], [any], [any] - Delta ResponseStreamEventUnionDelta `json:"delta"` + Delta ResponseStreamEventUnionDelta `json:"delta"` + SequenceNumber int64 `json:"sequence_number"` // Any of "response.audio.delta", "response.audio.done", // "response.audio.transcript.delta", "response.audio.transcript.done", // "response.code_interpreter_call.code.delta", @@ -8226,13 +8377,13 @@ type ResponseStreamEventUnion struct { // [any] Annotation ResponseStreamEventUnionAnnotation `json:"annotation"` AnnotationIndex int64 `json:"annotation_index"` - SequenceNumber int64 `json:"sequence_number"` // This field is from variant [ResponseImageGenCallPartialImageEvent]. PartialImageB64 string `json:"partial_image_b64"` // This field is from variant [ResponseImageGenCallPartialImageEvent]. PartialImageIndex int64 `json:"partial_image_index"` JSON struct { Delta respjson.Field + SequenceNumber respjson.Field Type respjson.Field OutputIndex respjson.Field Code respjson.Field @@ -8250,7 +8401,6 @@ type ResponseStreamEventUnion struct { Refusal respjson.Field Annotation respjson.Field AnnotationIndex respjson.Field - SequenceNumber respjson.Field PartialImageB64 respjson.Field PartialImageIndex respjson.Field raw string @@ -8900,6 +9050,8 @@ type ResponseTextAnnotationDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the text annotation was added to. OutputIndex int64 `json:"output_index,required"` + // The sequence number of this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.output_text.annotation.added`. Type constant.ResponseOutputTextAnnotationAdded `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. @@ -8909,6 +9061,7 @@ type ResponseTextAnnotationDeltaEvent struct { ContentIndex respjson.Field ItemID respjson.Field OutputIndex respjson.Field + SequenceNumber respjson.Field Type respjson.Field ExtraFields map[string]respjson.Field raw string @@ -9178,17 +9331,20 @@ type ResponseTextDeltaEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the text delta was added to. OutputIndex int64 `json:"output_index,required"` + // The sequence number for this event. + SequenceNumber int64 `json:"sequence_number,required"` // The type of the event. Always `response.output_text.delta`. Type constant.ResponseOutputTextDelta `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - Delta respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + Delta respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } @@ -9206,19 +9362,22 @@ type ResponseTextDoneEvent struct { ItemID string `json:"item_id,required"` // The index of the output item that the text content is finalized. OutputIndex int64 `json:"output_index,required"` + // The sequence number for this event. + SequenceNumber int64 `json:"sequence_number,required"` // The text content that is finalized. Text string `json:"text,required"` // The type of the event. Always `response.output_text.done`. Type constant.ResponseOutputTextDone `json:"type,required"` // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. JSON struct { - ContentIndex respjson.Field - ItemID respjson.Field - OutputIndex respjson.Field - Text respjson.Field - Type respjson.Field - ExtraFields map[string]respjson.Field - raw string + ContentIndex respjson.Field + ItemID respjson.Field + OutputIndex respjson.Field + SequenceNumber respjson.Field + Text respjson.Field + Type respjson.Field + ExtraFields map[string]respjson.Field + raw string } `json:"-"` } diff --git a/responses/response_test.go b/responses/response_test.go index e94a9a7..311dc74 100644 --- a/responses/response_test.go +++ b/responses/response_test.go @@ -129,3 +129,25 @@ func TestResponseDelete(t *testing.T) { t.Fatalf("err should be nil: %s", err.Error()) } } + +func TestResponseCancel(t *testing.T) { + baseURL := "http://localhost:4010" + if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { + baseURL = envURL + } + if !testutil.CheckTestServer(t, baseURL) { + return + } + client := openai.NewClient( + option.WithBaseURL(baseURL), + option.WithAPIKey("My API Key"), + ) + err := client.Responses.Cancel(context.TODO(), "resp_677efb5139a88190b512bc3fef8e535d") + if err != nil { + var apierr *openai.Error + if errors.As(err, &apierr) { + t.Log(string(apierr.DumpRequest(true))) + } + t.Fatalf("err should be nil: %s", err.Error()) + } +} diff --git a/shared/constant/constants.go b/shared/constant/constants.go index 7395fb9..47d22fc 100644 --- a/shared/constant/constants.go +++ b/shared/constant/constants.go @@ -33,6 +33,7 @@ type CodeInterpreterCall string // Always "code_interpreter_ type ComputerCallOutput string // Always "computer_call_output" type ComputerScreenshot string // Always "computer_screenshot" type ComputerUsePreview string // Always "computer_use_preview" +type ContainerFile string // Always "container.file" type Content string // Always "content" type Developer string // Always "developer" type DoubleClick string // Always "double_click" @@ -216,6 +217,7 @@ func (c CodeInterpreterCall) Default() CodeInterpreterCall { return "code_in func (c ComputerCallOutput) Default() ComputerCallOutput { return "computer_call_output" } func (c ComputerScreenshot) Default() ComputerScreenshot { return "computer_screenshot" } func (c ComputerUsePreview) Default() ComputerUsePreview { return "computer_use_preview" } +func (c ContainerFile) Default() ContainerFile { return "container.file" } func (c Content) Default() Content { return "content" } func (c Developer) Default() Developer { return "developer" } func (c DoubleClick) Default() DoubleClick { return "double_click" } @@ -489,6 +491,7 @@ func (c CodeInterpreterCall) MarshalJSON() ([]byte, error) { r func (c ComputerCallOutput) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ComputerScreenshot) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c ComputerUsePreview) MarshalJSON() ([]byte, error) { return marshalString(c) } +func (c ContainerFile) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Content) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c Developer) MarshalJSON() ([]byte, error) { return marshalString(c) } func (c DoubleClick) MarshalJSON() ([]byte, error) { return marshalString(c) }