Repository navigation
Expand file tree
/
Copy pathadminorganizationadminapikey.go
More file actions
252 lines (228 loc) · 10.1 KB
/
Copy pathadminorganizationadminapikey.go
File metadata and controls
252 lines (228 loc) · 10.1 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
// 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"
)
// AdminOrganizationAdminAPIKeyService 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 [NewAdminOrganizationAdminAPIKeyService] method instead.
type AdminOrganizationAdminAPIKeyService struct {
Options []option.RequestOption
}
// NewAdminOrganizationAdminAPIKeyService 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 NewAdminOrganizationAdminAPIKeyService(opts ...option.RequestOption) (r AdminOrganizationAdminAPIKeyService) {
r = AdminOrganizationAdminAPIKeyService{}
r.Options = requestconfig.InheritedOptions(opts...)
return
}
// Create an organization admin API key
func (r *AdminOrganizationAdminAPIKeyService) New(ctx context.Context, body AdminOrganizationAdminAPIKeyNewParams, opts ...option.RequestOption) (res *AdminOrganizationAdminAPIKeyNewResponse, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
path := "organization/admin_api_keys"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Retrieve a single organization API key
func (r *AdminOrganizationAdminAPIKeyService) Get(ctx context.Context, keyID string, opts ...option.RequestOption) (res *AdminAPIKey, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if keyID == "" {
err = errors.New("missing required key_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/admin_api_keys/%s", keyID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List organization API keys
func (r *AdminOrganizationAdminAPIKeyService) List(ctx context.Context, query AdminOrganizationAdminAPIKeyListParams, opts ...option.RequestOption) (res *pagination.CursorPage[AdminAPIKey], 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...)
path := "organization/admin_api_keys"
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 organization API keys
func (r *AdminOrganizationAdminAPIKeyService) ListAutoPaging(ctx context.Context, query AdminOrganizationAdminAPIKeyListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[AdminAPIKey] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Delete an organization admin API key
func (r *AdminOrganizationAdminAPIKeyService) Delete(ctx context.Context, keyID string, opts ...option.RequestOption) (res *AdminOrganizationAdminAPIKeyDeleteResponse, err error) {
var preClientOpts = []option.RequestOption{requestconfig.WithAdminAPIKeyAuthSecurity()}
opts = slices.Concat(preClientOpts, r.Options, opts)
if keyID == "" {
err = errors.New("missing required key_id parameter")
return nil, err
}
path := requestconfig.FormatPath("organization/admin_api_keys/%s", keyID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// Represents an individual Admin API key in an org.
type AdminAPIKey struct {
// The identifier, which can be referenced in API endpoints
ID string `json:"id" api:"required"`
// The Unix timestamp (in seconds) of when the API key was created
CreatedAt int64 `json:"created_at" api:"required" format:"unixtime"`
// The Unix timestamp (in seconds) of when the API key expires
ExpiresAt int64 `json:"expires_at" api:"required" format:"unixtime"`
// The object type, which is always `organization.admin_api_key`
Object constant.OrganizationAdminAPIKey `json:"object" default:"organization.admin_api_key"`
Owner AdminAPIKeyOwner `json:"owner" api:"required"`
// The redacted value of the API key
RedactedValue string `json:"redacted_value" api:"required"`
// The Unix timestamp (in seconds) of when the API key was last used
LastUsedAt int64 `json:"last_used_at" api:"nullable" format:"unixtime"`
// The name of the API key
Name string `json:"name" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
ExpiresAt respjson.Field
Object respjson.Field
Owner respjson.Field
RedactedValue respjson.Field
LastUsedAt respjson.Field
Name respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AdminAPIKey) RawJSON() string { return r.JSON.raw }
func (r *AdminAPIKey) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminAPIKeyOwner struct {
// The identifier, which can be referenced in API endpoints
ID string `json:"id"`
// The Unix timestamp (in seconds) of when the user was created
CreatedAt int64 `json:"created_at" format:"unixtime"`
// The name of the user
Name string `json:"name"`
// The object type, which is always organization.user
Object string `json:"object"`
// Always `owner`
Role string `json:"role"`
// Always `user`
Type string `json:"type"`
// 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
Role respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AdminAPIKeyOwner) RawJSON() string { return r.JSON.raw }
func (r *AdminAPIKeyOwner) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Represents an individual Admin API key in an org.
type AdminOrganizationAdminAPIKeyNewResponse struct {
// The value of the API key. Only shown on create.
Value string `json:"value" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Value respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
AdminAPIKey
}
// Returns the unmodified JSON received from the API
func (r AdminOrganizationAdminAPIKeyNewResponse) RawJSON() string { return r.JSON.raw }
func (r *AdminOrganizationAdminAPIKeyNewResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationAdminAPIKeyDeleteResponse struct {
ID string `json:"id" api:"required"`
Deleted bool `json:"deleted" api:"required"`
Object constant.OrganizationAdminAPIKeyDeleted `json:"object" default:"organization.admin_api_key.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 AdminOrganizationAdminAPIKeyDeleteResponse) RawJSON() string { return r.JSON.raw }
func (r *AdminOrganizationAdminAPIKeyDeleteResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationAdminAPIKeyNewParams struct {
Name string `json:"name" api:"required"`
// The number of seconds until the API key expires. Omit this field for a key that
// does not expire.
ExpiresInSeconds param.Opt[int64] `json:"expires_in_seconds,omitzero"`
paramObj
}
func (r AdminOrganizationAdminAPIKeyNewParams) MarshalJSON() (data []byte, err error) {
type shadow AdminOrganizationAdminAPIKeyNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *AdminOrganizationAdminAPIKeyNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AdminOrganizationAdminAPIKeyListParams struct {
// Return keys with IDs that come after this ID in the pagination order.
After param.Opt[string] `query:"after,omitzero" json:"-"`
// Maximum number of keys to return.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Order results by creation time, ascending or descending.
//
// Any of "asc", "desc".
Order AdminOrganizationAdminAPIKeyListParamsOrder `query:"order,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [AdminOrganizationAdminAPIKeyListParams]'s query parameters
// as `url.Values`.
func (r AdminOrganizationAdminAPIKeyListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatBrackets,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Order results by creation time, ascending or descending.
type AdminOrganizationAdminAPIKeyListParamsOrder string
const (
AdminOrganizationAdminAPIKeyListParamsOrderAsc AdminOrganizationAdminAPIKeyListParamsOrder = "asc"
AdminOrganizationAdminAPIKeyListParamsOrderDesc AdminOrganizationAdminAPIKeyListParamsOrder = "desc"
)