github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationworkspaceratelimit.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 "errors" 8 "fmt" 9 "net/http" 10 "net/url" 11 "slices" 12 13 "github.com/anthropics/anthropic-sdk-go/internal/apijson" 14 "github.com/anthropics/anthropic-sdk-go/internal/apiquery" 15 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig" 16 "github.com/anthropics/anthropic-sdk-go/option" 17 "github.com/anthropics/anthropic-sdk-go/packages/pagination" 18 "github.com/anthropics/anthropic-sdk-go/packages/param" 19 "github.com/anthropics/anthropic-sdk-go/packages/respjson" 20 "github.com/anthropics/anthropic-sdk-go/shared/constant" 21 ) 22 23 // BetaOrganizationWorkspaceRateLimitService contains methods and other services 24 // that help with interacting with the anthropic API. 25 // 26 // Note, unlike clients, this service does not read variables from the environment 27 // automatically. You should not instantiate this service directly, and instead use 28 // the [NewBetaOrganizationWorkspaceRateLimitService] method instead. 29 type BetaOrganizationWorkspaceRateLimitService struct { 30 Options []option.RequestOption 31 } 32 33 // NewBetaOrganizationWorkspaceRateLimitService generates a new service that 34 // applies the given options to each request. These options are applied after the 35 // parent client's options (if there is one), and before any request-specific 36 // options. 37 func NewBetaOrganizationWorkspaceRateLimitService(opts ...option.RequestOption) (r BetaOrganizationWorkspaceRateLimitService) { 38 r = BetaOrganizationWorkspaceRateLimitService{} 39 r.Options = opts 40 return 41 } 42 43 // List rate-limit overrides configured for a workspace. 44 // 45 // Returns only the groups and limiter types that have a workspace-level override. 46 // Groups without overrides inherit the organization limits and are not listed; use 47 // `GET /v1/organizations/rate_limits` to see those. 48 // 49 // When `limit` is omitted, every matching entry is returned in a single page; when 50 // `limit` truncates the result, follow `next_page` to fetch the remaining entries. 51 func (r *BetaOrganizationWorkspaceRateLimitService) List(ctx context.Context, workspaceID string, query BetaOrganizationWorkspaceRateLimitListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaWorkspaceRateLimit], err error) { 52 var raw *http.Response 53 opts = slices.Concat(r.Options, opts) 54 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) 55 if workspaceID == "" { 56 err = errors.New("missing required workspace_id parameter") 57 return nil, err 58 } 59 path := fmt.Sprintf("v1/organizations/workspaces/%s/rate_limits?beta=true", workspaceID) 60 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) 61 if err != nil { 62 return nil, err 63 } 64 err = cfg.Execute() 65 if err != nil { 66 return nil, err 67 } 68 res.SetPageConfig(cfg, raw) 69 return res, nil 70 } 71 72 // List rate-limit overrides configured for a workspace. 73 // 74 // Returns only the groups and limiter types that have a workspace-level override. 75 // Groups without overrides inherit the organization limits and are not listed; use 76 // `GET /v1/organizations/rate_limits` to see those. 77 // 78 // When `limit` is omitted, every matching entry is returned in a single page; when 79 // `limit` truncates the result, follow `next_page` to fetch the remaining entries. 80 func (r *BetaOrganizationWorkspaceRateLimitService) ListAutoPaging(ctx context.Context, workspaceID string, query BetaOrganizationWorkspaceRateLimitListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaWorkspaceRateLimit] { 81 return pagination.NewPageCursorAutoPager(r.List(ctx, workspaceID, query, opts...)) 82 } 83 84 type BetaWorkspaceRateLimit struct { 85 // The kind of rate-limit group this entry represents. `model_group` entries apply 86 // to a family of models (listed in `models`); other values apply to an API-surface 87 // category and have `models` set to `null`. 88 // 89 // Any of "batch", "files", "model_group", "skills", "token_count", "web_search". 90 GroupType BetaWorkspaceRateLimitGroupType `json:"group_type" api:"required"` 91 // The limiter values overridden for this group in this workspace. Limiter types 92 // without a workspace override are omitted and inherit the organization value. 93 Limits []BetaWorkspaceRateLimitValue `json:"limits" api:"required"` 94 // Model names this entry's limits apply to, including aliases. `null` when 95 // `group_type` is not `"model_group"`. 96 Models []string `json:"models" api:"required"` 97 // The `id` of the RateLimit group this override applies to. 98 RateLimitID string `json:"rate_limit_id" api:"required"` 99 // Object type. Always `workspace_rate_limit` for workspace rate-limit entries. 100 Type constant.WorkspaceRateLimit `json:"type" default:"workspace_rate_limit"` 101 // ID of the Workspace this override applies to. 102 WorkspaceID string `json:"workspace_id" api:"required"` 103 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 104 JSON struct { 105 GroupType respjson.Field 106 Limits respjson.Field 107 Models respjson.Field 108 RateLimitID respjson.Field 109 Type respjson.Field 110 WorkspaceID respjson.Field 111 ExtraFields map[string]respjson.Field 112 raw string 113 } `json:"-"` 114 } 115 116 // Returns the unmodified JSON received from the API 117 func (r BetaWorkspaceRateLimit) RawJSON() string { return r.JSON.raw } 118 func (r *BetaWorkspaceRateLimit) UnmarshalJSON(data []byte) error { 119 return apijson.UnmarshalRoot(data, r) 120 } 121 122 // The kind of rate-limit group this entry represents. `model_group` entries apply 123 // to a family of models (listed in `models`); other values apply to an API-surface 124 // category and have `models` set to `null`. 125 type BetaWorkspaceRateLimitGroupType string 126 127 const ( 128 BetaWorkspaceRateLimitGroupTypeBatch BetaWorkspaceRateLimitGroupType = "batch" 129 BetaWorkspaceRateLimitGroupTypeFiles BetaWorkspaceRateLimitGroupType = "files" 130 BetaWorkspaceRateLimitGroupTypeModelGroup BetaWorkspaceRateLimitGroupType = "model_group" 131 BetaWorkspaceRateLimitGroupTypeSkills BetaWorkspaceRateLimitGroupType = "skills" 132 BetaWorkspaceRateLimitGroupTypeTokenCount BetaWorkspaceRateLimitGroupType = "token_count" 133 BetaWorkspaceRateLimitGroupTypeWebSearch BetaWorkspaceRateLimitGroupType = "web_search" 134 ) 135 136 type BetaWorkspaceRateLimitValue struct { 137 // The organization-level value for the same limiter type, for reference. `null` 138 // when the organization has no limit configured for this limiter type. 139 OrgLimit int64 `json:"org_limit" api:"required"` 140 // The limiter type (for example, `requests_per_minute` or 141 // `input_tokens_per_minute`). 142 Type string `json:"type" api:"required"` 143 // The workspace-level override value for this limiter type. 144 Value int64 `json:"value" api:"required"` 145 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 146 JSON struct { 147 OrgLimit respjson.Field 148 Type respjson.Field 149 Value respjson.Field 150 ExtraFields map[string]respjson.Field 151 raw string 152 } `json:"-"` 153 } 154 155 // Returns the unmodified JSON received from the API 156 func (r BetaWorkspaceRateLimitValue) RawJSON() string { return r.JSON.raw } 157 func (r *BetaWorkspaceRateLimitValue) UnmarshalJSON(data []byte) error { 158 return apijson.UnmarshalRoot(data, r) 159 } 160 161 type BetaOrganizationWorkspaceRateLimitListParams struct { 162 // Maximum number of items to return per page. Ranges from `1` to `1000`. 163 // 164 // When omitted, every remaining entry is returned in a single page and `next_page` 165 // is `null`. 166 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 167 // Opaque cursor from a previous response's `next_page`. 168 Page param.Opt[string] `query:"page,omitzero" json:"-"` 169 // Filter by group type. 170 // 171 // Any of "batch", "files", "model_group", "skills", "token_count", "web_search". 172 GroupType BetaOrganizationWorkspaceRateLimitListParamsGroupType `query:"group_type,omitzero" json:"-"` 173 paramObj 174 } 175 176 // URLQuery serializes [BetaOrganizationWorkspaceRateLimitListParams]'s query 177 // parameters as `url.Values`. 178 func (r BetaOrganizationWorkspaceRateLimitListParams) URLQuery() (v url.Values, err error) { 179 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 180 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 181 NestedFormat: apiquery.NestedQueryFormatBrackets, 182 }) 183 } 184 185 // Filter by group type. 186 type BetaOrganizationWorkspaceRateLimitListParamsGroupType string 187 188 const ( 189 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeBatch BetaOrganizationWorkspaceRateLimitListParamsGroupType = "batch" 190 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeFiles BetaOrganizationWorkspaceRateLimitListParamsGroupType = "files" 191 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeModelGroup BetaOrganizationWorkspaceRateLimitListParamsGroupType = "model_group" 192 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeSkills BetaOrganizationWorkspaceRateLimitListParamsGroupType = "skills" 193 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeTokenCount BetaOrganizationWorkspaceRateLimitListParamsGroupType = "token_count" 194 BetaOrganizationWorkspaceRateLimitListParamsGroupTypeWebSearch BetaOrganizationWorkspaceRateLimitListParamsGroupType = "web_search" 195 )