-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathadminorganizationprojectspendalert.go
More file actions
386 lines (345 loc) · 15.9 KB
/
Copy pathadminorganizationprojectspendalert.go
File metadata and controls
386 lines (345 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"net/http"
"net/url"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/apiquery"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/pagination"
"github.com/openai/openai-go/v3/packages/param"
"github.com/openai/openai-go/v3/packages/respjson"
"github.com/openai/openai-go/v3/shared/constant"
)
// AdminOrganizationProjectSpendAlertService 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 [NewAdminOrganizationProjectSpendAlertService] method instead.
type AdminOrganizationProjectSpendAlertService struct {
Options []option.RequestOption
}
// NewAdminOrganizationProjectSpendAlertService 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 NewAdminOrganizationProjectSpendAlertService(opts ...option.RequestOption) (r AdminOrganizationProjectSpendAlertService) {
r = AdminOrganizationProjectSpendAlertService{}
r.Options = opts
return
}
// Creates a project spend alert.
func (r *AdminOrganizationProjectSpendAlertService) New(ctx context.Context, projectID string, body AdminOrganizationProjectSpendAlertNewParams, opts ...option.RequestOption) (res *ProjectSpendAlert, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/spend_alerts", projectID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Retrieves a project spend alert.
func (r *AdminOrganizationProjectSpendAlertService) Get(ctx context.Context, projectID string, alertID string, opts ...option.RequestOption) (res *ProjectSpendAlert, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
if alertID == "" {
err = errors.New("missing required alert_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/spend_alerts/%s", projectID, alertID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Updates a project spend alert.
func (r *AdminOrganizationProjectSpendAlertService) Update(ctx context.Context, projectID string, alertID string, body AdminOrganizationProjectSpendAlertUpdateParams, opts ...option.RequestOption) (res *ProjectSpendAlert, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
if alertID == "" {
err = errors.New("missing required alert_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/spend_alerts/%s", projectID, alertID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Lists project spend alerts.
func (r *AdminOrganizationProjectSpendAlertService) List(ctx context.Context, projectID string, query AdminOrganizationProjectSpendAlertListParams, opts ...option.RequestOption) (res *pagination.ConversationCursorPage[ProjectSpendAlert], err error) {
var raw *http.Response
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/spend_alerts", projectID)
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
}
// Lists project spend alerts.
func (r *AdminOrganizationProjectSpendAlertService) ListAutoPaging(ctx context.Context, projectID string, query AdminOrganizationProjectSpendAlertListParams, opts ...option.RequestOption) *pagination.ConversationCursorPageAutoPager[ProjectSpendAlert] {
return pagination.NewConversationCursorPageAutoPager(r.List(ctx, projectID, query, opts...))
}
// Deletes a project spend alert.
func (r *AdminOrganizationProjectSpendAlertService) Delete(ctx context.Context, projectID string, alertID string, opts ...option.RequestOption) (res *ProjectSpendAlertDeleted, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if projectID == "" {
err = errors.New("missing required project_id parameter")
return nil, err
}
if alertID == "" {
err = errors.New("missing required alert_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/projects/%s/spend_alerts/%s", projectID, alertID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Represents a spend alert configured at the project level.
type ProjectSpendAlert struct {
// The identifier, which can be referenced in API endpoints.
ID string `json:"id" api:"required"`
// The currency for the threshold amount.
//
// Any of "USD".
Currency ProjectSpendAlertCurrency `json:"currency" api:"required"`
// The time interval for evaluating spend against the threshold.
//
// Any of "month".
Interval ProjectSpendAlertInterval `json:"interval" api:"required"`
// Email notification settings for a spend alert.
NotificationChannel ProjectSpendAlertNotificationChannel `json:"notification_channel" api:"required"`
// The object type, which is always `project.spend_alert`.
Object constant.ProjectSpendAlert `json:"object" default:"project.spend_alert"`
// The alert threshold amount, in cents.
ThresholdAmount int64 `json:"threshold_amount" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Currency respjson.Field
Interval respjson.Field
NotificationChannel respjson.Field
Object respjson.Field
ThresholdAmount respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ProjectSpendAlert) RawJSON() string { return r.JSON.raw }
func (r *ProjectSpendAlert) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The currency for the threshold amount.
type ProjectSpendAlertCurrency string
const (
ProjectSpendAlertCurrencyUsd ProjectSpendAlertCurrency = "USD"
)
// The time interval for evaluating spend against the threshold.
type ProjectSpendAlertInterval string
const (
ProjectSpendAlertIntervalMonth ProjectSpendAlertInterval = "month"
)
// Email notification settings for a spend alert.
type ProjectSpendAlertNotificationChannel struct {
// Email addresses that receive the spend alert notification.
Recipients []string `json:"recipients" api:"required"`
// The notification channel type. Currently only `email` is supported.
Type constant.Email `json:"type" default:"email"`
// Optional subject prefix for alert emails.
SubjectPrefix string `json:"subject_prefix" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Recipients respjson.Field
Type respjson.Field
SubjectPrefix respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ProjectSpendAlertNotificationChannel) RawJSON() string { return r.JSON.raw }
func (r *ProjectSpendAlertNotificationChannel) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Confirmation payload returned after deleting a project spend alert.
type ProjectSpendAlertDeleted struct {
// The deleted spend alert ID.
ID string `json:"id" api:"required"`
// Whether the spend alert was deleted.
Deleted bool `json:"deleted" api:"required"`
// Always `project.spend_alert.deleted`.
Object constant.ProjectSpendAlertDeleted `json:"object" default:"project.spend_alert.deleted"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Deleted respjson.Field
Object respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ProjectSpendAlertDeleted) RawJSON() string { return r.JSON.raw }
func (r *ProjectSpendAlertDeleted) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationProjectSpendAlertNewParams struct {
// The currency for the threshold amount.
//
// Any of "USD".
Currency AdminOrganizationProjectSpendAlertNewParamsCurrency `json:"currency,omitzero" api:"required"`
// The time interval for evaluating spend against the threshold.
//
// Any of "month".
Interval AdminOrganizationProjectSpendAlertNewParamsInterval `json:"interval,omitzero" api:"required"`
// Email notification settings for a spend alert.
NotificationChannel AdminOrganizationProjectSpendAlertNewParamsNotificationChannel `json:"notification_channel,omitzero" api:"required"`
// The alert threshold amount, in cents.
ThresholdAmount int64 `json:"threshold_amount" api:"required"`
paramObj
}
func (r AdminOrganizationProjectSpendAlertNewParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectSpendAlertNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectSpendAlertNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The currency for the threshold amount.
type AdminOrganizationProjectSpendAlertNewParamsCurrency string
const (
AdminOrganizationProjectSpendAlertNewParamsCurrencyUsd AdminOrganizationProjectSpendAlertNewParamsCurrency = "USD"
)
// The time interval for evaluating spend against the threshold.
type AdminOrganizationProjectSpendAlertNewParamsInterval string
const (
AdminOrganizationProjectSpendAlertNewParamsIntervalMonth AdminOrganizationProjectSpendAlertNewParamsInterval = "month"
)
// Email notification settings for a spend alert.
//
// The properties Recipients, Type are required.
type AdminOrganizationProjectSpendAlertNewParamsNotificationChannel struct {
// Email addresses that receive the spend alert notification.
Recipients []string `json:"recipients,omitzero" api:"required"`
// Optional subject prefix for alert emails.
SubjectPrefix param.Opt[string] `json:"subject_prefix,omitzero"`
// The notification channel type. Currently only `email` is supported.
//
// This field can be elided, and will marshal its zero value as "email".
Type constant.Email `json:"type" default:"email"`
paramObj
}
func (r AdminOrganizationProjectSpendAlertNewParamsNotificationChannel) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectSpendAlertNewParamsNotificationChannel
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectSpendAlertNewParamsNotificationChannel) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationProjectSpendAlertUpdateParams struct {
// The currency for the threshold amount.
//
// Any of "USD".
Currency AdminOrganizationProjectSpendAlertUpdateParamsCurrency `json:"currency,omitzero" api:"required"`
// The time interval for evaluating spend against the threshold.
//
// Any of "month".
Interval AdminOrganizationProjectSpendAlertUpdateParamsInterval `json:"interval,omitzero" api:"required"`
// Email notification settings for a spend alert.
NotificationChannel AdminOrganizationProjectSpendAlertUpdateParamsNotificationChannel `json:"notification_channel,omitzero" api:"required"`
// The alert threshold amount, in cents.
ThresholdAmount int64 `json:"threshold_amount" api:"required"`
paramObj
}
func (r AdminOrganizationProjectSpendAlertUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectSpendAlertUpdateParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectSpendAlertUpdateParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The currency for the threshold amount.
type AdminOrganizationProjectSpendAlertUpdateParamsCurrency string
const (
AdminOrganizationProjectSpendAlertUpdateParamsCurrencyUsd AdminOrganizationProjectSpendAlertUpdateParamsCurrency = "USD"
)
// The time interval for evaluating spend against the threshold.
type AdminOrganizationProjectSpendAlertUpdateParamsInterval string
const (
AdminOrganizationProjectSpendAlertUpdateParamsIntervalMonth AdminOrganizationProjectSpendAlertUpdateParamsInterval = "month"
)
// Email notification settings for a spend alert.
//
// The properties Recipients, Type are required.
type AdminOrganizationProjectSpendAlertUpdateParamsNotificationChannel struct {
// Email addresses that receive the spend alert notification.
Recipients []string `json:"recipients,omitzero" api:"required"`
// Optional subject prefix for alert emails.
SubjectPrefix param.Opt[string] `json:"subject_prefix,omitzero"`
// The notification channel type. Currently only `email` is supported.
//
// This field can be elided, and will marshal its zero value as "email".
Type constant.Email `json:"type" default:"email"`
paramObj
}
func (r AdminOrganizationProjectSpendAlertUpdateParamsNotificationChannel) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationProjectSpendAlertUpdateParamsNotificationChannel
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationProjectSpendAlertUpdateParamsNotificationChannel) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationProjectSpendAlertListParams struct {
// Cursor for pagination. Provide the ID of the last spend alert from the previous
// response to fetch the next page.
After param.Opt[string] `query:"after,omitzero" json:"-"`
// Cursor for pagination. Provide the ID of the first spend alert from the previous
// response to fetch the previous page.
Before param.Opt[string] `query:"before,omitzero" json:"-"`
// A limit on the number of spend alerts to return. Defaults to 20.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Sort order for the returned spend alerts.
//
// Any of "asc", "desc".
Order AdminOrganizationProjectSpendAlertListParamsOrder `query:"order,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [AdminOrganizationProjectSpendAlertListParams]'s query
// parameters as `url.Values`.
func (r AdminOrganizationProjectSpendAlertListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Sort order for the returned spend alerts.
type AdminOrganizationProjectSpendAlertListParamsOrder string
const (
AdminOrganizationProjectSpendAlertListParamsOrderAsc AdminOrganizationProjectSpendAlertListParamsOrder = "asc"
AdminOrganizationProjectSpendAlertListParamsOrderDesc AdminOrganizationProjectSpendAlertListParamsOrder = "desc"
)