1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package openai
4
5import (
6 "context"
7 "errors"
8 "fmt"
9 "net/http"
10 "net/url"
11
12 "github.com/openai/openai-go/internal/apijson"
13 "github.com/openai/openai-go/internal/apiquery"
14 "github.com/openai/openai-go/internal/requestconfig"
15 "github.com/openai/openai-go/option"
16 "github.com/openai/openai-go/packages/pagination"
17 "github.com/openai/openai-go/packages/param"
18 "github.com/openai/openai-go/packages/respjson"
19)
20
21// ContainerService contains methods and other services that help with interacting
22// with the openai API.
23//
24// Note, unlike clients, this service does not read variables from the environment
25// automatically. You should not instantiate this service directly, and instead use
26// the [NewContainerService] method instead.
27type ContainerService struct {
28 Options []option.RequestOption
29 Files ContainerFileService
30}
31
32// NewContainerService generates a new service that applies the given options to
33// each request. These options are applied after the parent client's options (if
34// there is one), and before any request-specific options.
35func NewContainerService(opts ...option.RequestOption) (r ContainerService) {
36 r = ContainerService{}
37 r.Options = opts
38 r.Files = NewContainerFileService(opts...)
39 return
40}
41
42// Create Container
43func (r *ContainerService) New(ctx context.Context, body ContainerNewParams, opts ...option.RequestOption) (res *ContainerNewResponse, err error) {
44 opts = append(r.Options[:], opts...)
45 path := "containers"
46 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
47 return
48}
49
50// Retrieve Container
51func (r *ContainerService) Get(ctx context.Context, containerID string, opts ...option.RequestOption) (res *ContainerGetResponse, err error) {
52 opts = append(r.Options[:], opts...)
53 if containerID == "" {
54 err = errors.New("missing required container_id parameter")
55 return
56 }
57 path := fmt.Sprintf("containers/%s", containerID)
58 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
59 return
60}
61
62// List Containers
63func (r *ContainerService) List(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) (res *pagination.CursorPage[ContainerListResponse], err error) {
64 var raw *http.Response
65 opts = append(r.Options[:], opts...)
66 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
67 path := "containers"
68 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
69 if err != nil {
70 return nil, err
71 }
72 err = cfg.Execute()
73 if err != nil {
74 return nil, err
75 }
76 res.SetPageConfig(cfg, raw)
77 return res, nil
78}
79
80// List Containers
81func (r *ContainerService) ListAutoPaging(ctx context.Context, query ContainerListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[ContainerListResponse] {
82 return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
83}
84
85// Delete Container
86func (r *ContainerService) Delete(ctx context.Context, containerID string, opts ...option.RequestOption) (err error) {
87 opts = append(r.Options[:], opts...)
88 opts = append([]option.RequestOption{option.WithHeader("Accept", "")}, opts...)
89 if containerID == "" {
90 err = errors.New("missing required container_id parameter")
91 return
92 }
93 path := fmt.Sprintf("containers/%s", containerID)
94 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, nil, opts...)
95 return
96}
97
98type ContainerNewResponse struct {
99 // Unique identifier for the container.
100 ID string `json:"id,required"`
101 // Unix timestamp (in seconds) when the container was created.
102 CreatedAt int64 `json:"created_at,required"`
103 // Name of the container.
104 Name string `json:"name,required"`
105 // The type of this object.
106 Object string `json:"object,required"`
107 // Status of the container (e.g., active, deleted).
108 Status string `json:"status,required"`
109 // The container will expire after this time period. The anchor is the reference
110 // point for the expiration. The minutes is the number of minutes after the anchor
111 // before the container expires.
112 ExpiresAfter ContainerNewResponseExpiresAfter `json:"expires_after"`
113 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
114 JSON struct {
115 ID respjson.Field
116 CreatedAt respjson.Field
117 Name respjson.Field
118 Object respjson.Field
119 Status respjson.Field
120 ExpiresAfter respjson.Field
121 ExtraFields map[string]respjson.Field
122 raw string
123 } `json:"-"`
124}
125
126// Returns the unmodified JSON received from the API
127func (r ContainerNewResponse) RawJSON() string { return r.JSON.raw }
128func (r *ContainerNewResponse) UnmarshalJSON(data []byte) error {
129 return apijson.UnmarshalRoot(data, r)
130}
131
132// The container will expire after this time period. The anchor is the reference
133// point for the expiration. The minutes is the number of minutes after the anchor
134// before the container expires.
135type ContainerNewResponseExpiresAfter struct {
136 // The reference point for the expiration.
137 //
138 // Any of "last_active_at".
139 Anchor string `json:"anchor"`
140 // The number of minutes after the anchor before the container expires.
141 Minutes int64 `json:"minutes"`
142 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
143 JSON struct {
144 Anchor respjson.Field
145 Minutes respjson.Field
146 ExtraFields map[string]respjson.Field
147 raw string
148 } `json:"-"`
149}
150
151// Returns the unmodified JSON received from the API
152func (r ContainerNewResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
153func (r *ContainerNewResponseExpiresAfter) UnmarshalJSON(data []byte) error {
154 return apijson.UnmarshalRoot(data, r)
155}
156
157type ContainerGetResponse struct {
158 // Unique identifier for the container.
159 ID string `json:"id,required"`
160 // Unix timestamp (in seconds) when the container was created.
161 CreatedAt int64 `json:"created_at,required"`
162 // Name of the container.
163 Name string `json:"name,required"`
164 // The type of this object.
165 Object string `json:"object,required"`
166 // Status of the container (e.g., active, deleted).
167 Status string `json:"status,required"`
168 // The container will expire after this time period. The anchor is the reference
169 // point for the expiration. The minutes is the number of minutes after the anchor
170 // before the container expires.
171 ExpiresAfter ContainerGetResponseExpiresAfter `json:"expires_after"`
172 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
173 JSON struct {
174 ID respjson.Field
175 CreatedAt respjson.Field
176 Name respjson.Field
177 Object respjson.Field
178 Status respjson.Field
179 ExpiresAfter respjson.Field
180 ExtraFields map[string]respjson.Field
181 raw string
182 } `json:"-"`
183}
184
185// Returns the unmodified JSON received from the API
186func (r ContainerGetResponse) RawJSON() string { return r.JSON.raw }
187func (r *ContainerGetResponse) UnmarshalJSON(data []byte) error {
188 return apijson.UnmarshalRoot(data, r)
189}
190
191// The container will expire after this time period. The anchor is the reference
192// point for the expiration. The minutes is the number of minutes after the anchor
193// before the container expires.
194type ContainerGetResponseExpiresAfter struct {
195 // The reference point for the expiration.
196 //
197 // Any of "last_active_at".
198 Anchor string `json:"anchor"`
199 // The number of minutes after the anchor before the container expires.
200 Minutes int64 `json:"minutes"`
201 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
202 JSON struct {
203 Anchor respjson.Field
204 Minutes respjson.Field
205 ExtraFields map[string]respjson.Field
206 raw string
207 } `json:"-"`
208}
209
210// Returns the unmodified JSON received from the API
211func (r ContainerGetResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
212func (r *ContainerGetResponseExpiresAfter) UnmarshalJSON(data []byte) error {
213 return apijson.UnmarshalRoot(data, r)
214}
215
216type ContainerListResponse struct {
217 // Unique identifier for the container.
218 ID string `json:"id,required"`
219 // Unix timestamp (in seconds) when the container was created.
220 CreatedAt int64 `json:"created_at,required"`
221 // Name of the container.
222 Name string `json:"name,required"`
223 // The type of this object.
224 Object string `json:"object,required"`
225 // Status of the container (e.g., active, deleted).
226 Status string `json:"status,required"`
227 // The container will expire after this time period. The anchor is the reference
228 // point for the expiration. The minutes is the number of minutes after the anchor
229 // before the container expires.
230 ExpiresAfter ContainerListResponseExpiresAfter `json:"expires_after"`
231 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
232 JSON struct {
233 ID respjson.Field
234 CreatedAt respjson.Field
235 Name respjson.Field
236 Object respjson.Field
237 Status respjson.Field
238 ExpiresAfter respjson.Field
239 ExtraFields map[string]respjson.Field
240 raw string
241 } `json:"-"`
242}
243
244// Returns the unmodified JSON received from the API
245func (r ContainerListResponse) RawJSON() string { return r.JSON.raw }
246func (r *ContainerListResponse) UnmarshalJSON(data []byte) error {
247 return apijson.UnmarshalRoot(data, r)
248}
249
250// The container will expire after this time period. The anchor is the reference
251// point for the expiration. The minutes is the number of minutes after the anchor
252// before the container expires.
253type ContainerListResponseExpiresAfter struct {
254 // The reference point for the expiration.
255 //
256 // Any of "last_active_at".
257 Anchor string `json:"anchor"`
258 // The number of minutes after the anchor before the container expires.
259 Minutes int64 `json:"minutes"`
260 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
261 JSON struct {
262 Anchor respjson.Field
263 Minutes respjson.Field
264 ExtraFields map[string]respjson.Field
265 raw string
266 } `json:"-"`
267}
268
269// Returns the unmodified JSON received from the API
270func (r ContainerListResponseExpiresAfter) RawJSON() string { return r.JSON.raw }
271func (r *ContainerListResponseExpiresAfter) UnmarshalJSON(data []byte) error {
272 return apijson.UnmarshalRoot(data, r)
273}
274
275type ContainerNewParams struct {
276 // Name of the container to create.
277 Name string `json:"name,required"`
278 // Container expiration time in seconds relative to the 'anchor' time.
279 ExpiresAfter ContainerNewParamsExpiresAfter `json:"expires_after,omitzero"`
280 // IDs of files to copy to the container.
281 FileIDs []string `json:"file_ids,omitzero"`
282 paramObj
283}
284
285func (r ContainerNewParams) MarshalJSON() (data []byte, err error) {
286 type shadow ContainerNewParams
287 return param.MarshalObject(r, (*shadow)(&r))
288}
289func (r *ContainerNewParams) UnmarshalJSON(data []byte) error {
290 return apijson.UnmarshalRoot(data, r)
291}
292
293// Container expiration time in seconds relative to the 'anchor' time.
294//
295// The properties Anchor, Minutes are required.
296type ContainerNewParamsExpiresAfter struct {
297 // Time anchor for the expiration time. Currently only 'last_active_at' is
298 // supported.
299 //
300 // Any of "last_active_at".
301 Anchor string `json:"anchor,omitzero,required"`
302 Minutes int64 `json:"minutes,required"`
303 paramObj
304}
305
306func (r ContainerNewParamsExpiresAfter) MarshalJSON() (data []byte, err error) {
307 type shadow ContainerNewParamsExpiresAfter
308 return param.MarshalObject(r, (*shadow)(&r))
309}
310func (r *ContainerNewParamsExpiresAfter) UnmarshalJSON(data []byte) error {
311 return apijson.UnmarshalRoot(data, r)
312}
313
314func init() {
315 apijson.RegisterFieldValidator[ContainerNewParamsExpiresAfter](
316 "anchor", "last_active_at",
317 )
318}
319
320type ContainerListParams struct {
321 // A cursor for use in pagination. `after` is an object ID that defines your place
322 // in the list. For instance, if you make a list request and receive 100 objects,
323 // ending with obj_foo, your subsequent call can include after=obj_foo in order to
324 // fetch the next page of the list.
325 After param.Opt[string] `query:"after,omitzero" json:"-"`
326 // A limit on the number of objects to be returned. Limit can range between 1 and
327 // 100, and the default is 20.
328 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
329 // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
330 // order and `desc` for descending order.
331 //
332 // Any of "asc", "desc".
333 Order ContainerListParamsOrder `query:"order,omitzero" json:"-"`
334 paramObj
335}
336
337// URLQuery serializes [ContainerListParams]'s query parameters as `url.Values`.
338func (r ContainerListParams) URLQuery() (v url.Values, err error) {
339 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
340 ArrayFormat: apiquery.ArrayQueryFormatBrackets,
341 NestedFormat: apiquery.NestedQueryFormatBrackets,
342 })
343}
344
345// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
346// order and `desc` for descending order.
347type ContainerListParamsOrder string
348
349const (
350 ContainerListParamsOrderAsc ContainerListParamsOrder = "asc"
351 ContainerListParamsOrderDesc ContainerListParamsOrder = "desc"
352)