github.com/anthropics/anthropic-sdk-go@v1.70.1/betaenvironment.go (about) 1 // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. 2 3 package anthropic 4 5 import ( 6 "context" 7 "encoding/json" 8 "errors" 9 "fmt" 10 "net/http" 11 "net/url" 12 "slices" 13 14 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 15 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 16 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 17 "github.com/anthropics/anthropic-sdk-go/option" 18 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 19 "github.com/anthropics/anthropic-sdk-go/packages/param" 20 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 21 "github.com/anthropics/anthropic-sdk-go/shared/constant" 22 ) 23 24 // BetaEnvironmentService contains methods and other services that help with 25 // interacting with the anthropic API. 26 // 27 // Note, unlike clients, this service does not read variables from the environment 28 // automatically. You should not instantiate this service directly, and instead use 29 // the [NewBetaEnvironmentService] method instead. 30 type BetaEnvironmentService struct { 31 Options []option.RequestOption 32 Work BetaEnvironmentWorkService 33 } 34 35 // NewBetaEnvironmentService generates a new service that applies the given options 36 // to each request. These options are applied after the parent client's options (if 37 // there is one), and before any request-specific options. 38 func NewBetaEnvironmentService(opts ...option.RequestOption) (r BetaEnvironmentService) { 39 r = BetaEnvironmentService{} 40 r.Options = opts 41 r.Work = NewBetaEnvironmentWorkService(opts...) 42 return 43 } 44 45 // Create a new environment with the specified configuration. 46 func (r *BetaEnvironmentService) New(ctx context.Context, params BetaEnvironmentNewParams, opts ...option.RequestOption) (res *BetaEnvironment, err error) { 47 for _, v := range params.Betas { 48 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 49 } 50 if !param.IsOmitted(params.WorkspaceID) { 51 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 52 } 53 opts = slices.Concat(r.Options, opts) 54 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 55 path := "v1/environments?beta=true" 56 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 57 return res, err 58 } 59 60 // Retrieve a specific environment by ID. 61 func (r *BetaEnvironmentService) Get(ctx context.Context, environmentID string, query BetaEnvironmentGetParams, opts ...option.RequestOption) (res *BetaEnvironment, err error) { 62 for _, v := range query.Betas { 63 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 64 } 65 if !param.IsOmitted(query.WorkspaceID) { 66 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", query.WorkspaceID.Value))) 67 } 68 opts = slices.Concat(r.Options, opts) 69 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 70 if environmentID == "" { 71 err = errors.New("missing required environment_id parameter") 72 return nil, err 73 } 74 path := fmt.Sprintf("v1/environments/%s?beta=true", environmentID) 75 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 76 return res, err 77 } 78 79 // Update an existing environment's configuration. 80 func (r *BetaEnvironmentService) Update(ctx context.Context, environmentID string, params BetaEnvironmentUpdateParams, opts ...option.RequestOption) (res *BetaEnvironment, err error) { 81 for _, v := range params.Betas { 82 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 83 } 84 if !param.IsOmitted(params.WorkspaceID) { 85 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 86 } 87 opts = slices.Concat(r.Options, opts) 88 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 89 if environmentID == "" { 90 err = errors.New("missing required environment_id parameter") 91 return nil, err 92 } 93 path := fmt.Sprintf("v1/environments/%s?beta=true", environmentID) 94 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...) 95 return res, err 96 } 97 98 // List environments with pagination support. 99 func (r *BetaEnvironmentService) List(ctx context.Context, params BetaEnvironmentListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaEnvironment], err error) { 100 var raw *http.Response 101 for _, v := range params.Betas { 102 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 103 } 104 if !param.IsOmitted(params.WorkspaceID) { 105 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 106 } 107 opts = slices.Concat(r.Options, opts) 108 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01"), option.WithResponseInto(&raw)}, opts...) 109 path := "v1/environments?beta=true" 110 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 111 if err != nil { 112 return nil, err 113 } 114 err = cfg.Execute() 115 if err != nil { 116 return nil, err 117 } 118 res.SetPageConfig(cfg, raw) 119 return res, nil 120 } 121 122 // List environments with pagination support. 123 func (r *BetaEnvironmentService) ListAutoPaging(ctx context.Context, params BetaEnvironmentListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaEnvironment] { 124 return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...)) 125 } 126 127 // Delete an environment by ID. Returns a confirmation of the deletion. 128 func (r *BetaEnvironmentService) Delete(ctx context.Context, environmentID string, body BetaEnvironmentDeleteParams, opts ...option.RequestOption) (res *BetaEnvironmentDeleteResponse, err error) { 129 for _, v := range body.Betas { 130 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 131 } 132 if !param.IsOmitted(body.WorkspaceID) { 133 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", body.WorkspaceID.Value))) 134 } 135 opts = slices.Concat(r.Options, opts) 136 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 137 if environmentID == "" { 138 err = errors.New("missing required environment_id parameter") 139 return nil, err 140 } 141 path := fmt.Sprintf("v1/environments/%s?beta=true", environmentID) 142 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...) 143 return res, err 144 } 145 146 // Archive an environment by ID. Archived environments cannot be used to create new 147 // sessions. 148 func (r *BetaEnvironmentService) Archive(ctx context.Context, environmentID string, body BetaEnvironmentArchiveParams, opts ...option.RequestOption) (res *BetaEnvironment, err error) { 149 for _, v := range body.Betas { 150 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 151 } 152 if !param.IsOmitted(body.WorkspaceID) { 153 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", body.WorkspaceID.Value))) 154 } 155 opts = slices.Concat(r.Options, opts) 156 opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...) 157 if environmentID == "" { 158 err = errors.New("missing required environment_id parameter") 159 return nil, err 160 } 161 path := fmt.Sprintf("v1/environments/%s/archive?beta=true", environmentID) 162 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...) 163 return res, err 164 } 165 166 // `cloud` environment configuration. 167 type BetaCloudConfig struct { 168 // Network configuration policy. 169 Networking BetaCloudConfigNetworkingUnion `json:"networking" api:"required"` 170 // Package manager configuration. 171 Packages BetaPackages `json:"packages" api:"required"` 172 // Environment type 173 Type constant.Cloud `json:"type" default:"cloud"` 174 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 175 JSON struct { 176 Networking respjson.Field 177 Packages respjson.Field 178 Type respjson.Field 179 ExtraFields map[string]respjson.Field 180 raw string 181 } `json:"-"` 182 } 183 184 // Returns the unmodified JSON received from the API 185 func (r BetaCloudConfig) RawJSON() string { return r.JSON.raw } 186 func (r *BetaCloudConfig) UnmarshalJSON(data []byte) error { 187 return apijson.UnmarshalRoot(data, r) 188 } 189 190 // BetaCloudConfigNetworkingUnion contains all possible properties and values from 191 // [BetaUnrestrictedNetwork], [BetaLimitedNetwork]. 192 // 193 // Use the [BetaCloudConfigNetworkingUnion.AsAny] method to switch on the variant. 194 // 195 // Use the methods beginning with 'As' to cast the union to one of its variants. 196 type BetaCloudConfigNetworkingUnion struct { 197 // Any of "unrestricted", "limited". 198 Type string `json:"type"` 199 // This field is from variant [BetaLimitedNetwork]. 200 AllowMCPServers bool `json:"allow_mcp_servers"` 201 // This field is from variant [BetaLimitedNetwork]. 202 AllowPackageManagers bool `json:"allow_package_managers"` 203 // This field is from variant [BetaLimitedNetwork]. 204 AllowedHosts []string `json:"allowed_hosts"` 205 JSON struct { 206 Type respjson.Field 207 AllowMCPServers respjson.Field 208 AllowPackageManagers respjson.Field 209 AllowedHosts respjson.Field 210 raw string 211 } `json:"-"` 212 } 213 214 // anyBetaCloudConfigNetworking is implemented by each variant of 215 // [BetaCloudConfigNetworkingUnion] to add type safety for the return type of 216 // [BetaCloudConfigNetworkingUnion.AsAny] 217 type anyBetaCloudConfigNetworking interface { 218 implBetaCloudConfigNetworkingUnion() 219 } 220 221 func (BetaUnrestrictedNetwork) implBetaCloudConfigNetworkingUnion() {} 222 func (BetaLimitedNetwork) implBetaCloudConfigNetworkingUnion() {} 223 224 // Use the following switch statement to find the correct variant 225 // 226 // switch variant := BetaCloudConfigNetworkingUnion.AsAny().(type) { 227 // case anthropic.BetaUnrestrictedNetwork: 228 // case anthropic.BetaLimitedNetwork: 229 // default: 230 // fmt.Errorf("no variant present") 231 // } 232 func (u BetaCloudConfigNetworkingUnion) AsAny() anyBetaCloudConfigNetworking { 233 switch u.Type { 234 case "unrestricted": 235 return u.AsUnrestricted() 236 case "limited": 237 return u.AsLimited() 238 } 239 return nil 240 } 241 242 func (u BetaCloudConfigNetworkingUnion) AsUnrestricted() (v BetaUnrestrictedNetwork) { 243 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 244 return 245 } 246 247 func (u BetaCloudConfigNetworkingUnion) AsLimited() (v BetaLimitedNetwork) { 248 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 249 return 250 } 251 252 // Returns the unmodified JSON received from the API 253 func (u BetaCloudConfigNetworkingUnion) RawJSON() string { return u.JSON.raw } 254 255 func (r *BetaCloudConfigNetworkingUnion) UnmarshalJSON(data []byte) error { 256 return apijson.UnmarshalRoot(data, r) 257 } 258 259 // Request params for `cloud` environment configuration. 260 // 261 // Fields default to null; on update, omitted fields preserve the existing value. 262 // 263 // The property Type is required. 264 type BetaCloudConfigParams struct { 265 // Network configuration policy. Omit on update to preserve the existing value. 266 Networking BetaCloudConfigParamsNetworkingUnion `json:"networking,omitzero"` 267 // Specify packages (and optionally their versions) available in this environment. 268 // 269 // When versioning, use the version semantics relevant for the package manager, 270 // e.g. for `pip` use `package==1.0.0`. You are responsible for validating the 271 // package and version exist. Unversioned installs the latest. 272 // 273 // Under `limited` networking, requires `networking.allow_package_managers` to be 274 // `true`. 275 Packages BetaPackagesParams `json:"packages,omitzero"` 276 // Environment type 277 // 278 // This field can be elided, and will marshal its zero value as "cloud". 279 Type constant.Cloud `json:"type" default:"cloud"` 280 paramObj 281 } 282 283 func (r BetaCloudConfigParams) MarshalJSON() (data []byte, err error) { 284 type shadow BetaCloudConfigParams 285 return param.MarshalObject(r, (*shadow)(&r)) 286 } 287 func (r *BetaCloudConfigParams) UnmarshalJSON(data []byte) error { 288 return apijson.UnmarshalRoot(data, r) 289 } 290 291 // Only one field can be non-zero. 292 // 293 // Use [param.IsOmitted] to confirm if a field is set. 294 type BetaCloudConfigParamsNetworkingUnion struct { 295 OfUnrestricted *BetaUnrestrictedNetworkParam `json:",omitzero,inline"` 296 OfLimited *BetaLimitedNetworkParams `json:",omitzero,inline"` 297 paramUnion 298 } 299 300 func (u BetaCloudConfigParamsNetworkingUnion) MarshalJSON() ([]byte, error) { 301 return param.MarshalUnion(u, u.OfUnrestricted, u.OfLimited) 302 } 303 func (u *BetaCloudConfigParamsNetworkingUnion) UnmarshalJSON(data []byte) error { 304 return apijson.UnmarshalRoot(data, u) 305 } 306 307 func (u *BetaCloudConfigParamsNetworkingUnion) asAny() any { 308 if !param.IsOmitted(u.OfUnrestricted) { 309 return u.OfUnrestricted 310 } else if !param.IsOmitted(u.OfLimited) { 311 return u.OfLimited 312 } 313 return nil 314 } 315 316 // Returns a pointer to the underlying variant's property, if present. 317 func (u BetaCloudConfigParamsNetworkingUnion) GetAllowMCPServers() *bool { 318 if vt := u.OfLimited; vt != nil && vt.AllowMCPServers.Valid() { 319 return &vt.AllowMCPServers.Value 320 } 321 return nil 322 } 323 324 // Returns a pointer to the underlying variant's property, if present. 325 func (u BetaCloudConfigParamsNetworkingUnion) GetAllowPackageManagers() *bool { 326 if vt := u.OfLimited; vt != nil && vt.AllowPackageManagers.Valid() { 327 return &vt.AllowPackageManagers.Value 328 } 329 return nil 330 } 331 332 // Returns a pointer to the underlying variant's property, if present. 333 func (u BetaCloudConfigParamsNetworkingUnion) GetAllowedHosts() []string { 334 if vt := u.OfLimited; vt != nil { 335 return vt.AllowedHosts 336 } 337 return nil 338 } 339 340 // Returns a pointer to the underlying variant's property, if present. 341 func (u BetaCloudConfigParamsNetworkingUnion) GetType() *string { 342 if vt := u.OfUnrestricted; vt != nil { 343 return (*string)(&vt.Type) 344 } else if vt := u.OfLimited; vt != nil { 345 return (*string)(&vt.Type) 346 } 347 return nil 348 } 349 350 func init() { 351 apijson.RegisterUnion[BetaCloudConfigParamsNetworkingUnion]( 352 "type", 353 apijson.Discriminator[BetaUnrestrictedNetworkParam]("unrestricted"), 354 apijson.Discriminator[BetaLimitedNetworkParams]("limited"), 355 ) 356 } 357 358 // Unified Environment resource for both cloud and self-hosted environments. 359 type BetaEnvironment struct { 360 // Environment identifier (e.g., 'env\_...') 361 ID string `json:"id" api:"required"` 362 // RFC 3339 timestamp when environment was archived, or null if not archived 363 ArchivedAt string `json:"archived_at" api:"required"` 364 // Environment configuration (either Anthropic Cloud or self-hosted) 365 Config BetaEnvironmentConfigUnion `json:"config" api:"required"` 366 // RFC 3339 timestamp when environment was created 367 CreatedAt string `json:"created_at" api:"required"` 368 // User-provided description for the environment; null when unset 369 Description string `json:"description" api:"required"` 370 // User-provided metadata key-value pairs 371 Metadata map[string]string `json:"metadata" api:"required"` 372 // Human-readable name for the environment 373 Name string `json:"name" api:"required"` 374 // The type of object (always 'environment') 375 Type constant.Environment `json:"type" default:"environment"` 376 // RFC 3339 timestamp when environment was last updated 377 UpdatedAt string `json:"updated_at" api:"required"` 378 // The visibility scope for this environment. 'organization' means visible to all 379 // accounts. 'account' means visible only to the owning account. 380 // 381 // Any of "organization", "account". 382 Scope BetaEnvironmentScope `json:"scope"` 383 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 384 JSON struct { 385 ID respjson.Field 386 ArchivedAt respjson.Field 387 Config respjson.Field 388 CreatedAt respjson.Field 389 Description respjson.Field 390 Metadata respjson.Field 391 Name respjson.Field 392 Type respjson.Field 393 UpdatedAt respjson.Field 394 Scope respjson.Field 395 ExtraFields map[string]respjson.Field 396 raw string 397 } `json:"-"` 398 } 399 400 // Returns the unmodified JSON received from the API 401 func (r BetaEnvironment) RawJSON() string { return r.JSON.raw } 402 func (r *BetaEnvironment) UnmarshalJSON(data []byte) error { 403 return apijson.UnmarshalRoot(data, r) 404 } 405 406 // BetaEnvironmentConfigUnion contains all possible properties and values from 407 // [BetaCloudConfig], [BetaSelfHostedConfig]. 408 // 409 // Use the [BetaEnvironmentConfigUnion.AsAny] method to switch on the variant. 410 // 411 // Use the methods beginning with 'As' to cast the union to one of its variants. 412 type BetaEnvironmentConfigUnion struct { 413 // This field is from variant [BetaCloudConfig]. 414 Networking BetaCloudConfigNetworkingUnion `json:"networking"` 415 // This field is from variant [BetaCloudConfig]. 416 Packages BetaPackages `json:"packages"` 417 // Any of "cloud", "self_hosted". 418 Type string `json:"type"` 419 JSON struct { 420 Networking respjson.Field 421 Packages respjson.Field 422 Type respjson.Field 423 raw string 424 } `json:"-"` 425 } 426 427 // anyBetaEnvironmentConfig is implemented by each variant of 428 // [BetaEnvironmentConfigUnion] to add type safety for the return type of 429 // [BetaEnvironmentConfigUnion.AsAny] 430 type anyBetaEnvironmentConfig interface { 431 implBetaEnvironmentConfigUnion() 432 } 433 434 func (BetaCloudConfig) implBetaEnvironmentConfigUnion() {} 435 func (BetaSelfHostedConfig) implBetaEnvironmentConfigUnion() {} 436 437 // Use the following switch statement to find the correct variant 438 // 439 // switch variant := BetaEnvironmentConfigUnion.AsAny().(type) { 440 // case anthropic.BetaCloudConfig: 441 // case anthropic.BetaSelfHostedConfig: 442 // default: 443 // fmt.Errorf("no variant present") 444 // } 445 func (u BetaEnvironmentConfigUnion) AsAny() anyBetaEnvironmentConfig { 446 switch u.Type { 447 case "cloud": 448 return u.AsCloud() 449 case "self_hosted": 450 return u.AsSelfHosted() 451 } 452 return nil 453 } 454 455 func (u BetaEnvironmentConfigUnion) AsCloud() (v BetaCloudConfig) { 456 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 457 return 458 } 459 460 func (u BetaEnvironmentConfigUnion) AsSelfHosted() (v BetaSelfHostedConfig) { 461 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v) 462 return 463 } 464 465 // Returns the unmodified JSON received from the API 466 func (u BetaEnvironmentConfigUnion) RawJSON() string { return u.JSON.raw } 467 468 func (r *BetaEnvironmentConfigUnion) UnmarshalJSON(data []byte) error { 469 return apijson.UnmarshalRoot(data, r) 470 } 471 472 // The visibility scope for this environment. 'organization' means visible to all 473 // accounts. 'account' means visible only to the owning account. 474 type BetaEnvironmentScope string 475 476 const ( 477 BetaEnvironmentScopeOrganization BetaEnvironmentScope = "organization" 478 BetaEnvironmentScopeAccount BetaEnvironmentScope = "account" 479 ) 480 481 // Response after deleting an environment. 482 type BetaEnvironmentDeleteResponse struct { 483 // Environment identifier 484 ID string `json:"id" api:"required"` 485 // The type of response 486 // 487 // Any of "environment_deleted". 488 Type BetaEnvironmentDeleteResponseType `json:"type" api:"required"` 489 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 490 JSON struct { 491 ID respjson.Field 492 Type respjson.Field 493 ExtraFields map[string]respjson.Field 494 raw string 495 } `json:"-"` 496 } 497 498 // Returns the unmodified JSON received from the API 499 func (r BetaEnvironmentDeleteResponse) RawJSON() string { return r.JSON.raw } 500 func (r *BetaEnvironmentDeleteResponse) UnmarshalJSON(data []byte) error { 501 return apijson.UnmarshalRoot(data, r) 502 } 503 504 // The type of response 505 type BetaEnvironmentDeleteResponseType string 506 507 const ( 508 BetaEnvironmentDeleteResponseTypeEnvironmentDeleted BetaEnvironmentDeleteResponseType = "environment_deleted" 509 ) 510 511 // Limited network access. 512 type BetaLimitedNetwork struct { 513 // Permits outbound access to MCP server endpoints configured on the agent, beyond 514 // those listed in the `allowed_hosts` array. 515 AllowMCPServers bool `json:"allow_mcp_servers" api:"required"` 516 // Permits outbound access to public package registries (PyPI, npm, etc.) beyond 517 // those listed in the `allowed_hosts` array. 518 AllowPackageManagers bool `json:"allow_package_managers" api:"required"` 519 // Specifies domains the container can reach. 520 AllowedHosts []string `json:"allowed_hosts" api:"required"` 521 // Network policy type 522 Type constant.Limited `json:"type" default:"limited"` 523 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 524 JSON struct { 525 AllowMCPServers respjson.Field 526 AllowPackageManagers respjson.Field 527 AllowedHosts respjson.Field 528 Type respjson.Field 529 ExtraFields map[string]respjson.Field 530 raw string 531 } `json:"-"` 532 } 533 534 // Returns the unmodified JSON received from the API 535 func (r BetaLimitedNetwork) RawJSON() string { return r.JSON.raw } 536 func (r *BetaLimitedNetwork) UnmarshalJSON(data []byte) error { 537 return apijson.UnmarshalRoot(data, r) 538 } 539 540 // Limited network request params. 541 // 542 // Fields default to null; on update, omitted fields preserve the existing value. 543 // 544 // The property Type is required. 545 type BetaLimitedNetworkParams struct { 546 // Permits outbound access to MCP server endpoints configured on the agent, beyond 547 // those listed in the `allowed_hosts` array. Defaults to `false`. 548 AllowMCPServers param.Opt[bool] `json:"allow_mcp_servers,omitzero"` 549 // Permits outbound access to public package registries (PyPI, npm, etc.) beyond 550 // those listed in the `allowed_hosts` array. Defaults to `false` on creation. Must 551 // be `true` when `packages` are specified. 552 AllowPackageManagers param.Opt[bool] `json:"allow_package_managers,omitzero"` 553 // Specifies domains the container can reach. 554 AllowedHosts []string `json:"allowed_hosts,omitzero"` 555 // Network policy type 556 // 557 // This field can be elided, and will marshal its zero value as "limited". 558 Type constant.Limited `json:"type" default:"limited"` 559 paramObj 560 } 561 562 func (r BetaLimitedNetworkParams) MarshalJSON() (data []byte, err error) { 563 type shadow BetaLimitedNetworkParams 564 return param.MarshalObject(r, (*shadow)(&r)) 565 } 566 func (r *BetaLimitedNetworkParams) UnmarshalJSON(data []byte) error { 567 return apijson.UnmarshalRoot(data, r) 568 } 569 570 // Packages (and their versions) available in this environment. 571 type BetaPackages struct { 572 // Ubuntu/Debian packages to install 573 Apt []string `json:"apt" api:"required"` 574 // Rust packages to install 575 Cargo []string `json:"cargo" api:"required"` 576 // Ruby packages to install 577 Gem []string `json:"gem" api:"required"` 578 // Go packages to install 579 Go []string `json:"go" api:"required"` 580 // Node.js packages to install 581 Npm []string `json:"npm" api:"required"` 582 // Python packages to install 583 Pip []string `json:"pip" api:"required"` 584 // Package configuration type 585 // 586 // Any of "packages". 587 Type BetaPackagesType `json:"type"` 588 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 589 JSON struct { 590 Apt respjson.Field 591 Cargo respjson.Field 592 Gem respjson.Field 593 Go respjson.Field 594 Npm respjson.Field 595 Pip respjson.Field 596 Type respjson.Field 597 ExtraFields map[string]respjson.Field 598 raw string 599 } `json:"-"` 600 } 601 602 // Returns the unmodified JSON received from the API 603 func (r BetaPackages) RawJSON() string { return r.JSON.raw } 604 func (r *BetaPackages) UnmarshalJSON(data []byte) error { 605 return apijson.UnmarshalRoot(data, r) 606 } 607 608 // Package configuration type 609 type BetaPackagesType string 610 611 const ( 612 BetaPackagesTypePackages BetaPackagesType = "packages" 613 ) 614 615 // Specify packages (and optionally their versions) available in this environment. 616 // 617 // When versioning, use the version semantics relevant for the package manager, 618 // e.g. for `pip` use `package==1.0.0`. You are responsible for validating the 619 // package and version exist. Unversioned installs the latest. 620 // 621 // Under `limited` networking, requires `networking.allow_package_managers` to be 622 // `true`. 623 type BetaPackagesParams struct { 624 // Ubuntu/Debian packages to install 625 Apt []string `json:"apt,omitzero"` 626 // Rust packages to install 627 Cargo []string `json:"cargo,omitzero"` 628 // Ruby packages to install 629 Gem []string `json:"gem,omitzero"` 630 // Go packages to install 631 Go []string `json:"go,omitzero"` 632 // Node.js packages to install 633 Npm []string `json:"npm,omitzero"` 634 // Python packages to install 635 Pip []string `json:"pip,omitzero"` 636 // Package configuration type 637 // 638 // Any of "packages". 639 Type BetaPackagesParamsType `json:"type,omitzero"` 640 paramObj 641 } 642 643 func (r BetaPackagesParams) MarshalJSON() (data []byte, err error) { 644 type shadow BetaPackagesParams 645 return param.MarshalObject(r, (*shadow)(&r)) 646 } 647 func (r *BetaPackagesParams) UnmarshalJSON(data []byte) error { 648 return apijson.UnmarshalRoot(data, r) 649 } 650 651 // Package configuration type 652 type BetaPackagesParamsType string 653 654 const ( 655 BetaPackagesParamsTypePackages BetaPackagesParamsType = "packages" 656 ) 657 658 // Configuration for self-hosted environments. 659 type BetaSelfHostedConfig struct { 660 // Environment type 661 Type constant.SelfHosted `json:"type" default:"self_hosted"` 662 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 663 JSON struct { 664 Type respjson.Field 665 ExtraFields map[string]respjson.Field 666 raw string 667 } `json:"-"` 668 } 669 670 // Returns the unmodified JSON received from the API 671 func (r BetaSelfHostedConfig) RawJSON() string { return r.JSON.raw } 672 func (r *BetaSelfHostedConfig) UnmarshalJSON(data []byte) error { 673 return apijson.UnmarshalRoot(data, r) 674 } 675 676 func NewBetaSelfHostedConfigParams() BetaSelfHostedConfigParams { 677 return BetaSelfHostedConfigParams{ 678 Type: "self_hosted", 679 } 680 } 681 682 // Request params for `self_hosted` environment configuration. 683 // 684 // This struct has a constant value, construct it with 685 // [NewBetaSelfHostedConfigParams]. 686 type BetaSelfHostedConfigParams struct { 687 // Environment type 688 Type constant.SelfHosted `json:"type" default:"self_hosted"` 689 paramObj 690 } 691 692 func (r BetaSelfHostedConfigParams) MarshalJSON() (data []byte, err error) { 693 type shadow BetaSelfHostedConfigParams 694 return param.MarshalObject(r, (*shadow)(&r)) 695 } 696 func (r *BetaSelfHostedConfigParams) UnmarshalJSON(data []byte) error { 697 return apijson.UnmarshalRoot(data, r) 698 } 699 700 // Unrestricted network access. 701 type BetaUnrestrictedNetwork struct { 702 // Network policy type 703 Type constant.Unrestricted `json:"type" default:"unrestricted"` 704 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 705 JSON struct { 706 Type respjson.Field 707 ExtraFields map[string]respjson.Field 708 raw string 709 } `json:"-"` 710 } 711 712 // Returns the unmodified JSON received from the API 713 func (r BetaUnrestrictedNetwork) RawJSON() string { return r.JSON.raw } 714 func (r *BetaUnrestrictedNetwork) UnmarshalJSON(data []byte) error { 715 return apijson.UnmarshalRoot(data, r) 716 } 717 718 // ToParam converts this BetaUnrestrictedNetwork to a BetaUnrestrictedNetworkParam. 719 // 720 // Warning: the fields of the param type will not be present. ToParam should only 721 // be used at the last possible moment before sending a request. Test for this with 722 // BetaUnrestrictedNetworkParam.Overrides() 723 func (r BetaUnrestrictedNetwork) ToParam() BetaUnrestrictedNetworkParam { 724 return param.Override[BetaUnrestrictedNetworkParam](json.RawMessage(r.RawJSON())) 725 } 726 727 func NewBetaUnrestrictedNetworkParam() BetaUnrestrictedNetworkParam { 728 return BetaUnrestrictedNetworkParam{ 729 Type: "unrestricted", 730 } 731 } 732 733 // Unrestricted network access. 734 // 735 // This struct has a constant value, construct it with 736 // [NewBetaUnrestrictedNetworkParam]. 737 type BetaUnrestrictedNetworkParam struct { 738 // Network policy type 739 Type constant.Unrestricted `json:"type" default:"unrestricted"` 740 paramObj 741 } 742 743 func (r BetaUnrestrictedNetworkParam) MarshalJSON() (data []byte, err error) { 744 type shadow BetaUnrestrictedNetworkParam 745 return param.MarshalObject(r, (*shadow)(&r)) 746 } 747 func (r *BetaUnrestrictedNetworkParam) UnmarshalJSON(data []byte) error { 748 return apijson.UnmarshalRoot(data, r) 749 } 750 751 type BetaEnvironmentNewParams struct { 752 // Human-readable name for the environment 753 Name string `json:"name" api:"required"` 754 // Optional description of the environment 755 Description param.Opt[string] `json:"description,omitzero"` 756 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 757 // Environment configuration 758 Config BetaEnvironmentNewParamsConfigUnion `json:"config,omitzero"` 759 // The visibility scope for this environment. 'organization' makes the environment 760 // visible to all accounts. 'account' restricts visibility to the owning account 761 // only. Only applicable for self-hosted environments. If not specified, defaults 762 // based on organization type. 763 // 764 // Any of "organization", "account". 765 Scope BetaEnvironmentNewParamsScope `json:"scope,omitzero"` 766 // User-provided metadata key-value pairs 767 Metadata map[string]string `json:"metadata,omitzero"` 768 // Optional header to specify the beta version(s) you want to use. 769 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 770 paramObj 771 } 772 773 func (r BetaEnvironmentNewParams) MarshalJSON() (data []byte, err error) { 774 type shadow BetaEnvironmentNewParams 775 return param.MarshalObject(r, (*shadow)(&r)) 776 } 777 func (r *BetaEnvironmentNewParams) UnmarshalJSON(data []byte) error { 778 return apijson.UnmarshalRoot(data, r) 779 } 780 781 // Only one field can be non-zero. 782 // 783 // Use [param.IsOmitted] to confirm if a field is set. 784 type BetaEnvironmentNewParamsConfigUnion struct { 785 OfCloud *BetaCloudConfigParams `json:",omitzero,inline"` 786 OfSelfHosted *BetaSelfHostedConfigParams `json:",omitzero,inline"` 787 paramUnion 788 } 789 790 func (u BetaEnvironmentNewParamsConfigUnion) MarshalJSON() ([]byte, error) { 791 return param.MarshalUnion(u, u.OfCloud, u.OfSelfHosted) 792 } 793 func (u *BetaEnvironmentNewParamsConfigUnion) UnmarshalJSON(data []byte) error { 794 return apijson.UnmarshalRoot(data, u) 795 } 796 797 func (u *BetaEnvironmentNewParamsConfigUnion) asAny() any { 798 if !param.IsOmitted(u.OfCloud) { 799 return u.OfCloud 800 } else if !param.IsOmitted(u.OfSelfHosted) { 801 return u.OfSelfHosted 802 } 803 return nil 804 } 805 806 // Returns a pointer to the underlying variant's property, if present. 807 func (u BetaEnvironmentNewParamsConfigUnion) GetNetworking() *BetaCloudConfigParamsNetworkingUnion { 808 if vt := u.OfCloud; vt != nil { 809 return &vt.Networking 810 } 811 return nil 812 } 813 814 // Returns a pointer to the underlying variant's property, if present. 815 func (u BetaEnvironmentNewParamsConfigUnion) GetPackages() *BetaPackagesParams { 816 if vt := u.OfCloud; vt != nil { 817 return &vt.Packages 818 } 819 return nil 820 } 821 822 // Returns a pointer to the underlying variant's property, if present. 823 func (u BetaEnvironmentNewParamsConfigUnion) GetType() *string { 824 if vt := u.OfCloud; vt != nil { 825 return (*string)(&vt.Type) 826 } else if vt := u.OfSelfHosted; vt != nil { 827 return (*string)(&vt.Type) 828 } 829 return nil 830 } 831 832 func init() { 833 apijson.RegisterUnion[BetaEnvironmentNewParamsConfigUnion]( 834 "type", 835 apijson.Discriminator[BetaCloudConfigParams]("cloud"), 836 apijson.Discriminator[BetaSelfHostedConfigParams]("self_hosted"), 837 ) 838 } 839 840 // The visibility scope for this environment. 'organization' makes the environment 841 // visible to all accounts. 'account' restricts visibility to the owning account 842 // only. Only applicable for self-hosted environments. If not specified, defaults 843 // based on organization type. 844 type BetaEnvironmentNewParamsScope string 845 846 const ( 847 BetaEnvironmentNewParamsScopeOrganization BetaEnvironmentNewParamsScope = "organization" 848 BetaEnvironmentNewParamsScopeAccount BetaEnvironmentNewParamsScope = "account" 849 ) 850 851 type BetaEnvironmentGetParams struct { 852 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 853 // Optional header to specify the beta version(s) you want to use. 854 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 855 paramObj 856 } 857 858 type BetaEnvironmentUpdateParams struct { 859 // Updated description of the environment. Omit to preserve; null clears to null; 860 // an empty string is stored as an empty string. 861 Description param.Opt[string] `json:"description,omitzero"` 862 // Updated name for the environment 863 Name param.Opt[string] `json:"name,omitzero"` 864 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 865 // Updated environment configuration 866 Config BetaEnvironmentUpdateParamsConfigUnion `json:"config,omitzero"` 867 // The visibility scope for this environment. 'organization' makes the environment 868 // visible to all accounts. 'account' restricts visibility to the owning account 869 // only. 870 // 871 // Any of "organization", "account". 872 Scope BetaEnvironmentUpdateParamsScope `json:"scope,omitzero"` 873 // User-provided metadata key-value pairs. Set a value to null or empty string to 874 // delete the key. 875 Metadata map[string]string `json:"metadata,omitzero"` 876 // Optional header to specify the beta version(s) you want to use. 877 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 878 paramObj 879 } 880 881 func (r BetaEnvironmentUpdateParams) MarshalJSON() (data []byte, err error) { 882 type shadow BetaEnvironmentUpdateParams 883 return param.MarshalObject(r, (*shadow)(&r)) 884 } 885 func (r *BetaEnvironmentUpdateParams) UnmarshalJSON(data []byte) error { 886 return apijson.UnmarshalRoot(data, r) 887 } 888 889 // Only one field can be non-zero. 890 // 891 // Use [param.IsOmitted] to confirm if a field is set. 892 type BetaEnvironmentUpdateParamsConfigUnion struct { 893 OfCloud *BetaCloudConfigParams `json:",omitzero,inline"` 894 OfSelfHosted *BetaSelfHostedConfigParams `json:",omitzero,inline"` 895 paramUnion 896 } 897 898 func (u BetaEnvironmentUpdateParamsConfigUnion) MarshalJSON() ([]byte, error) { 899 return param.MarshalUnion(u, u.OfCloud, u.OfSelfHosted) 900 } 901 func (u *BetaEnvironmentUpdateParamsConfigUnion) UnmarshalJSON(data []byte) error { 902 return apijson.UnmarshalRoot(data, u) 903 } 904 905 func (u *BetaEnvironmentUpdateParamsConfigUnion) asAny() any { 906 if !param.IsOmitted(u.OfCloud) { 907 return u.OfCloud 908 } else if !param.IsOmitted(u.OfSelfHosted) { 909 return u.OfSelfHosted 910 } 911 return nil 912 } 913 914 // Returns a pointer to the underlying variant's property, if present. 915 func (u BetaEnvironmentUpdateParamsConfigUnion) GetNetworking() *BetaCloudConfigParamsNetworkingUnion { 916 if vt := u.OfCloud; vt != nil { 917 return &vt.Networking 918 } 919 return nil 920 } 921 922 // Returns a pointer to the underlying variant's property, if present. 923 func (u BetaEnvironmentUpdateParamsConfigUnion) GetPackages() *BetaPackagesParams { 924 if vt := u.OfCloud; vt != nil { 925 return &vt.Packages 926 } 927 return nil 928 } 929 930 // Returns a pointer to the underlying variant's property, if present. 931 func (u BetaEnvironmentUpdateParamsConfigUnion) GetType() *string { 932 if vt := u.OfCloud; vt != nil { 933 return (*string)(&vt.Type) 934 } else if vt := u.OfSelfHosted; vt != nil { 935 return (*string)(&vt.Type) 936 } 937 return nil 938 } 939 940 func init() { 941 apijson.RegisterUnion[BetaEnvironmentUpdateParamsConfigUnion]( 942 "type", 943 apijson.Discriminator[BetaCloudConfigParams]("cloud"), 944 apijson.Discriminator[BetaSelfHostedConfigParams]("self_hosted"), 945 ) 946 } 947 948 // The visibility scope for this environment. 'organization' makes the environment 949 // visible to all accounts. 'account' restricts visibility to the owning account 950 // only. 951 type BetaEnvironmentUpdateParamsScope string 952 953 const ( 954 BetaEnvironmentUpdateParamsScopeOrganization BetaEnvironmentUpdateParamsScope = "organization" 955 BetaEnvironmentUpdateParamsScopeAccount BetaEnvironmentUpdateParamsScope = "account" 956 ) 957 958 type BetaEnvironmentListParams struct { 959 // Opaque cursor from previous response for pagination. Pass the `next_page` value 960 // from the previous response. 961 Page param.Opt[string] `query:"page,omitzero" json:"-"` 962 // Include archived environments in the response 963 IncludeArchived param.Opt[bool] `query:"include_archived,omitzero" json:"-"` 964 // Maximum number of environments to return 965 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 966 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 967 // Optional header to specify the beta version(s) you want to use. 968 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 969 paramObj 970 } 971 972 // URLQuery serializes [BetaEnvironmentListParams]'s query parameters as 973 // `url.Values`. 974 func (r BetaEnvironmentListParams) URLQuery() (v url.Values, err error) { 975 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 976 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 977 NestedFormat: apiquery.NestedQueryFormatBrackets, 978 }) 979 } 980 981 type BetaEnvironmentDeleteParams struct { 982 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 983 // Optional header to specify the beta version(s) you want to use. 984 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 985 paramObj 986 } 987 988 type BetaEnvironmentArchiveParams struct { 989 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 990 // Optional header to specify the beta version(s) you want to use. 991 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 992 paramObj 993 }