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