-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathbeta.go
More file actions
387 lines (345 loc) · 14.1 KB
/
beta.go
File metadata and controls
387 lines (345 loc) · 14.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
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
387
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package anthropic
import (
"encoding/json"
"github.com/anthropics/anthropic-sdk-go/internal/apijson"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/anthropics/anthropic-sdk-go/packages/respjson"
"github.com/anthropics/anthropic-sdk-go/shared/constant"
)
// BetaService contains methods and other services that help with interacting with
// the anthropic 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 [NewBetaService] method instead.
type BetaService struct {
Options []option.RequestOption
Models BetaModelService
Messages BetaMessageService
Agents BetaAgentService
Environments BetaEnvironmentService
Sessions BetaSessionService
Vaults BetaVaultService
Files BetaFileService
Skills BetaSkillService
UserProfiles BetaUserProfileService
}
// NewBetaService 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 NewBetaService(opts ...option.RequestOption) (r BetaService) {
r = BetaService{}
r.Options = opts
r.Models = NewBetaModelService(opts...)
r.Messages = NewBetaMessageService(opts...)
r.Agents = NewBetaAgentService(opts...)
r.Environments = NewBetaEnvironmentService(opts...)
r.Sessions = NewBetaSessionService(opts...)
r.Vaults = NewBetaVaultService(opts...)
r.Files = NewBetaFileService(opts...)
r.Skills = NewBetaSkillService(opts...)
r.UserProfiles = NewBetaUserProfileService(opts...)
return
}
type AnthropicBeta = string
const (
AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24"
AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31"
AnthropicBetaComputerUse2024_10_22 AnthropicBeta = "computer-use-2024-10-22"
AnthropicBetaComputerUse2025_01_24 AnthropicBeta = "computer-use-2025-01-24"
AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25"
AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01"
AnthropicBetaTokenEfficientTools2025_02_19 AnthropicBeta = "token-efficient-tools-2025-02-19"
AnthropicBetaOutput128k2025_02_19 AnthropicBeta = "output-128k-2025-02-19"
AnthropicBetaFilesAPI2025_04_14 AnthropicBeta = "files-api-2025-04-14"
AnthropicBetaMCPClient2025_04_04 AnthropicBeta = "mcp-client-2025-04-04"
AnthropicBetaMCPClient2025_11_20 AnthropicBeta = "mcp-client-2025-11-20"
AnthropicBetaDevFullThinking2025_05_14 AnthropicBeta = "dev-full-thinking-2025-05-14"
AnthropicBetaInterleavedThinking2025_05_14 AnthropicBeta = "interleaved-thinking-2025-05-14"
AnthropicBetaCodeExecution2025_05_22 AnthropicBeta = "code-execution-2025-05-22"
AnthropicBetaExtendedCacheTTL2025_04_11 AnthropicBeta = "extended-cache-ttl-2025-04-11"
AnthropicBetaContext1m2025_08_07 AnthropicBeta = "context-1m-2025-08-07"
AnthropicBetaContextManagement2025_06_27 AnthropicBeta = "context-management-2025-06-27"
AnthropicBetaModelContextWindowExceeded2025_08_26 AnthropicBeta = "model-context-window-exceeded-2025-08-26"
AnthropicBetaSkills2025_10_02 AnthropicBeta = "skills-2025-10-02"
AnthropicBetaFastMode2026_02_01 AnthropicBeta = "fast-mode-2026-02-01"
AnthropicBetaOutput300k2026_03_24 AnthropicBeta = "output-300k-2026-03-24"
AnthropicBetaAdvisorTool2026_03_01 AnthropicBeta = "advisor-tool-2026-03-01"
AnthropicBetaUserProfiles2026_03_24 AnthropicBeta = "user-profiles-2026-03-24"
)
type BetaAPIError struct {
Message string `json:"message" api:"required"`
Type constant.APIError `json:"type" default:"api_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAPIError) RawJSON() string { return r.JSON.raw }
func (r *BetaAPIError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAuthenticationError struct {
Message string `json:"message" api:"required"`
Type constant.AuthenticationError `json:"type" default:"authentication_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAuthenticationError) RawJSON() string { return r.JSON.raw }
func (r *BetaAuthenticationError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBillingError struct {
Message string `json:"message" api:"required"`
Type constant.BillingError `json:"type" default:"billing_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBillingError) RawJSON() string { return r.JSON.raw }
func (r *BetaBillingError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaErrorUnion contains all possible properties and values from
// [BetaInvalidRequestError], [BetaAuthenticationError], [BetaBillingError],
// [BetaPermissionError], [BetaNotFoundError], [BetaRateLimitError],
// [BetaGatewayTimeoutError], [BetaAPIError], [BetaOverloadedError].
//
// Use the [BetaErrorUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaErrorUnion struct {
Message string `json:"message"`
// Any of "invalid_request_error", "authentication_error", "billing_error",
// "permission_error", "not_found_error", "rate_limit_error", "timeout_error",
// "api_error", "overloaded_error".
Type string `json:"type"`
JSON struct {
Message respjson.Field
Type respjson.Field
raw string
} `json:"-"`
}
// anyBetaError is implemented by each variant of [BetaErrorUnion] to add type
// safety for the return type of [BetaErrorUnion.AsAny]
type anyBetaError interface {
implBetaErrorUnion()
}
func (BetaInvalidRequestError) implBetaErrorUnion() {}
func (BetaAuthenticationError) implBetaErrorUnion() {}
func (BetaBillingError) implBetaErrorUnion() {}
func (BetaPermissionError) implBetaErrorUnion() {}
func (BetaNotFoundError) implBetaErrorUnion() {}
func (BetaRateLimitError) implBetaErrorUnion() {}
func (BetaGatewayTimeoutError) implBetaErrorUnion() {}
func (BetaAPIError) implBetaErrorUnion() {}
func (BetaOverloadedError) implBetaErrorUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := BetaErrorUnion.AsAny().(type) {
// case anthropic.BetaInvalidRequestError:
// case anthropic.BetaAuthenticationError:
// case anthropic.BetaBillingError:
// case anthropic.BetaPermissionError:
// case anthropic.BetaNotFoundError:
// case anthropic.BetaRateLimitError:
// case anthropic.BetaGatewayTimeoutError:
// case anthropic.BetaAPIError:
// case anthropic.BetaOverloadedError:
// default:
// fmt.Errorf("no variant present")
// }
func (u BetaErrorUnion) AsAny() anyBetaError {
switch u.Type {
case "invalid_request_error":
return u.AsInvalidRequestError()
case "authentication_error":
return u.AsAuthenticationError()
case "billing_error":
return u.AsBillingError()
case "permission_error":
return u.AsPermissionError()
case "not_found_error":
return u.AsNotFoundError()
case "rate_limit_error":
return u.AsRateLimitError()
case "timeout_error":
return u.AsTimeoutError()
case "api_error":
return u.AsAPIError()
case "overloaded_error":
return u.AsOverloadedError()
}
return nil
}
func (u BetaErrorUnion) AsInvalidRequestError() (v BetaInvalidRequestError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsAuthenticationError() (v BetaAuthenticationError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsBillingError() (v BetaBillingError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsPermissionError() (v BetaPermissionError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsNotFoundError() (v BetaNotFoundError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsRateLimitError() (v BetaRateLimitError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsTimeoutError() (v BetaGatewayTimeoutError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsAPIError() (v BetaAPIError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaErrorUnion) AsOverloadedError() (v BetaOverloadedError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaErrorUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaErrorUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaErrorResponse struct {
Error BetaErrorUnion `json:"error" api:"required"`
RequestID string `json:"request_id" api:"required"`
Type constant.Error `json:"type" default:"error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Error respjson.Field
RequestID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaErrorResponse) RawJSON() string { return r.JSON.raw }
func (r *BetaErrorResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaGatewayTimeoutError struct {
Message string `json:"message" api:"required"`
Type constant.TimeoutError `json:"type" default:"timeout_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaGatewayTimeoutError) RawJSON() string { return r.JSON.raw }
func (r *BetaGatewayTimeoutError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaInvalidRequestError struct {
Message string `json:"message" api:"required"`
Type constant.InvalidRequestError `json:"type" default:"invalid_request_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaInvalidRequestError) RawJSON() string { return r.JSON.raw }
func (r *BetaInvalidRequestError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaNotFoundError struct {
Message string `json:"message" api:"required"`
Type constant.NotFoundError `json:"type" default:"not_found_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaNotFoundError) RawJSON() string { return r.JSON.raw }
func (r *BetaNotFoundError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaOverloadedError struct {
Message string `json:"message" api:"required"`
Type constant.OverloadedError `json:"type" default:"overloaded_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaOverloadedError) RawJSON() string { return r.JSON.raw }
func (r *BetaOverloadedError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaPermissionError struct {
Message string `json:"message" api:"required"`
Type constant.PermissionError `json:"type" default:"permission_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaPermissionError) RawJSON() string { return r.JSON.raw }
func (r *BetaPermissionError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaRateLimitError struct {
Message string `json:"message" api:"required"`
Type constant.RateLimitError `json:"type" default:"rate_limit_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaRateLimitError) RawJSON() string { return r.JSON.raw }
func (r *BetaRateLimitError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}