github.com/anthropics/anthropic-sdk-go@v1.70.1/betamodel.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 "github.com/anthropics/anthropic-sdk-go/shared/constant" 22 ) 23 24 // BetaModelService contains methods and other services that help with interacting 25 // 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 [NewBetaModelService] method instead. 30 type BetaModelService struct { 31 Options []option.RequestOption 32 } 33 34 // NewBetaModelService generates a new service that applies the given options to 35 // each request. These options are applied after the parent client's options (if 36 // there is one), and before any request-specific options. 37 func NewBetaModelService(opts ...option.RequestOption) (r BetaModelService) { 38 r = BetaModelService{} 39 r.Options = opts 40 return 41 } 42 43 // Get a specific model. 44 // 45 // The Models API response can be used to determine information about a specific 46 // model or resolve a model alias to a model ID. 47 func (r *BetaModelService) Get(ctx context.Context, modelID string, query BetaModelGetParams, opts ...option.RequestOption) (res *BetaModelInfo, err error) { 48 for _, v := range query.Betas { 49 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 50 } 51 if !param.IsOmitted(query.WorkspaceID) { 52 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", query.WorkspaceID.Value))) 53 } 54 opts = slices.Concat(r.Options, opts) 55 if modelID == "" { 56 err = errors.New("missing required model_id parameter") 57 return nil, err 58 } 59 path := fmt.Sprintf("v1/models/%s?beta=true", modelID) 60 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...) 61 return res, err 62 } 63 64 // List available models. 65 // 66 // The Models API response can be used to determine which models are available for 67 // use in the API. More recently released models are listed first. 68 func (r *BetaModelService) List(ctx context.Context, params BetaModelListParams, opts ...option.RequestOption) (res *pagination.Page[BetaModelInfo], err error) { 69 var raw *http.Response 70 for _, v := range params.Betas { 71 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v))) 72 } 73 if !param.IsOmitted(params.WorkspaceID) { 74 opts = append(opts, option.WithHeader("anthropic-workspace-id", fmt.Sprintf("%v", params.WorkspaceID.Value))) 75 } 76 opts = slices.Concat(r.Options, opts) 77 opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) 78 path := "v1/models?beta=true" 79 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) 80 if err != nil { 81 return nil, err 82 } 83 err = cfg.Execute() 84 if err != nil { 85 return nil, err 86 } 87 res.SetPageConfig(cfg, raw) 88 return res, nil 89 } 90 91 // List available models. 92 // 93 // The Models API response can be used to determine which models are available for 94 // use in the API. More recently released models are listed first. 95 func (r *BetaModelService) ListAutoPaging(ctx context.Context, params BetaModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaModelInfo] { 96 return pagination.NewPageAutoPager(r.List(ctx, params, opts...)) 97 } 98 99 // Indicates whether a capability is supported. 100 type BetaCapabilitySupport struct { 101 // Whether this capability is supported by the model. 102 Supported bool `json:"supported" api:"required"` 103 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 104 JSON struct { 105 Supported respjson.Field 106 ExtraFields map[string]respjson.Field 107 raw string 108 } `json:"-"` 109 } 110 111 // Returns the unmodified JSON received from the API 112 func (r BetaCapabilitySupport) RawJSON() string { return r.JSON.raw } 113 func (r *BetaCapabilitySupport) UnmarshalJSON(data []byte) error { 114 return apijson.UnmarshalRoot(data, r) 115 } 116 117 // Context management capability details. 118 type BetaContextManagementCapability struct { 119 // Indicates whether a capability is supported. 120 ClearThinking20251015 BetaCapabilitySupport `json:"clear_thinking_20251015" api:"required"` 121 // Indicates whether a capability is supported. 122 ClearToolUses20250919 BetaCapabilitySupport `json:"clear_tool_uses_20250919" api:"required"` 123 // Indicates whether a capability is supported. 124 Compact20260112 BetaCapabilitySupport `json:"compact_20260112" api:"required"` 125 // Whether this capability is supported by the model. 126 Supported bool `json:"supported" api:"required"` 127 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 128 JSON struct { 129 ClearThinking20251015 respjson.Field 130 ClearToolUses20250919 respjson.Field 131 Compact20260112 respjson.Field 132 Supported respjson.Field 133 ExtraFields map[string]respjson.Field 134 raw string 135 } `json:"-"` 136 } 137 138 // Returns the unmodified JSON received from the API 139 func (r BetaContextManagementCapability) RawJSON() string { return r.JSON.raw } 140 func (r *BetaContextManagementCapability) UnmarshalJSON(data []byte) error { 141 return apijson.UnmarshalRoot(data, r) 142 } 143 144 // Effort (reasoning_effort) capability details. 145 type BetaEffortCapability struct { 146 // Whether the model supports high effort level. 147 High BetaCapabilitySupport `json:"high" api:"required"` 148 // Whether the model supports low effort level. 149 Low BetaCapabilitySupport `json:"low" api:"required"` 150 // Whether the model supports max effort level. 151 Max BetaCapabilitySupport `json:"max" api:"required"` 152 // Whether the model supports medium effort level. 153 Medium BetaCapabilitySupport `json:"medium" api:"required"` 154 // Whether this capability is supported by the model. 155 Supported bool `json:"supported" api:"required"` 156 // Indicates whether a capability is supported. 157 Xhigh BetaCapabilitySupport `json:"xhigh" api:"required"` 158 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 159 JSON struct { 160 High respjson.Field 161 Low respjson.Field 162 Max respjson.Field 163 Medium respjson.Field 164 Supported respjson.Field 165 Xhigh respjson.Field 166 ExtraFields map[string]respjson.Field 167 raw string 168 } `json:"-"` 169 } 170 171 // Returns the unmodified JSON received from the API 172 func (r BetaEffortCapability) RawJSON() string { return r.JSON.raw } 173 func (r *BetaEffortCapability) UnmarshalJSON(data []byte) error { 174 return apijson.UnmarshalRoot(data, r) 175 } 176 177 // Model capability information. 178 type BetaModelCapabilities struct { 179 // Whether the model supports the Batch API. 180 Batch BetaCapabilitySupport `json:"batch" api:"required"` 181 // Whether the model supports citation generation. 182 Citations BetaCapabilitySupport `json:"citations" api:"required"` 183 // Whether the model supports code execution tools. 184 CodeExecution BetaCapabilitySupport `json:"code_execution" api:"required"` 185 // Context management support and available strategies. 186 ContextManagement BetaContextManagementCapability `json:"context_management" api:"required"` 187 // Effort (reasoning_effort) support and available levels. 188 Effort BetaEffortCapability `json:"effort" api:"required"` 189 // Whether the model accepts image content blocks. 190 ImageInput BetaCapabilitySupport `json:"image_input" api:"required"` 191 // Whether the model accepts PDF content blocks. 192 PDFInput BetaCapabilitySupport `json:"pdf_input" api:"required"` 193 // Whether the model supports structured output / JSON mode / strict tool schemas. 194 StructuredOutputs BetaCapabilitySupport `json:"structured_outputs" api:"required"` 195 // Thinking capability and supported type configurations. 196 Thinking BetaThinkingCapability `json:"thinking" api:"required"` 197 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 198 JSON struct { 199 Batch respjson.Field 200 Citations respjson.Field 201 CodeExecution respjson.Field 202 ContextManagement respjson.Field 203 Effort respjson.Field 204 ImageInput respjson.Field 205 PDFInput respjson.Field 206 StructuredOutputs respjson.Field 207 Thinking respjson.Field 208 ExtraFields map[string]respjson.Field 209 raw string 210 } `json:"-"` 211 } 212 213 // Returns the unmodified JSON received from the API 214 func (r BetaModelCapabilities) RawJSON() string { return r.JSON.raw } 215 func (r *BetaModelCapabilities) UnmarshalJSON(data []byte) error { 216 return apijson.UnmarshalRoot(data, r) 217 } 218 219 type BetaModelInfo struct { 220 // Unique model identifier. 221 ID string `json:"id" api:"required"` 222 // Model IDs this model accepts as `fallbacks[i].model` on the Messages API. An 223 // empty list means the `fallbacks` parameter is not supported for this model as 224 // primary. 225 AllowedFallbackModels []string `json:"allowed_fallback_models" api:"required"` 226 // Model capability information. 227 Capabilities BetaModelCapabilities `json:"capabilities" api:"required"` 228 // RFC 3339 datetime string representing the time at which the model was released. 229 // May be set to an epoch value if the release date is unknown. 230 CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"` 231 // A human-readable name for the model. 232 DisplayName string `json:"display_name" api:"required"` 233 // Maximum input context window size in tokens for this model. 234 MaxInputTokens int64 `json:"max_input_tokens" api:"required"` 235 // Maximum value for the `max_tokens` parameter when using this model. 236 MaxTokens int64 `json:"max_tokens" api:"required"` 237 // Object type. 238 // 239 // For Models, this is always `"model"`. 240 Type constant.Model `json:"type" default:"model"` 241 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 242 JSON struct { 243 ID respjson.Field 244 AllowedFallbackModels respjson.Field 245 Capabilities respjson.Field 246 CreatedAt respjson.Field 247 DisplayName respjson.Field 248 MaxInputTokens respjson.Field 249 MaxTokens respjson.Field 250 Type respjson.Field 251 ExtraFields map[string]respjson.Field 252 raw string 253 } `json:"-"` 254 } 255 256 // Returns the unmodified JSON received from the API 257 func (r BetaModelInfo) RawJSON() string { return r.JSON.raw } 258 func (r *BetaModelInfo) UnmarshalJSON(data []byte) error { 259 return apijson.UnmarshalRoot(data, r) 260 } 261 262 // Thinking capability details. 263 type BetaThinkingCapability struct { 264 // Whether this capability is supported by the model. 265 Supported bool `json:"supported" api:"required"` 266 // Supported thinking type configurations. 267 Types BetaThinkingTypes `json:"types" api:"required"` 268 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 269 JSON struct { 270 Supported respjson.Field 271 Types respjson.Field 272 ExtraFields map[string]respjson.Field 273 raw string 274 } `json:"-"` 275 } 276 277 // Returns the unmodified JSON received from the API 278 func (r BetaThinkingCapability) RawJSON() string { return r.JSON.raw } 279 func (r *BetaThinkingCapability) UnmarshalJSON(data []byte) error { 280 return apijson.UnmarshalRoot(data, r) 281 } 282 283 // Supported thinking type configurations. 284 type BetaThinkingTypes struct { 285 // Whether the model supports thinking with type 'adaptive' (auto). 286 Adaptive BetaCapabilitySupport `json:"adaptive" api:"required"` 287 // Whether the model supports thinking with type 'enabled'. 288 Enabled BetaCapabilitySupport `json:"enabled" api:"required"` 289 // JSON contains metadata for fields, check presence with [respjson.Field.Valid]. 290 JSON struct { 291 Adaptive respjson.Field 292 Enabled respjson.Field 293 ExtraFields map[string]respjson.Field 294 raw string 295 } `json:"-"` 296 } 297 298 // Returns the unmodified JSON received from the API 299 func (r BetaThinkingTypes) RawJSON() string { return r.JSON.raw } 300 func (r *BetaThinkingTypes) UnmarshalJSON(data []byte) error { 301 return apijson.UnmarshalRoot(data, r) 302 } 303 304 type BetaModelGetParams struct { 305 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 306 // Optional header to specify the beta version(s) you want to use. 307 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 308 paramObj 309 } 310 311 type BetaModelListParams struct { 312 // ID of the object to use as a cursor for pagination. When provided, returns the 313 // page of results immediately after this object. 314 AfterID param.Opt[string] `query:"after_id,omitzero" json:"-"` 315 // ID of the object to use as a cursor for pagination. When provided, returns the 316 // page of results immediately before this object. 317 BeforeID param.Opt[string] `query:"before_id,omitzero" json:"-"` 318 // Number of items to return per page. 319 // 320 // Defaults to `20`. Ranges from `1` to `1000`. 321 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"` 322 WorkspaceID param.Opt[string] `header:"anthropic-workspace-id,omitzero" json:"-"` 323 // Optional header to specify the beta version(s) you want to use. 324 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"` 325 paramObj 326 } 327 328 // URLQuery serializes [BetaModelListParams]'s query parameters as `url.Values`. 329 func (r BetaModelListParams) URLQuery() (v url.Values, err error) { 330 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ 331 ArrayFormat: apiquery.ArrayQueryFormatBrackets, 332 NestedFormat: apiquery.NestedQueryFormatBrackets, 333 }) 334 }