github.com/anthropics/anthropic-sdk-go@v1.70.1/beta.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "encoding/json" 7 8 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 9 "github.com/anthropics/anthropic-sdk-go/option" 10 "github.com/anthropics/anthropic-sdk-go/packages/param" 11 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 12 "github.com/anthropics/anthropic-sdk-go/shared/constant" 13 ) 14 15 // BetaService contains methods and other services that help with interacting with 16 // the anthropic API. 17 // 18 // Note, unlike clients, this service does not read variables from the environment 19 // automatically. You should not instantiate this service directly, and instead use 20 // the [NewBetaService] method instead. 21 type BetaService struct { 22 Options []option.RequestOption 23 Models BetaModelService 24 Messages BetaMessageService 25 Agents BetaAgentService 26 Environments BetaEnvironmentService 27 Sessions BetaSessionService 28 Deployments BetaDeploymentService 29 DeploymentRuns BetaDeploymentRunService 30 Vaults BetaVaultService 31 MemoryStores BetaMemoryStoreService 32 Files BetaFileService 33 Skills BetaSkillService 34 Webhooks BetaWebhookService 35 UserProfiles BetaUserProfileService 36 Dreams BetaDreamService 37 Tunnels BetaTunnelService 38 Organization BetaOrganizationService 39 } 40 41 // NewBetaService generates a new service that applies the given options to each 42 // request. These options are applied after the parent client's options (if there 43 // is one), and before any request-specific options. 44 func NewBetaService(opts ...option.RequestOption) (r BetaService) { 45 r = BetaService{} 46 r.Options = opts 47 r.Models = NewBetaModelService(opts...) 48 r.Messages = NewBetaMessageService(opts...) 49 r.Agents = NewBetaAgentService(opts...) 50 r.Environments = NewBetaEnvironmentService(opts...) 51 r.Sessions = NewBetaSessionService(opts...) 52 r.Deployments = NewBetaDeploymentService(opts...) 53 r.DeploymentRuns = NewBetaDeploymentRunService(opts...) 54 r.Vaults = NewBetaVaultService(opts...) 55 r.MemoryStores = NewBetaMemoryStoreService(opts...) 56 r.Files = NewBetaFileService(opts...) 57 r.Skills = NewBetaSkillService(opts...) 58 r.Webhooks = NewBetaWebhookService(opts...) 59 r.UserProfiles = NewBetaUserProfileService(opts...) 60 r.Dreams = NewBetaDreamService(opts...) 61 r.Tunnels = NewBetaTunnelService(opts...) 62 r.Organization = NewBetaOrganizationService(opts...) 63 return 64 } 65 66 type AnthropicBeta = string 67 68 const ( 69 AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24" 70 AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31" 71 AnthropicBetaComputerUse2024_10_22 AnthropicBeta = "computer-use-2024-10-22" 72 AnthropicBetaComputerUse2025_01_24 AnthropicBeta = "computer-use-2025-01-24" 73 AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25" 74 AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01" 75 AnthropicBetaTokenEfficientTools2025_02_19 AnthropicBeta = "token-efficient-tools-2025-02-19" 76 AnthropicBetaOutput128k2025_02_19 AnthropicBeta = "output-128k-2025-02-19" 77 AnthropicBetaFilesAPI2025_04_14 AnthropicBeta = "files-api-2025-04-14" 78 AnthropicBetaMCPClient2025_04_04 AnthropicBeta = "mcp-client-2025-04-04" 79 AnthropicBetaMCPClient2025_11_20 AnthropicBeta = "mcp-client-2025-11-20" 80 AnthropicBetaDevFullThinking2025_05_14 AnthropicBeta = "dev-full-thinking-2025-05-14" 81 AnthropicBetaInterleavedThinking2025_05_14 AnthropicBeta = "interleaved-thinking-2025-05-14" 82 AnthropicBetaCodeExecution2025_05_22 AnthropicBeta = "code-execution-2025-05-22" 83 AnthropicBetaExtendedCacheTTL2025_04_11 AnthropicBeta = "extended-cache-ttl-2025-04-11" 84 AnthropicBetaContext1m2025_08_07 AnthropicBeta = "context-1m-2025-08-07" 85 AnthropicBetaContextManagement2025_06_27 AnthropicBeta = "context-management-2025-06-27" 86 AnthropicBetaModelContextWindowExceeded2025_08_26 AnthropicBeta = "model-context-window-exceeded-2025-08-26" 87 AnthropicBetaSkills2025_10_02 AnthropicBeta = "skills-2025-10-02" 88 AnthropicBetaFastMode2026_02_01 AnthropicBeta = "fast-mode-2026-02-01" 89 AnthropicBetaOutput300k2026_03_24 AnthropicBeta = "output-300k-2026-03-24" 90 AnthropicBetaUserProfiles2026_03_24 AnthropicBeta = "user-profiles-2026-03-24" 91 AnthropicBetaUserProfiles2026_08_18 AnthropicBeta = "user-profiles-2026-08-18" 92 AnthropicBetaAdvisorTool2026_03_01 AnthropicBeta = "advisor-tool-2026-03-01" 93 AnthropicBetaManagedAgents2026_04_01 AnthropicBeta = "managed-agents-2026-04-01" 94 AnthropicBetaCacheDiagnosis2026_04_07 AnthropicBeta = "cache-diagnosis-2026-04-07" 95 AnthropicBetaDreaming2026_04_21 AnthropicBeta = "dreaming-2026-04-21" 96 AnthropicBetaThinkingTokenCount2026_05_13 AnthropicBeta = "thinking-token-count-2026-05-13" 97 AnthropicBetaServerSideFallback2026_06_01 AnthropicBeta = "server-side-fallback-2026-06-01" 98 AnthropicBetaServerSideFallback2026_07_01 AnthropicBeta = "server-side-fallback-2026-07-01" 99 AnthropicBetaFallbackCredit2026_06_01 AnthropicBeta = "fallback-credit-2026-06-01" 100 AnthropicBetaFallbackCredit2026_07_01 AnthropicBeta = "fallback-credit-2026-07-01" 101 AnthropicBetaAgentMemory2026_07_22 AnthropicBeta = "agent-memory-2026-07-22" 102 AnthropicBetaMidConversationToolChanges2026_07_01 AnthropicBeta = "mid-conversation-tool-changes-2026-07-01" 103 AnthropicBetaCompact2026_01_12 AnthropicBeta = "compact-2026-01-12" 104 AnthropicBetaComputerUse2025_11_24 AnthropicBeta = "computer-use-2025-11-24" 105 AnthropicBetaMCPTunnels2026_06_22 AnthropicBeta = "mcp-tunnels-2026-06-22" 106 AnthropicBetaStructuredOutputs2025_11_13 AnthropicBeta = "structured-outputs-2025-11-13" 107 AnthropicBetaTaskBudgets2026_03_13 AnthropicBeta = "task-budgets-2026-03-13" 108 AnthropicBetaThinkingDisplayUpdates2026_08_18 AnthropicBeta = "thinking-display-updates-2026-08-18" 109 AnthropicBetaCEUserManagement2026_07_13 AnthropicBeta = "ce-user-management-2026-07-13" 110 AnthropicBetaMidConversationOutputConfig2026_07_01 AnthropicBeta = "mid-conversation-output-config-2026-07-01" 111 AnthropicBetaThinkingBindingControls2026_08_01 AnthropicBeta = "thinking-binding-controls-2026-08-01" 112 AnthropicBetaMidConversationSystemClearAt2026_08_21 AnthropicBeta = "mid-conversation-system-clear-at-2026-08-21" 113 ) 114 115 type BetaAPIError struct { 116 Message string `json:"message" api:"required"` 117 Type constant.APIError `json:"type" default:"api_error"` 118 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 119 JSON struct { 120 Message respjson.Field 121 Type respjson.Field 122 ExtraFields map[string]respjson.Field 123 raw string 124 } `json:"-"` 125 } 126 127 // Returns the unmodified JSON received from the API 128 func (r BetaAPIError) RawJSON() string { return r.JSON.raw } 129 func (r *BetaAPIError) UnmarshalJSON(data []byte) error { 130 return apijson.UnmarshalRoot(data, r) 131 } 132 133 type BetaAuthenticationError struct { 134 Message string `json:"message" api:"required"` 135 Type constant.AuthenticationError `json:"type" default:"authentication_error"` 136 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 137 JSON struct { 138 Message respjson.Field 139 Type respjson.Field 140 ExtraFields map[string]respjson.Field 141 raw string 142 } `json:"-"` 143 } 144 145 // Returns the unmodified JSON received from the API 146 func (r BetaAuthenticationError) RawJSON() string { return r.JSON.raw } 147 func (r *BetaAuthenticationError) UnmarshalJSON(data []byte) error { 148 return apijson.UnmarshalRoot(data, r) 149 } 150 151 type BetaBillingError struct { 152 Message string `json:"message" api:"required"` 153 Type constant.BillingError `json:"type" default:"billing_error"` 154 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 155 JSON struct { 156 Message respjson.Field 157 Type respjson.Field 158 ExtraFields map[string]respjson.Field 159 raw string 160 } `json:"-"` 161 } 162 163 // Returns the unmodified JSON received from the API 164 func (r BetaBillingError) RawJSON() string { return r.JSON.raw } 165 func (r *BetaBillingError) UnmarshalJSON(data []byte) error { 166 return apijson.UnmarshalRoot(data, r) 167 } 168 169 type BetaCurrency string 170 171 const ( 172 BetaCurrencyUSD BetaCurrency = "USD" 173 ) 174 175 // BetaErrorUnion contains all possible properties and values from 176 // [BetaInvalidRequestError], [BetaAuthenticationError], [BetaBillingError], 177 // [BetaPermissionError], [BetaNotFoundError], [BetaRateLimitError], 178 // [BetaGatewayTimeoutError], [BetaAPIError], [BetaOverloadedError]. 179 // 180 // Use the [BetaErrorUnion.AsAny] method to switch on the variant. 181 // 182 // Use the methods beginning with 'As' to cast the union to one of its variants. 183 type BetaErrorUnion struct { 184 Message string `json:"message"` 185 // Any of "invalid_request_error", "authentication_error", "billing_error", 186 // "permission_error", "not_found_error", "rate_limit_error", "timeout_error", 187 // "api_error", "overloaded_error". 188 Type string `json:"type"` 189 JSON struct { 190 Message respjson.Field 191 Type respjson.Field 192 raw string 193 } `json:"-"` 194 } 195 196 // anyBetaError is implemented by each variant of [BetaErrorUnion] to add type 197 // safety for the return type of [BetaErrorUnion.AsAny] 198 type anyBetaError interface { 199 implBetaErrorUnion() 200 } 201 202 func (BetaInvalidRequestError) implBetaErrorUnion() {} 203 func (BetaAuthenticationError) implBetaErrorUnion() {} 204 func (BetaBillingError) implBetaErrorUnion() {} 205 func (BetaPermissionError) implBetaErrorUnion() {} 206 func (BetaNotFoundError) implBetaErrorUnion() {} 207 func (BetaRateLimitError) implBetaErrorUnion() {} 208 func (BetaGatewayTimeoutError) implBetaErrorUnion() {} 209 func (BetaAPIError) implBetaErrorUnion() {} 210 func (BetaOverloadedError) implBetaErrorUnion() {} 211 212 // Use the following switch statement to find the correct variant 213 // 214 // switch variant := BetaErrorUnion.AsAny().(type) { 215 // case anthropic.BetaInvalidRequestError: 216 // case anthropic.BetaAuthenticationError: 217 // case anthropic.BetaBillingError: 218 // case anthropic.BetaPermissionError: 219 // case anthropic.BetaNotFoundError: 220 // case anthropic.BetaRateLimitError: 221 // case anthropic.BetaGatewayTimeoutError: 222 // case anthropic.BetaAPIError: 223 // case anthropic.BetaOverloadedError: 224 // default: 225 // fmt.Errorf("no variant present") 226 // } 227 func (u BetaErrorUnion) AsAny() anyBetaError { 228 switch u.Type { 229 case "invalid_request_error": 230 return u.AsInvalidRequestError() 231 case "authentication_error": 232 return u.AsAuthenticationError() 233 case "billing_error": 234 return u.AsBillingError() 235 case "permission_error": 236 return u.AsPermissionError() 237 case "not_found_error": 238 return u.AsNotFoundError() 239 case "rate_limit_error": 240 return u.AsRateLimitError() 241 case "timeout_error": 242 return u.AsTimeoutError() 243 case "api_error": 244 return u.AsAPIError() 245 case "overloaded_error": 246 return u.AsOverloadedError() 247 } 248 return nil 249 } 250 251 func (u BetaErrorUnion) AsInvalidRequestError() (v BetaInvalidRequestError) { 252 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 253 return 254 } 255 256 func (u BetaErrorUnion) AsAuthenticationError() (v BetaAuthenticationError) { 257 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 258 return 259 } 260 261 func (u BetaErrorUnion) AsBillingError() (v BetaBillingError) { 262 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 263 return 264 } 265 266 func (u BetaErrorUnion) AsPermissionError() (v BetaPermissionError) { 267 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 268 return 269 } 270 271 func (u BetaErrorUnion) AsNotFoundError() (v BetaNotFoundError) { 272 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 273 return 274 } 275 276 func (u BetaErrorUnion) AsRateLimitError() (v BetaRateLimitError) { 277 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 278 return 279 } 280 281 func (u BetaErrorUnion) AsTimeoutError() (v BetaGatewayTimeoutError) { 282 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 283 return 284 } 285 286 func (u BetaErrorUnion) AsAPIError() (v BetaAPIError) { 287 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 288 return 289 } 290 291 func (u BetaErrorUnion) AsOverloadedError() (v BetaOverloadedError) { 292 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 293 return 294 } 295 296 // Returns the unmodified JSON received from the API 297 func (u BetaErrorUnion) RawJSON() string { return u.JSON.raw } 298 299 func (r *BetaErrorUnion) UnmarshalJSON(data []byte) error { 300 return apijson.UnmarshalRoot(data, r) 301 } 302 303 type BetaErrorResponse struct { 304 Error BetaErrorUnion `json:"error" api:"required"` 305 RequestID string `json:"request_id" api:"required"` 306 Type constant.Error `json:"type" default:"error"` 307 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 308 JSON struct { 309 Error respjson.Field 310 RequestID respjson.Field 311 Type respjson.Field 312 ExtraFields map[string]respjson.Field 313 raw string 314 } `json:"-"` 315 } 316 317 // Returns the unmodified JSON received from the API 318 func (r BetaErrorResponse) RawJSON() string { return r.JSON.raw } 319 func (r *BetaErrorResponse) UnmarshalJSON(data []byte) error { 320 return apijson.UnmarshalRoot(data, r) 321 } 322 323 type BetaGatewayTimeoutError struct { 324 Message string `json:"message" api:"required"` 325 Type constant.TimeoutError `json:"type" default:"timeout_error"` 326 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 327 JSON struct { 328 Message respjson.Field 329 Type respjson.Field 330 ExtraFields map[string]respjson.Field 331 raw string 332 } `json:"-"` 333 } 334 335 // Returns the unmodified JSON received from the API 336 func (r BetaGatewayTimeoutError) RawJSON() string { return r.JSON.raw } 337 func (r *BetaGatewayTimeoutError) UnmarshalJSON(data []byte) error { 338 return apijson.UnmarshalRoot(data, r) 339 } 340 341 type BetaInvalidRequestError struct { 342 Message string `json:"message" api:"required"` 343 Type constant.InvalidRequestError `json:"type" default:"invalid_request_error"` 344 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 345 JSON struct { 346 Message respjson.Field 347 Type respjson.Field 348 ExtraFields map[string]respjson.Field 349 raw string 350 } `json:"-"` 351 } 352 353 // Returns the unmodified JSON received from the API 354 func (r BetaInvalidRequestError) RawJSON() string { return r.JSON.raw } 355 func (r *BetaInvalidRequestError) UnmarshalJSON(data []byte) error { 356 return apijson.UnmarshalRoot(data, r) 357 } 358 359 // A monetary amount in a specific currency. 360 type BetaMonetaryAmount struct { 361 // Amount in minor units of the currency, as an integer decimal string with no 362 // leading zeros: "2500" is $25.00 and "50" is fifty cents. A string rather than a 363 // number so no float rounding is ever applied. 364 Amount string `json:"amount" api:"required"` 365 // Uppercase ISO-4217 currency code. `USD` is the only currency currently 366 // supported; the accepted set is closed and grows only when a new currency is 367 // priced. 368 // 369 // Any of "USD". 370 Currency BetaCurrency `json:"currency" api:"required"` 371 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 372 JSON struct { 373 Amount respjson.Field 374 Currency respjson.Field 375 ExtraFields map[string]respjson.Field 376 raw string 377 } `json:"-"` 378 } 379 380 // Returns the unmodified JSON received from the API 381 func (r BetaMonetaryAmount) RawJSON() string { return r.JSON.raw } 382 func (r *BetaMonetaryAmount) UnmarshalJSON(data []byte) error { 383 return apijson.UnmarshalRoot(data, r) 384 } 385 386 // ToParam converts this BetaMonetaryAmount to a BetaMonetaryAmountParam. 387 // 388 // Warning: the fields of the param type will not be present. ToParam should only 389 // be used at the last possible moment before sending a request. Test for this with 390 // BetaMonetaryAmountParam.Overrides() 391 func (r BetaMonetaryAmount) ToParam() BetaMonetaryAmountParam { 392 return param.Override[BetaMonetaryAmountParam](json.RawMessage(r.RawJSON())) 393 } 394 395 // A monetary amount in a specific currency. 396 // 397 // The properties Amount, Currency are required. 398 type BetaMonetaryAmountParam struct { 399 // Amount in minor units of the currency, as an integer decimal string with no 400 // leading zeros: "2500" is $25.00 and "50" is fifty cents. A string rather than a 401 // number so no float rounding is ever applied. 402 Amount string `json:"amount" api:"required"` 403 // Uppercase ISO-4217 currency code. `USD` is the only currency currently 404 // supported; the accepted set is closed and grows only when a new currency is 405 // priced. 406 // 407 // Any of "USD". 408 Currency BetaCurrency `json:"currency,omitzero" api:"required"` 409 paramObj 410 } 411 412 func (r BetaMonetaryAmountParam) MarshalJSON() (data []byte, err error) { 413 type shadow BetaMonetaryAmountParam 414 return param.MarshalObject(r, (*shadow)(&r)) 415 } 416 func (r *BetaMonetaryAmountParam) UnmarshalJSON(data []byte) error { 417 return apijson.UnmarshalRoot(data, r) 418 } 419 420 type BetaNotFoundError struct { 421 Message string `json:"message" api:"required"` 422 Type constant.NotFoundError `json:"type" default:"not_found_error"` 423 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 424 JSON struct { 425 Message respjson.Field 426 Type respjson.Field 427 ExtraFields map[string]respjson.Field 428 raw string 429 } `json:"-"` 430 } 431 432 // Returns the unmodified JSON received from the API 433 func (r BetaNotFoundError) RawJSON() string { return r.JSON.raw } 434 func (r *BetaNotFoundError) UnmarshalJSON(data []byte) error { 435 return apijson.UnmarshalRoot(data, r) 436 } 437 438 type BetaOverloadedError struct { 439 Message string `json:"message" api:"required"` 440 Type constant.OverloadedError `json:"type" default:"overloaded_error"` 441 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 442 JSON struct { 443 Message respjson.Field 444 Type respjson.Field 445 ExtraFields map[string]respjson.Field 446 raw string 447 } `json:"-"` 448 } 449 450 // Returns the unmodified JSON received from the API 451 func (r BetaOverloadedError) RawJSON() string { return r.JSON.raw } 452 func (r *BetaOverloadedError) UnmarshalJSON(data []byte) error { 453 return apijson.UnmarshalRoot(data, r) 454 } 455 456 type BetaPermissionError struct { 457 Message string `json:"message" api:"required"` 458 Type constant.PermissionError `json:"type" default:"permission_error"` 459 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 460 JSON struct { 461 Message respjson.Field 462 Type respjson.Field 463 ExtraFields map[string]respjson.Field 464 raw string 465 } `json:"-"` 466 } 467 468 // Returns the unmodified JSON received from the API 469 func (r BetaPermissionError) RawJSON() string { return r.JSON.raw } 470 func (r *BetaPermissionError) UnmarshalJSON(data []byte) error { 471 return apijson.UnmarshalRoot(data, r) 472 } 473 474 type BetaRateLimitError struct { 475 Message string `json:"message" api:"required"` 476 Type constant.RateLimitError `json:"type" default:"rate_limit_error"` 477 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 478 JSON struct { 479 Message respjson.Field 480 Type respjson.Field 481 ExtraFields map[string]respjson.Field 482 raw string 483 } `json:"-"` 484 } 485 486 // Returns the unmodified JSON received from the API 487 func (r BetaRateLimitError) RawJSON() string { return r.JSON.raw } 488 func (r *BetaRateLimitError) UnmarshalJSON(data []byte) error { 489 return apijson.UnmarshalRoot(data, r) 490 }