github.com/anthropics/anthropic-sdk-go@v1.70.1/betauserprofile.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  	"time"
    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  )
    22  
    23  // BetaUserProfileService contains methods and other services that help with
    24  // 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 [NewBetaUserProfileService] method instead.
    29  type BetaUserProfileService struct {
    30  	Options []option.RequestOption
    31  }
    32  
    33  // NewBetaUserProfileService generates a new service that applies the given options
    34  // to each request. These options are applied after the parent client's options (if
    35  // there is one), and before any request-specific options.
    36  func NewBetaUserProfileService(opts ...option.RequestOption) (r BetaUserProfileService) {
    37  	r = BetaUserProfileService{}
    38  	r.Options = opts
    39  	return
    40  }
    41  
    42  // Create User Profile
    43  func (r *BetaUserProfileService) New(ctx context.Context, params BetaUserProfileNewParams, opts ...option.RequestOption) (res *BetaUserProfile, err error) {
    44  	for _, v := range params.Betas {
    45  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    46  	}
    47  	opts = slices.Concat(r.Options, opts)
    48  	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "user-profiles-2026-08-18")}, opts...)
    49  	path := "v1/user_profiles?beta=true"
    50  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
    51  	return res, err
    52  }
    53  
    54  // Get User Profile
    55  func (r *BetaUserProfileService) Get(ctx context.Context, userProfileID string, query BetaUserProfileGetParams, opts ...option.RequestOption) (res *BetaUserProfile, err error) {
    56  	for _, v := range query.Betas {
    57  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    58  	}
    59  	opts = slices.Concat(r.Options, opts)
    60  	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "user-profiles-2026-08-18")}, opts...)
    61  	if userProfileID == "" {
    62  		err = errors.New("missing required user_profile_id parameter")
    63  		return nil, err
    64  	}
    65  	path := fmt.Sprintf("v1/user_profiles/%s?beta=true", userProfileID)
    66  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
    67  	return res, err
    68  }
    69  
    70  // Update User Profile
    71  func (r *BetaUserProfileService) Update(ctx context.Context, userProfileID string, params BetaUserProfileUpdateParams, opts ...option.RequestOption) (res *BetaUserProfile, err error) {
    72  	for _, v := range params.Betas {
    73  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    74  	}
    75  	opts = slices.Concat(r.Options, opts)
    76  	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "user-profiles-2026-08-18")}, opts...)
    77  	if userProfileID == "" {
    78  		err = errors.New("missing required user_profile_id parameter")
    79  		return nil, err
    80  	}
    81  	path := fmt.Sprintf("v1/user_profiles/%s?beta=true", userProfileID)
    82  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
    83  	return res, err
    84  }
    85  
    86  // List User Profiles
    87  func (r *BetaUserProfileService) List(ctx context.Context, params BetaUserProfileListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaUserProfile], err error) {
    88  	var raw *http.Response
    89  	for _, v := range params.Betas {
    90  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
    91  	}
    92  	opts = slices.Concat(r.Options, opts)
    93  	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "user-profiles-2026-08-18"), option.WithResponseInto(&raw)}, opts...)
    94  	path := "v1/user_profiles?beta=true"
    95  	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
    96  	if err != nil {
    97  		return nil, err
    98  	}
    99  	err = cfg.Execute()
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	res.SetPageConfig(cfg, raw)
   104  	return res, nil
   105  }
   106  
   107  // List User Profiles
   108  func (r *BetaUserProfileService) ListAutoPaging(ctx context.Context, params BetaUserProfileListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaUserProfile] {
   109  	return pagination.NewPageCursorAutoPager(r.List(ctx, params, opts...))
   110  }
   111  
   112  // Create Enrollment URL
   113  func (r *BetaUserProfileService) NewEnrollmentURL(ctx context.Context, userProfileID string, body BetaUserProfileNewEnrollmentURLParams, opts ...option.RequestOption) (res *BetaUserProfileEnrollmentURL, err error) {
   114  	for _, v := range body.Betas {
   115  		opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
   116  	}
   117  	opts = slices.Concat(r.Options, opts)
   118  	opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "user-profiles-2026-08-18")}, opts...)
   119  	if userProfileID == "" {
   120  		err = errors.New("missing required user_profile_id parameter")
   121  		return nil, err
   122  	}
   123  	path := fmt.Sprintf("v1/user_profiles/%s/enrollment_url?beta=true", userProfileID)
   124  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
   125  	return res, err
   126  }
   127  
   128  type BetaUserProfile struct {
   129  	// Unique identifier for this user profile, prefixed `uprof_`.
   130  	ID string `json:"id" api:"required"`
   131  	// A timestamp in RFC 3339 format
   132  	CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
   133  	// Arbitrary key-value metadata. Maximum 16 pairs, keys up to 64 chars, values up
   134  	// to 512 chars.
   135  	Metadata map[string]string `json:"metadata" api:"required"`
   136  	// Trust grants for this profile, keyed by grant name. Key omitted when no grant is
   137  	// active or in flight.
   138  	TrustGrants map[string]BetaUserProfileTrustGrant `json:"trust_grants" api:"required"`
   139  	// Object type. Always `user_profile`.
   140  	//
   141  	// Any of "user_profile".
   142  	Type BetaUserProfileType `json:"type" api:"required"`
   143  	// A timestamp in RFC 3339 format
   144  	UpdatedAt time.Time `json:"updated_at" api:"required" format:"date-time"`
   145  	// How the platform uses the API on behalf of the entity this profile represents.
   146  	// `application`: the platform sells a product that uses the API behind the scenes,
   147  	// and the profile represents an individual end-user of that product.
   148  	// `passthrough`: the platform resells raw inference, and the profile identifies
   149  	// the resold-to company.
   150  	//
   151  	// Any of "application", "passthrough".
   152  	AccessType BetaUserProfileAccessType `json:"access_type"`
   153  	// Platform's own identifier for this user. Not enforced unique.
   154  	ExternalID string `json:"external_id" api:"nullable"`
   155  	// A timestamp in RFC 3339 format
   156  	ExternalUserOnboardedAt time.Time `json:"external_user_onboarded_at" api:"nullable" format:"date-time"`
   157  	// Real-world name of the entity this profile represents (company or individual).
   158  	// For a company the platform resells Claude access to (`access_type`
   159  	// `passthrough`) this is that company's name.
   160  	Name string `json:"name" api:"nullable"`
   161  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   162  	JSON struct {
   163  		ID                      respjson.Field
   164  		CreatedAt               respjson.Field
   165  		Metadata                respjson.Field
   166  		TrustGrants             respjson.Field
   167  		Type                    respjson.Field
   168  		UpdatedAt               respjson.Field
   169  		AccessType              respjson.Field
   170  		ExternalID              respjson.Field
   171  		ExternalUserOnboardedAt respjson.Field
   172  		Name                    respjson.Field
   173  		ExtraFields             map[string]respjson.Field
   174  		raw                     string
   175  	} `json:"-"`
   176  }
   177  
   178  // Returns the unmodified JSON received from the API
   179  func (r BetaUserProfile) RawJSON() string { return r.JSON.raw }
   180  func (r *BetaUserProfile) UnmarshalJSON(data []byte) error {
   181  	return apijson.UnmarshalRoot(data, r)
   182  }
   183  
   184  // Object type. Always `user_profile`.
   185  type BetaUserProfileType string
   186  
   187  const (
   188  	BetaUserProfileTypeUserProfile BetaUserProfileType = "user_profile"
   189  )
   190  
   191  // How the platform uses the API on behalf of the entity this profile represents.
   192  // `application`: the platform sells a product that uses the API behind the scenes,
   193  // and the profile represents an individual end-user of that product.
   194  // `passthrough`: the platform resells raw inference, and the profile identifies
   195  // the resold-to company.
   196  type BetaUserProfileAccessType string
   197  
   198  const (
   199  	BetaUserProfileAccessTypeApplication BetaUserProfileAccessType = "application"
   200  	BetaUserProfileAccessTypePassthrough BetaUserProfileAccessType = "passthrough"
   201  )
   202  
   203  type BetaUserProfileEnrollmentURL struct {
   204  	// A timestamp in RFC 3339 format
   205  	ExpiresAt time.Time `json:"expires_at" api:"required" format:"date-time"`
   206  	// Object type. Always `enrollment_url`.
   207  	//
   208  	// Any of "enrollment_url".
   209  	Type BetaUserProfileEnrollmentURLType `json:"type" api:"required"`
   210  	// Enrollment URL to send to the end user. Valid until `expires_at`.
   211  	URL string `json:"url" api:"required"`
   212  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   213  	JSON struct {
   214  		ExpiresAt   respjson.Field
   215  		Type        respjson.Field
   216  		URL         respjson.Field
   217  		ExtraFields map[string]respjson.Field
   218  		raw         string
   219  	} `json:"-"`
   220  }
   221  
   222  // Returns the unmodified JSON received from the API
   223  func (r BetaUserProfileEnrollmentURL) RawJSON() string { return r.JSON.raw }
   224  func (r *BetaUserProfileEnrollmentURL) UnmarshalJSON(data []byte) error {
   225  	return apijson.UnmarshalRoot(data, r)
   226  }
   227  
   228  // Object type. Always `enrollment_url`.
   229  type BetaUserProfileEnrollmentURLType string
   230  
   231  const (
   232  	BetaUserProfileEnrollmentURLTypeEnrollmentURL BetaUserProfileEnrollmentURLType = "enrollment_url"
   233  )
   234  
   235  type BetaUserProfileTrustGrant struct {
   236  	// Status of the trust grant.
   237  	//
   238  	// Any of "active", "pending", "rejected".
   239  	Status BetaUserProfileTrustGrantStatus `json:"status" api:"required"`
   240  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   241  	JSON struct {
   242  		Status      respjson.Field
   243  		ExtraFields map[string]respjson.Field
   244  		raw         string
   245  	} `json:"-"`
   246  }
   247  
   248  // Returns the unmodified JSON received from the API
   249  func (r BetaUserProfileTrustGrant) RawJSON() string { return r.JSON.raw }
   250  func (r *BetaUserProfileTrustGrant) UnmarshalJSON(data []byte) error {
   251  	return apijson.UnmarshalRoot(data, r)
   252  }
   253  
   254  // Status of the trust grant.
   255  type BetaUserProfileTrustGrantStatus string
   256  
   257  const (
   258  	BetaUserProfileTrustGrantStatusActive   BetaUserProfileTrustGrantStatus = "active"
   259  	BetaUserProfileTrustGrantStatusPending  BetaUserProfileTrustGrantStatus = "pending"
   260  	BetaUserProfileTrustGrantStatusRejected BetaUserProfileTrustGrantStatus = "rejected"
   261  )
   262  
   263  type BetaUserProfileNewParams struct {
   264  	// Platform's own identifier for this user. Not enforced unique. Maximum 255
   265  	// characters.
   266  	ExternalID param.Opt[string] `json:"external_id,omitzero"`
   267  	// Optional for all profiles. Real-world name of the entity this profile represents
   268  	// (company or individual); for a company the platform resells Claude access to
   269  	// (`access_type` `passthrough`), that company's name where known. Maximum 255
   270  	// characters.
   271  	Name param.Opt[string] `json:"name,omitzero"`
   272  	// A timestamp in RFC 3339 format
   273  	ExternalUserOnboardedAt param.Opt[time.Time] `json:"external_user_onboarded_at,omitzero" format:"date-time"`
   274  	// How the platform uses the API on behalf of the entity this profile represents.
   275  	// `application`: the platform sells a product that uses the API behind the scenes,
   276  	// and the profile represents an individual end-user of that product.
   277  	// `passthrough`: the platform resells raw inference, and the profile identifies
   278  	// the resold-to company.
   279  	//
   280  	// Any of "application", "passthrough".
   281  	AccessType BetaUserProfileNewParamsAccessType `json:"access_type,omitzero"`
   282  	// Free-form key-value data to attach to this user profile. Maximum 16 keys, with
   283  	// keys up to 64 characters and values up to 512 characters. Values must be
   284  	// non-empty strings.
   285  	Metadata map[string]string `json:"metadata,omitzero"`
   286  	// Optional header to specify the beta version(s) you want to use.
   287  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   288  	paramObj
   289  }
   290  
   291  func (r BetaUserProfileNewParams) MarshalJSON() (data []byte, err error) {
   292  	type shadow BetaUserProfileNewParams
   293  	return param.MarshalObject(r, (*shadow)(&r))
   294  }
   295  func (r *BetaUserProfileNewParams) UnmarshalJSON(data []byte) error {
   296  	return apijson.UnmarshalRoot(data, r)
   297  }
   298  
   299  // How the platform uses the API on behalf of the entity this profile represents.
   300  // `application`: the platform sells a product that uses the API behind the scenes,
   301  // and the profile represents an individual end-user of that product.
   302  // `passthrough`: the platform resells raw inference, and the profile identifies
   303  // the resold-to company.
   304  type BetaUserProfileNewParamsAccessType string
   305  
   306  const (
   307  	BetaUserProfileNewParamsAccessTypeApplication BetaUserProfileNewParamsAccessType = "application"
   308  	BetaUserProfileNewParamsAccessTypePassthrough BetaUserProfileNewParamsAccessType = "passthrough"
   309  )
   310  
   311  type BetaUserProfileGetParams struct {
   312  	// Optional header to specify the beta version(s) you want to use.
   313  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   314  	paramObj
   315  }
   316  
   317  type BetaUserProfileUpdateParams struct {
   318  	// If present, replaces the stored external_id. Omit to leave unchanged. Maximum
   319  	// 255 characters.
   320  	ExternalID param.Opt[string] `json:"external_id,omitzero"`
   321  	// If present, replaces the stored name. Omit to leave unchanged. Maximum 255
   322  	// characters.
   323  	Name param.Opt[string] `json:"name,omitzero"`
   324  	// A timestamp in RFC 3339 format
   325  	ExternalUserOnboardedAt param.Opt[time.Time] `json:"external_user_onboarded_at,omitzero" format:"date-time"`
   326  	// How the platform uses the API on behalf of the entity this profile represents.
   327  	// `application`: the platform sells a product that uses the API behind the scenes,
   328  	// and the profile represents an individual end-user of that product.
   329  	// `passthrough`: the platform resells raw inference, and the profile identifies
   330  	// the resold-to company.
   331  	//
   332  	// Any of "application", "passthrough".
   333  	AccessType BetaUserProfileUpdateParamsAccessType `json:"access_type,omitzero"`
   334  	// Key-value pairs to merge into the stored metadata. Keys provided overwrite
   335  	// existing values. To remove a key, set its value to an empty string. Keys not
   336  	// provided are left unchanged. Maximum 16 keys, with keys up to 64 characters and
   337  	// values up to 512 characters.
   338  	Metadata map[string]string `json:"metadata,omitzero"`
   339  	// Optional header to specify the beta version(s) you want to use.
   340  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   341  	paramObj
   342  }
   343  
   344  func (r BetaUserProfileUpdateParams) MarshalJSON() (data []byte, err error) {
   345  	type shadow BetaUserProfileUpdateParams
   346  	return param.MarshalObject(r, (*shadow)(&r))
   347  }
   348  func (r *BetaUserProfileUpdateParams) UnmarshalJSON(data []byte) error {
   349  	return apijson.UnmarshalRoot(data, r)
   350  }
   351  
   352  // How the platform uses the API on behalf of the entity this profile represents.
   353  // `application`: the platform sells a product that uses the API behind the scenes,
   354  // and the profile represents an individual end-user of that product.
   355  // `passthrough`: the platform resells raw inference, and the profile identifies
   356  // the resold-to company.
   357  type BetaUserProfileUpdateParamsAccessType string
   358  
   359  const (
   360  	BetaUserProfileUpdateParamsAccessTypeApplication BetaUserProfileUpdateParamsAccessType = "application"
   361  	BetaUserProfileUpdateParamsAccessTypePassthrough BetaUserProfileUpdateParamsAccessType = "passthrough"
   362  )
   363  
   364  type BetaUserProfileListParams struct {
   365  	// Query parameter for limit
   366  	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
   367  	// Query parameter for page
   368  	Page param.Opt[string] `query:"page,omitzero" json:"-"`
   369  	// Query parameter for order
   370  	//
   371  	// Any of "asc", "desc".
   372  	Order BetaUserProfileListParamsOrder `query:"order,omitzero" json:"-"`
   373  	// Query parameter for order_by
   374  	//
   375  	// Any of "created_at", "name".
   376  	OrderBy BetaUserProfileListParamsOrderBy `query:"order_by,omitzero" json:"-"`
   377  	// Optional header to specify the beta version(s) you want to use.
   378  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   379  	paramObj
   380  }
   381  
   382  // URLQuery serializes [BetaUserProfileListParams]'s query parameters as
   383  // `url.Values`.
   384  func (r BetaUserProfileListParams) URLQuery() (v url.Values, err error) {
   385  	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
   386  		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
   387  		NestedFormat: apiquery.NestedQueryFormatBrackets,
   388  	})
   389  }
   390  
   391  // Query parameter for order
   392  type BetaUserProfileListParamsOrder string
   393  
   394  const (
   395  	BetaUserProfileListParamsOrderAsc  BetaUserProfileListParamsOrder = "asc"
   396  	BetaUserProfileListParamsOrderDesc BetaUserProfileListParamsOrder = "desc"
   397  )
   398  
   399  // Query parameter for order_by
   400  type BetaUserProfileListParamsOrderBy string
   401  
   402  const (
   403  	BetaUserProfileListParamsOrderByCreatedAt BetaUserProfileListParamsOrderBy = "created_at"
   404  	BetaUserProfileListParamsOrderByName      BetaUserProfileListParamsOrderBy = "name"
   405  )
   406  
   407  type BetaUserProfileNewEnrollmentURLParams struct {
   408  	// Optional header to specify the beta version(s) you want to use.
   409  	Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
   410  	paramObj
   411  }