1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package anthropic
4
5import (
6 "context"
7 "encoding/json"
8 "fmt"
9 "net/http"
10 "time"
11
12 "github.com/anthropics/anthropic-sdk-go/internal/apijson"
13 "github.com/anthropics/anthropic-sdk-go/internal/paramutil"
14 "github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
15 "github.com/anthropics/anthropic-sdk-go/option"
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/packages/ssestream"
19 "github.com/anthropics/anthropic-sdk-go/shared/constant"
20)
21
22// BetaMessageService contains methods and other services that help with
23// interacting with the anthropic API.
24//
25// Note, unlike clients, this service does not read variables from the environment
26// automatically. You should not instantiate this service directly, and instead use
27// the [NewBetaMessageService] method instead.
28type BetaMessageService struct {
29 Options []option.RequestOption
30 Batches BetaMessageBatchService
31}
32
33// NewBetaMessageService generates a new service that applies the given options to
34// each request. These options are applied after the parent client's options (if
35// there is one), and before any request-specific options.
36func NewBetaMessageService(opts ...option.RequestOption) (r BetaMessageService) {
37 r = BetaMessageService{}
38 r.Options = opts
39 r.Batches = NewBetaMessageBatchService(opts...)
40 return
41}
42
43// Send a structured list of input messages with text and/or image content, and the
44// model will generate the next message in the conversation.
45//
46// The Messages API can be used for either single queries or stateless multi-turn
47// conversations.
48//
49// Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
50//
51// Note: If you choose to set a timeout for this request, we recommend 10 minutes.
52func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error) {
53 for _, v := range params.Betas {
54 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
55 }
56 opts = append(r.Options[:], opts...)
57
58 // For non-streaming requests, calculate the appropriate timeout based on maxTokens
59 // and check against model-specific limits
60 timeout, timeoutErr := CalculateNonStreamingTimeout(int(params.MaxTokens), params.Model, opts)
61 if timeoutErr != nil {
62 return nil, timeoutErr
63 }
64 opts = append(opts, option.WithRequestTimeout(timeout))
65
66 path := "v1/messages?beta=true"
67 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
68 return
69}
70
71// Send a structured list of input messages with text and/or image content, and the
72// model will generate the next message in the conversation.
73//
74// The Messages API can be used for either single queries or stateless multi-turn
75// conversations.
76//
77// Learn more about the Messages API in our [user guide](/en/docs/initial-setup)
78//
79// Note: If you choose to set a timeout for this request, we recommend 10 minutes.
80func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[BetaRawMessageStreamEventUnion]) {
81 var (
82 raw *http.Response
83 err error
84 )
85 for _, v := range params.Betas {
86 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
87 }
88 opts = append(r.Options[:], opts...)
89 opts = append([]option.RequestOption{option.WithJSONSet("stream", true)}, opts...)
90 path := "v1/messages?beta=true"
91 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &raw, opts...)
92 return ssestream.NewStream[BetaRawMessageStreamEventUnion](ssestream.NewDecoder(raw), err)
93}
94
95// Count the number of tokens in a Message.
96//
97// The Token Count API can be used to count the number of tokens in a Message,
98// including tools, images, and documents, without creating it.
99//
100// Learn more about token counting in our
101// [user guide](/en/docs/build-with-claude/token-counting)
102func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error) {
103 for _, v := range params.Betas {
104 opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
105 }
106 opts = append(r.Options[:], opts...)
107 path := "v1/messages/count_tokens?beta=true"
108 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
109 return
110}
111
112// The properties Data, MediaType, Type are required.
113type BetaBase64ImageSourceParam struct {
114 Data string `json:"data,required" format:"byte"`
115 // Any of "image/jpeg", "image/png", "image/gif", "image/webp".
116 MediaType BetaBase64ImageSourceMediaType `json:"media_type,omitzero,required"`
117 // This field can be elided, and will marshal its zero value as "base64".
118 Type constant.Base64 `json:"type,required"`
119 paramObj
120}
121
122func (r BetaBase64ImageSourceParam) MarshalJSON() (data []byte, err error) {
123 type shadow BetaBase64ImageSourceParam
124 return param.MarshalObject(r, (*shadow)(&r))
125}
126func (r *BetaBase64ImageSourceParam) UnmarshalJSON(data []byte) error {
127 return apijson.UnmarshalRoot(data, r)
128}
129
130type BetaBase64ImageSourceMediaType string
131
132const (
133 BetaBase64ImageSourceMediaTypeImageJPEG BetaBase64ImageSourceMediaType = "image/jpeg"
134 BetaBase64ImageSourceMediaTypeImagePNG BetaBase64ImageSourceMediaType = "image/png"
135 BetaBase64ImageSourceMediaTypeImageGIF BetaBase64ImageSourceMediaType = "image/gif"
136 BetaBase64ImageSourceMediaTypeImageWebP BetaBase64ImageSourceMediaType = "image/webp"
137)
138
139// The properties Source, Type are required.
140type BetaBase64PDFBlockParam struct {
141 Source BetaBase64PDFBlockSourceUnionParam `json:"source,omitzero,required"`
142 Context param.Opt[string] `json:"context,omitzero"`
143 Title param.Opt[string] `json:"title,omitzero"`
144 // Create a cache control breakpoint at this content block.
145 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
146 Citations BetaCitationsConfigParam `json:"citations,omitzero"`
147 // This field can be elided, and will marshal its zero value as "document".
148 Type constant.Document `json:"type,required"`
149 paramObj
150}
151
152func (r BetaBase64PDFBlockParam) MarshalJSON() (data []byte, err error) {
153 type shadow BetaBase64PDFBlockParam
154 return param.MarshalObject(r, (*shadow)(&r))
155}
156func (r *BetaBase64PDFBlockParam) UnmarshalJSON(data []byte) error {
157 return apijson.UnmarshalRoot(data, r)
158}
159
160// Only one field can be non-zero.
161//
162// Use [param.IsOmitted] to confirm if a field is set.
163type BetaBase64PDFBlockSourceUnionParam struct {
164 OfBase64 *BetaBase64PDFSourceParam `json:",omitzero,inline"`
165 OfText *BetaPlainTextSourceParam `json:",omitzero,inline"`
166 OfContent *BetaContentBlockSourceParam `json:",omitzero,inline"`
167 OfURL *BetaURLPDFSourceParam `json:",omitzero,inline"`
168 OfFile *BetaFileDocumentSourceParam `json:",omitzero,inline"`
169 paramUnion
170}
171
172func (u BetaBase64PDFBlockSourceUnionParam) MarshalJSON() ([]byte, error) {
173 return param.MarshalUnion(u, u.OfBase64,
174 u.OfText,
175 u.OfContent,
176 u.OfURL,
177 u.OfFile)
178}
179func (u *BetaBase64PDFBlockSourceUnionParam) UnmarshalJSON(data []byte) error {
180 return apijson.UnmarshalRoot(data, u)
181}
182
183func (u *BetaBase64PDFBlockSourceUnionParam) asAny() any {
184 if !param.IsOmitted(u.OfBase64) {
185 return u.OfBase64
186 } else if !param.IsOmitted(u.OfText) {
187 return u.OfText
188 } else if !param.IsOmitted(u.OfContent) {
189 return u.OfContent
190 } else if !param.IsOmitted(u.OfURL) {
191 return u.OfURL
192 } else if !param.IsOmitted(u.OfFile) {
193 return u.OfFile
194 }
195 return nil
196}
197
198// Returns a pointer to the underlying variant's property, if present.
199func (u BetaBase64PDFBlockSourceUnionParam) GetContent() *BetaContentBlockSourceContentUnionParam {
200 if vt := u.OfContent; vt != nil {
201 return &vt.Content
202 }
203 return nil
204}
205
206// Returns a pointer to the underlying variant's property, if present.
207func (u BetaBase64PDFBlockSourceUnionParam) GetURL() *string {
208 if vt := u.OfURL; vt != nil {
209 return &vt.URL
210 }
211 return nil
212}
213
214// Returns a pointer to the underlying variant's property, if present.
215func (u BetaBase64PDFBlockSourceUnionParam) GetFileID() *string {
216 if vt := u.OfFile; vt != nil {
217 return &vt.FileID
218 }
219 return nil
220}
221
222// Returns a pointer to the underlying variant's property, if present.
223func (u BetaBase64PDFBlockSourceUnionParam) GetData() *string {
224 if vt := u.OfBase64; vt != nil {
225 return (*string)(&vt.Data)
226 } else if vt := u.OfText; vt != nil {
227 return (*string)(&vt.Data)
228 }
229 return nil
230}
231
232// Returns a pointer to the underlying variant's property, if present.
233func (u BetaBase64PDFBlockSourceUnionParam) GetMediaType() *string {
234 if vt := u.OfBase64; vt != nil {
235 return (*string)(&vt.MediaType)
236 } else if vt := u.OfText; vt != nil {
237 return (*string)(&vt.MediaType)
238 }
239 return nil
240}
241
242// Returns a pointer to the underlying variant's property, if present.
243func (u BetaBase64PDFBlockSourceUnionParam) GetType() *string {
244 if vt := u.OfBase64; vt != nil {
245 return (*string)(&vt.Type)
246 } else if vt := u.OfText; vt != nil {
247 return (*string)(&vt.Type)
248 } else if vt := u.OfContent; vt != nil {
249 return (*string)(&vt.Type)
250 } else if vt := u.OfURL; vt != nil {
251 return (*string)(&vt.Type)
252 } else if vt := u.OfFile; vt != nil {
253 return (*string)(&vt.Type)
254 }
255 return nil
256}
257
258func init() {
259 apijson.RegisterUnion[BetaBase64PDFBlockSourceUnionParam](
260 "type",
261 apijson.Discriminator[BetaBase64PDFSourceParam]("base64"),
262 apijson.Discriminator[BetaPlainTextSourceParam]("text"),
263 apijson.Discriminator[BetaContentBlockSourceParam]("content"),
264 apijson.Discriminator[BetaURLPDFSourceParam]("url"),
265 apijson.Discriminator[BetaFileDocumentSourceParam]("file"),
266 )
267}
268
269func init() {
270 apijson.RegisterUnion[BetaContentBlockParamUnion](
271 "type",
272 apijson.Discriminator[BetaServerToolUseBlockParam]("server_tool_use"),
273 apijson.Discriminator[BetaWebSearchToolResultBlockParam]("web_search_tool_result"),
274 apijson.Discriminator[BetaCodeExecutionToolResultBlockParam]("code_execution_tool_result"),
275 apijson.Discriminator[BetaMCPToolUseBlockParam]("mcp_tool_use"),
276 apijson.Discriminator[BetaRequestMCPToolResultBlockParam]("mcp_tool_result"),
277 apijson.Discriminator[BetaTextBlockParam]("text"),
278 apijson.Discriminator[BetaImageBlockParam]("image"),
279 apijson.Discriminator[BetaToolUseBlockParam]("tool_use"),
280 apijson.Discriminator[BetaToolResultBlockParam]("tool_result"),
281 apijson.Discriminator[BetaBase64PDFBlockParam]("document"),
282 apijson.Discriminator[BetaThinkingBlockParam]("thinking"),
283 apijson.Discriminator[BetaRedactedThinkingBlockParam]("redacted_thinking"),
284 apijson.Discriminator[BetaContainerUploadBlockParam]("container_upload"),
285 )
286}
287
288func init() {
289 apijson.RegisterUnion[BetaImageBlockParamSourceUnion](
290 "type",
291 apijson.Discriminator[BetaBase64ImageSourceParam]("base64"),
292 apijson.Discriminator[BetaURLImageSourceParam]("url"),
293 apijson.Discriminator[BetaFileImageSourceParam]("file"),
294 )
295}
296
297func init() {
298 apijson.RegisterUnion[BetaTextCitationParamUnion](
299 "type",
300 apijson.Discriminator[BetaCitationCharLocationParam]("char_location"),
301 apijson.Discriminator[BetaCitationPageLocationParam]("page_location"),
302 apijson.Discriminator[BetaCitationContentBlockLocationParam]("content_block_location"),
303 apijson.Discriminator[BetaCitationWebSearchResultLocationParam]("web_search_result_location"),
304 )
305}
306
307func init() {
308 apijson.RegisterUnion[BetaThinkingConfigParamUnion](
309 "type",
310 apijson.Discriminator[BetaThinkingConfigEnabledParam]("enabled"),
311 apijson.Discriminator[BetaThinkingConfigDisabledParam]("disabled"),
312 )
313}
314
315func init() {
316 apijson.RegisterUnion[BetaToolChoiceUnionParam](
317 "type",
318 apijson.Discriminator[BetaToolChoiceAutoParam]("auto"),
319 apijson.Discriminator[BetaToolChoiceAnyParam]("any"),
320 apijson.Discriminator[BetaToolChoiceToolParam]("tool"),
321 apijson.Discriminator[BetaToolChoiceNoneParam]("none"),
322 )
323}
324
325func init() {
326 apijson.RegisterUnion[BetaToolResultBlockParamContentUnion](
327 "type",
328 apijson.Discriminator[BetaTextBlockParam]("text"),
329 apijson.Discriminator[BetaImageBlockParam]("image"),
330 )
331}
332
333// The properties Data, MediaType, Type are required.
334type BetaBase64PDFSourceParam struct {
335 Data string `json:"data,required" format:"byte"`
336 // This field can be elided, and will marshal its zero value as "application/pdf".
337 MediaType constant.ApplicationPDF `json:"media_type,required"`
338 // This field can be elided, and will marshal its zero value as "base64".
339 Type constant.Base64 `json:"type,required"`
340 paramObj
341}
342
343func (r BetaBase64PDFSourceParam) MarshalJSON() (data []byte, err error) {
344 type shadow BetaBase64PDFSourceParam
345 return param.MarshalObject(r, (*shadow)(&r))
346}
347func (r *BetaBase64PDFSourceParam) UnmarshalJSON(data []byte) error {
348 return apijson.UnmarshalRoot(data, r)
349}
350
351func NewBetaCacheControlEphemeralParam() BetaCacheControlEphemeralParam {
352 return BetaCacheControlEphemeralParam{
353 Type: "ephemeral",
354 }
355}
356
357// This struct has a constant value, construct it with
358// [NewBetaCacheControlEphemeralParam].
359type BetaCacheControlEphemeralParam struct {
360 // The time-to-live for the cache control breakpoint.
361 //
362 // This may be one the following values:
363 //
364 // - `5m`: 5 minutes
365 // - `1h`: 1 hour
366 //
367 // Defaults to `5m`.
368 //
369 // Any of "5m", "1h".
370 TTL BetaCacheControlEphemeralTTL `json:"ttl,omitzero"`
371 Type constant.Ephemeral `json:"type,required"`
372 paramObj
373}
374
375func (r BetaCacheControlEphemeralParam) MarshalJSON() (data []byte, err error) {
376 type shadow BetaCacheControlEphemeralParam
377 return param.MarshalObject(r, (*shadow)(&r))
378}
379func (r *BetaCacheControlEphemeralParam) UnmarshalJSON(data []byte) error {
380 return apijson.UnmarshalRoot(data, r)
381}
382
383// The time-to-live for the cache control breakpoint.
384//
385// This may be one the following values:
386//
387// - `5m`: 5 minutes
388// - `1h`: 1 hour
389//
390// Defaults to `5m`.
391type BetaCacheControlEphemeralTTL string
392
393const (
394 BetaCacheControlEphemeralTTLTTL5m BetaCacheControlEphemeralTTL = "5m"
395 BetaCacheControlEphemeralTTLTTL1h BetaCacheControlEphemeralTTL = "1h"
396)
397
398type BetaCacheCreation struct {
399 // The number of input tokens used to create the 1 hour cache entry.
400 Ephemeral1hInputTokens int64 `json:"ephemeral_1h_input_tokens,required"`
401 // The number of input tokens used to create the 5 minute cache entry.
402 Ephemeral5mInputTokens int64 `json:"ephemeral_5m_input_tokens,required"`
403 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
404 JSON struct {
405 Ephemeral1hInputTokens respjson.Field
406 Ephemeral5mInputTokens respjson.Field
407 ExtraFields map[string]respjson.Field
408 raw string
409 } `json:"-"`
410}
411
412// Returns the unmodified JSON received from the API
413func (r BetaCacheCreation) RawJSON() string { return r.JSON.raw }
414func (r *BetaCacheCreation) UnmarshalJSON(data []byte) error {
415 return apijson.UnmarshalRoot(data, r)
416}
417
418type BetaCitationCharLocation struct {
419 CitedText string `json:"cited_text,required"`
420 DocumentIndex int64 `json:"document_index,required"`
421 DocumentTitle string `json:"document_title,required"`
422 EndCharIndex int64 `json:"end_char_index,required"`
423 StartCharIndex int64 `json:"start_char_index,required"`
424 Type constant.CharLocation `json:"type,required"`
425 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
426 JSON struct {
427 CitedText respjson.Field
428 DocumentIndex respjson.Field
429 DocumentTitle respjson.Field
430 EndCharIndex respjson.Field
431 StartCharIndex respjson.Field
432 Type respjson.Field
433 ExtraFields map[string]respjson.Field
434 raw string
435 } `json:"-"`
436}
437
438// Returns the unmodified JSON received from the API
439func (r BetaCitationCharLocation) RawJSON() string { return r.JSON.raw }
440func (r *BetaCitationCharLocation) UnmarshalJSON(data []byte) error {
441 return apijson.UnmarshalRoot(data, r)
442}
443
444// The properties CitedText, DocumentIndex, DocumentTitle, EndCharIndex,
445// StartCharIndex, Type are required.
446type BetaCitationCharLocationParam struct {
447 DocumentTitle param.Opt[string] `json:"document_title,omitzero,required"`
448 CitedText string `json:"cited_text,required"`
449 DocumentIndex int64 `json:"document_index,required"`
450 EndCharIndex int64 `json:"end_char_index,required"`
451 StartCharIndex int64 `json:"start_char_index,required"`
452 // This field can be elided, and will marshal its zero value as "char_location".
453 Type constant.CharLocation `json:"type,required"`
454 paramObj
455}
456
457func (r BetaCitationCharLocationParam) MarshalJSON() (data []byte, err error) {
458 type shadow BetaCitationCharLocationParam
459 return param.MarshalObject(r, (*shadow)(&r))
460}
461func (r *BetaCitationCharLocationParam) UnmarshalJSON(data []byte) error {
462 return apijson.UnmarshalRoot(data, r)
463}
464
465type BetaCitationContentBlockLocation struct {
466 CitedText string `json:"cited_text,required"`
467 DocumentIndex int64 `json:"document_index,required"`
468 DocumentTitle string `json:"document_title,required"`
469 EndBlockIndex int64 `json:"end_block_index,required"`
470 StartBlockIndex int64 `json:"start_block_index,required"`
471 Type constant.ContentBlockLocation `json:"type,required"`
472 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
473 JSON struct {
474 CitedText respjson.Field
475 DocumentIndex respjson.Field
476 DocumentTitle respjson.Field
477 EndBlockIndex respjson.Field
478 StartBlockIndex respjson.Field
479 Type respjson.Field
480 ExtraFields map[string]respjson.Field
481 raw string
482 } `json:"-"`
483}
484
485// Returns the unmodified JSON received from the API
486func (r BetaCitationContentBlockLocation) RawJSON() string { return r.JSON.raw }
487func (r *BetaCitationContentBlockLocation) UnmarshalJSON(data []byte) error {
488 return apijson.UnmarshalRoot(data, r)
489}
490
491// The properties CitedText, DocumentIndex, DocumentTitle, EndBlockIndex,
492// StartBlockIndex, Type are required.
493type BetaCitationContentBlockLocationParam struct {
494 DocumentTitle param.Opt[string] `json:"document_title,omitzero,required"`
495 CitedText string `json:"cited_text,required"`
496 DocumentIndex int64 `json:"document_index,required"`
497 EndBlockIndex int64 `json:"end_block_index,required"`
498 StartBlockIndex int64 `json:"start_block_index,required"`
499 // This field can be elided, and will marshal its zero value as
500 // "content_block_location".
501 Type constant.ContentBlockLocation `json:"type,required"`
502 paramObj
503}
504
505func (r BetaCitationContentBlockLocationParam) MarshalJSON() (data []byte, err error) {
506 type shadow BetaCitationContentBlockLocationParam
507 return param.MarshalObject(r, (*shadow)(&r))
508}
509func (r *BetaCitationContentBlockLocationParam) UnmarshalJSON(data []byte) error {
510 return apijson.UnmarshalRoot(data, r)
511}
512
513type BetaCitationPageLocation struct {
514 CitedText string `json:"cited_text,required"`
515 DocumentIndex int64 `json:"document_index,required"`
516 DocumentTitle string `json:"document_title,required"`
517 EndPageNumber int64 `json:"end_page_number,required"`
518 StartPageNumber int64 `json:"start_page_number,required"`
519 Type constant.PageLocation `json:"type,required"`
520 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
521 JSON struct {
522 CitedText respjson.Field
523 DocumentIndex respjson.Field
524 DocumentTitle respjson.Field
525 EndPageNumber respjson.Field
526 StartPageNumber respjson.Field
527 Type respjson.Field
528 ExtraFields map[string]respjson.Field
529 raw string
530 } `json:"-"`
531}
532
533// Returns the unmodified JSON received from the API
534func (r BetaCitationPageLocation) RawJSON() string { return r.JSON.raw }
535func (r *BetaCitationPageLocation) UnmarshalJSON(data []byte) error {
536 return apijson.UnmarshalRoot(data, r)
537}
538
539// The properties CitedText, DocumentIndex, DocumentTitle, EndPageNumber,
540// StartPageNumber, Type are required.
541type BetaCitationPageLocationParam struct {
542 DocumentTitle param.Opt[string] `json:"document_title,omitzero,required"`
543 CitedText string `json:"cited_text,required"`
544 DocumentIndex int64 `json:"document_index,required"`
545 EndPageNumber int64 `json:"end_page_number,required"`
546 StartPageNumber int64 `json:"start_page_number,required"`
547 // This field can be elided, and will marshal its zero value as "page_location".
548 Type constant.PageLocation `json:"type,required"`
549 paramObj
550}
551
552func (r BetaCitationPageLocationParam) MarshalJSON() (data []byte, err error) {
553 type shadow BetaCitationPageLocationParam
554 return param.MarshalObject(r, (*shadow)(&r))
555}
556func (r *BetaCitationPageLocationParam) UnmarshalJSON(data []byte) error {
557 return apijson.UnmarshalRoot(data, r)
558}
559
560// The properties CitedText, EncryptedIndex, Title, Type, URL are required.
561type BetaCitationWebSearchResultLocationParam struct {
562 Title param.Opt[string] `json:"title,omitzero,required"`
563 CitedText string `json:"cited_text,required"`
564 EncryptedIndex string `json:"encrypted_index,required"`
565 URL string `json:"url,required"`
566 // This field can be elided, and will marshal its zero value as
567 // "web_search_result_location".
568 Type constant.WebSearchResultLocation `json:"type,required"`
569 paramObj
570}
571
572func (r BetaCitationWebSearchResultLocationParam) MarshalJSON() (data []byte, err error) {
573 type shadow BetaCitationWebSearchResultLocationParam
574 return param.MarshalObject(r, (*shadow)(&r))
575}
576func (r *BetaCitationWebSearchResultLocationParam) UnmarshalJSON(data []byte) error {
577 return apijson.UnmarshalRoot(data, r)
578}
579
580type BetaCitationsConfigParam struct {
581 Enabled param.Opt[bool] `json:"enabled,omitzero"`
582 paramObj
583}
584
585func (r BetaCitationsConfigParam) MarshalJSON() (data []byte, err error) {
586 type shadow BetaCitationsConfigParam
587 return param.MarshalObject(r, (*shadow)(&r))
588}
589func (r *BetaCitationsConfigParam) UnmarshalJSON(data []byte) error {
590 return apijson.UnmarshalRoot(data, r)
591}
592
593type BetaCitationsDelta struct {
594 Citation BetaCitationsDeltaCitationUnion `json:"citation,required"`
595 Type constant.CitationsDelta `json:"type,required"`
596 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
597 JSON struct {
598 Citation respjson.Field
599 Type respjson.Field
600 ExtraFields map[string]respjson.Field
601 raw string
602 } `json:"-"`
603}
604
605// Returns the unmodified JSON received from the API
606func (r BetaCitationsDelta) RawJSON() string { return r.JSON.raw }
607func (r *BetaCitationsDelta) UnmarshalJSON(data []byte) error {
608 return apijson.UnmarshalRoot(data, r)
609}
610
611// BetaCitationsDeltaCitationUnion contains all possible properties and values from
612// [BetaCitationCharLocation], [BetaCitationPageLocation],
613// [BetaCitationContentBlockLocation], [BetaCitationsWebSearchResultLocation].
614//
615// Use the [BetaCitationsDeltaCitationUnion.AsAny] method to switch on the variant.
616//
617// Use the methods beginning with 'As' to cast the union to one of its variants.
618type BetaCitationsDeltaCitationUnion struct {
619 CitedText string `json:"cited_text"`
620 DocumentIndex int64 `json:"document_index"`
621 DocumentTitle string `json:"document_title"`
622 // This field is from variant [BetaCitationCharLocation].
623 EndCharIndex int64 `json:"end_char_index"`
624 // This field is from variant [BetaCitationCharLocation].
625 StartCharIndex int64 `json:"start_char_index"`
626 // Any of "char_location", "page_location", "content_block_location",
627 // "web_search_result_location".
628 Type string `json:"type"`
629 // This field is from variant [BetaCitationPageLocation].
630 EndPageNumber int64 `json:"end_page_number"`
631 // This field is from variant [BetaCitationPageLocation].
632 StartPageNumber int64 `json:"start_page_number"`
633 // This field is from variant [BetaCitationContentBlockLocation].
634 EndBlockIndex int64 `json:"end_block_index"`
635 // This field is from variant [BetaCitationContentBlockLocation].
636 StartBlockIndex int64 `json:"start_block_index"`
637 // This field is from variant [BetaCitationsWebSearchResultLocation].
638 EncryptedIndex string `json:"encrypted_index"`
639 // This field is from variant [BetaCitationsWebSearchResultLocation].
640 Title string `json:"title"`
641 // This field is from variant [BetaCitationsWebSearchResultLocation].
642 URL string `json:"url"`
643 JSON struct {
644 CitedText respjson.Field
645 DocumentIndex respjson.Field
646 DocumentTitle respjson.Field
647 EndCharIndex respjson.Field
648 StartCharIndex respjson.Field
649 Type respjson.Field
650 EndPageNumber respjson.Field
651 StartPageNumber respjson.Field
652 EndBlockIndex respjson.Field
653 StartBlockIndex respjson.Field
654 EncryptedIndex respjson.Field
655 Title respjson.Field
656 URL respjson.Field
657 raw string
658 } `json:"-"`
659}
660
661// anyBetaCitationsDeltaCitation is implemented by each variant of
662// [BetaCitationsDeltaCitationUnion] to add type safety for the return type of
663// [BetaCitationsDeltaCitationUnion.AsAny]
664type anyBetaCitationsDeltaCitation interface {
665 implBetaCitationsDeltaCitationUnion()
666}
667
668func (BetaCitationCharLocation) implBetaCitationsDeltaCitationUnion() {}
669func (BetaCitationPageLocation) implBetaCitationsDeltaCitationUnion() {}
670func (BetaCitationContentBlockLocation) implBetaCitationsDeltaCitationUnion() {}
671func (BetaCitationsWebSearchResultLocation) implBetaCitationsDeltaCitationUnion() {}
672
673// Use the following switch statement to find the correct variant
674//
675// switch variant := BetaCitationsDeltaCitationUnion.AsAny().(type) {
676// case anthropic.BetaCitationCharLocation:
677// case anthropic.BetaCitationPageLocation:
678// case anthropic.BetaCitationContentBlockLocation:
679// case anthropic.BetaCitationsWebSearchResultLocation:
680// default:
681// fmt.Errorf("no variant present")
682// }
683func (u BetaCitationsDeltaCitationUnion) AsAny() anyBetaCitationsDeltaCitation {
684 switch u.Type {
685 case "char_location":
686 return u.AsCharLocation()
687 case "page_location":
688 return u.AsPageLocation()
689 case "content_block_location":
690 return u.AsContentBlockLocation()
691 case "web_search_result_location":
692 return u.AsWebSearchResultLocation()
693 }
694 return nil
695}
696
697func (u BetaCitationsDeltaCitationUnion) AsCharLocation() (v BetaCitationCharLocation) {
698 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
699 return
700}
701
702func (u BetaCitationsDeltaCitationUnion) AsPageLocation() (v BetaCitationPageLocation) {
703 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
704 return
705}
706
707func (u BetaCitationsDeltaCitationUnion) AsContentBlockLocation() (v BetaCitationContentBlockLocation) {
708 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
709 return
710}
711
712func (u BetaCitationsDeltaCitationUnion) AsWebSearchResultLocation() (v BetaCitationsWebSearchResultLocation) {
713 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
714 return
715}
716
717// Returns the unmodified JSON received from the API
718func (u BetaCitationsDeltaCitationUnion) RawJSON() string { return u.JSON.raw }
719
720func (r *BetaCitationsDeltaCitationUnion) UnmarshalJSON(data []byte) error {
721 return apijson.UnmarshalRoot(data, r)
722}
723
724type BetaCitationsWebSearchResultLocation struct {
725 CitedText string `json:"cited_text,required"`
726 EncryptedIndex string `json:"encrypted_index,required"`
727 Title string `json:"title,required"`
728 Type constant.WebSearchResultLocation `json:"type,required"`
729 URL string `json:"url,required"`
730 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
731 JSON struct {
732 CitedText respjson.Field
733 EncryptedIndex respjson.Field
734 Title respjson.Field
735 Type respjson.Field
736 URL respjson.Field
737 ExtraFields map[string]respjson.Field
738 raw string
739 } `json:"-"`
740}
741
742// Returns the unmodified JSON received from the API
743func (r BetaCitationsWebSearchResultLocation) RawJSON() string { return r.JSON.raw }
744func (r *BetaCitationsWebSearchResultLocation) UnmarshalJSON(data []byte) error {
745 return apijson.UnmarshalRoot(data, r)
746}
747
748type BetaCodeExecutionOutputBlock struct {
749 FileID string `json:"file_id,required"`
750 Type constant.CodeExecutionOutput `json:"type,required"`
751 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
752 JSON struct {
753 FileID respjson.Field
754 Type respjson.Field
755 ExtraFields map[string]respjson.Field
756 raw string
757 } `json:"-"`
758}
759
760// Returns the unmodified JSON received from the API
761func (r BetaCodeExecutionOutputBlock) RawJSON() string { return r.JSON.raw }
762func (r *BetaCodeExecutionOutputBlock) UnmarshalJSON(data []byte) error {
763 return apijson.UnmarshalRoot(data, r)
764}
765
766// The properties FileID, Type are required.
767type BetaCodeExecutionOutputBlockParam struct {
768 FileID string `json:"file_id,required"`
769 // This field can be elided, and will marshal its zero value as
770 // "code_execution_output".
771 Type constant.CodeExecutionOutput `json:"type,required"`
772 paramObj
773}
774
775func (r BetaCodeExecutionOutputBlockParam) MarshalJSON() (data []byte, err error) {
776 type shadow BetaCodeExecutionOutputBlockParam
777 return param.MarshalObject(r, (*shadow)(&r))
778}
779func (r *BetaCodeExecutionOutputBlockParam) UnmarshalJSON(data []byte) error {
780 return apijson.UnmarshalRoot(data, r)
781}
782
783type BetaCodeExecutionResultBlock struct {
784 Content []BetaCodeExecutionOutputBlock `json:"content,required"`
785 ReturnCode int64 `json:"return_code,required"`
786 Stderr string `json:"stderr,required"`
787 Stdout string `json:"stdout,required"`
788 Type constant.CodeExecutionResult `json:"type,required"`
789 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
790 JSON struct {
791 Content respjson.Field
792 ReturnCode respjson.Field
793 Stderr respjson.Field
794 Stdout respjson.Field
795 Type respjson.Field
796 ExtraFields map[string]respjson.Field
797 raw string
798 } `json:"-"`
799}
800
801// Returns the unmodified JSON received from the API
802func (r BetaCodeExecutionResultBlock) RawJSON() string { return r.JSON.raw }
803func (r *BetaCodeExecutionResultBlock) UnmarshalJSON(data []byte) error {
804 return apijson.UnmarshalRoot(data, r)
805}
806
807// The properties Content, ReturnCode, Stderr, Stdout, Type are required.
808type BetaCodeExecutionResultBlockParam struct {
809 Content []BetaCodeExecutionOutputBlockParam `json:"content,omitzero,required"`
810 ReturnCode int64 `json:"return_code,required"`
811 Stderr string `json:"stderr,required"`
812 Stdout string `json:"stdout,required"`
813 // This field can be elided, and will marshal its zero value as
814 // "code_execution_result".
815 Type constant.CodeExecutionResult `json:"type,required"`
816 paramObj
817}
818
819func (r BetaCodeExecutionResultBlockParam) MarshalJSON() (data []byte, err error) {
820 type shadow BetaCodeExecutionResultBlockParam
821 return param.MarshalObject(r, (*shadow)(&r))
822}
823func (r *BetaCodeExecutionResultBlockParam) UnmarshalJSON(data []byte) error {
824 return apijson.UnmarshalRoot(data, r)
825}
826
827// The properties Name, Type are required.
828type BetaCodeExecutionTool20250522Param struct {
829 // Create a cache control breakpoint at this content block.
830 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
831 // Name of the tool.
832 //
833 // This is how the tool will be called by the model and in `tool_use` blocks.
834 //
835 // This field can be elided, and will marshal its zero value as "code_execution".
836 Name constant.CodeExecution `json:"name,required"`
837 // This field can be elided, and will marshal its zero value as
838 // "code_execution_20250522".
839 Type constant.CodeExecution20250522 `json:"type,required"`
840 paramObj
841}
842
843func (r BetaCodeExecutionTool20250522Param) MarshalJSON() (data []byte, err error) {
844 type shadow BetaCodeExecutionTool20250522Param
845 return param.MarshalObject(r, (*shadow)(&r))
846}
847func (r *BetaCodeExecutionTool20250522Param) UnmarshalJSON(data []byte) error {
848 return apijson.UnmarshalRoot(data, r)
849}
850
851type BetaCodeExecutionToolResultBlock struct {
852 Content BetaCodeExecutionToolResultBlockContentUnion `json:"content,required"`
853 ToolUseID string `json:"tool_use_id,required"`
854 Type constant.CodeExecutionToolResult `json:"type,required"`
855 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
856 JSON struct {
857 Content respjson.Field
858 ToolUseID respjson.Field
859 Type respjson.Field
860 ExtraFields map[string]respjson.Field
861 raw string
862 } `json:"-"`
863}
864
865// Returns the unmodified JSON received from the API
866func (r BetaCodeExecutionToolResultBlock) RawJSON() string { return r.JSON.raw }
867func (r *BetaCodeExecutionToolResultBlock) UnmarshalJSON(data []byte) error {
868 return apijson.UnmarshalRoot(data, r)
869}
870
871// BetaCodeExecutionToolResultBlockContentUnion contains all possible properties
872// and values from [BetaCodeExecutionToolResultError],
873// [BetaCodeExecutionResultBlock].
874//
875// Use the methods beginning with 'As' to cast the union to one of its variants.
876type BetaCodeExecutionToolResultBlockContentUnion struct {
877 // This field is from variant [BetaCodeExecutionToolResultError].
878 ErrorCode BetaCodeExecutionToolResultErrorCode `json:"error_code"`
879 Type string `json:"type"`
880 // This field is from variant [BetaCodeExecutionResultBlock].
881 Content []BetaCodeExecutionOutputBlock `json:"content"`
882 // This field is from variant [BetaCodeExecutionResultBlock].
883 ReturnCode int64 `json:"return_code"`
884 // This field is from variant [BetaCodeExecutionResultBlock].
885 Stderr string `json:"stderr"`
886 // This field is from variant [BetaCodeExecutionResultBlock].
887 Stdout string `json:"stdout"`
888 JSON struct {
889 ErrorCode respjson.Field
890 Type respjson.Field
891 Content respjson.Field
892 ReturnCode respjson.Field
893 Stderr respjson.Field
894 Stdout respjson.Field
895 raw string
896 } `json:"-"`
897}
898
899func (u BetaCodeExecutionToolResultBlockContentUnion) AsResponseCodeExecutionToolResultError() (v BetaCodeExecutionToolResultError) {
900 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
901 return
902}
903
904func (u BetaCodeExecutionToolResultBlockContentUnion) AsResponseCodeExecutionResultBlock() (v BetaCodeExecutionResultBlock) {
905 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
906 return
907}
908
909// Returns the unmodified JSON received from the API
910func (u BetaCodeExecutionToolResultBlockContentUnion) RawJSON() string { return u.JSON.raw }
911
912func (r *BetaCodeExecutionToolResultBlockContentUnion) UnmarshalJSON(data []byte) error {
913 return apijson.UnmarshalRoot(data, r)
914}
915
916// The properties Content, ToolUseID, Type are required.
917type BetaCodeExecutionToolResultBlockParam struct {
918 Content BetaCodeExecutionToolResultBlockParamContentUnion `json:"content,omitzero,required"`
919 ToolUseID string `json:"tool_use_id,required"`
920 // Create a cache control breakpoint at this content block.
921 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
922 // This field can be elided, and will marshal its zero value as
923 // "code_execution_tool_result".
924 Type constant.CodeExecutionToolResult `json:"type,required"`
925 paramObj
926}
927
928func (r BetaCodeExecutionToolResultBlockParam) MarshalJSON() (data []byte, err error) {
929 type shadow BetaCodeExecutionToolResultBlockParam
930 return param.MarshalObject(r, (*shadow)(&r))
931}
932func (r *BetaCodeExecutionToolResultBlockParam) UnmarshalJSON(data []byte) error {
933 return apijson.UnmarshalRoot(data, r)
934}
935
936func BetaNewCodeExecutionToolRequestError(errorCode BetaCodeExecutionToolResultErrorCode) BetaCodeExecutionToolResultBlockParamContentUnion {
937 var variant BetaCodeExecutionToolResultErrorParam
938 variant.ErrorCode = errorCode
939 return BetaCodeExecutionToolResultBlockParamContentUnion{OfError: &variant}
940}
941
942// Only one field can be non-zero.
943//
944// Use [param.IsOmitted] to confirm if a field is set.
945type BetaCodeExecutionToolResultBlockParamContentUnion struct {
946 OfError *BetaCodeExecutionToolResultErrorParam `json:",omitzero,inline"`
947 OfResultBlock *BetaCodeExecutionResultBlockParam `json:",omitzero,inline"`
948 paramUnion
949}
950
951func (u BetaCodeExecutionToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
952 return param.MarshalUnion(u, u.OfError, u.OfResultBlock)
953}
954func (u *BetaCodeExecutionToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
955 return apijson.UnmarshalRoot(data, u)
956}
957
958func (u *BetaCodeExecutionToolResultBlockParamContentUnion) asAny() any {
959 if !param.IsOmitted(u.OfError) {
960 return u.OfError
961 } else if !param.IsOmitted(u.OfResultBlock) {
962 return u.OfResultBlock
963 }
964 return nil
965}
966
967// Returns a pointer to the underlying variant's property, if present.
968func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetErrorCode() *string {
969 if vt := u.OfError; vt != nil {
970 return (*string)(&vt.ErrorCode)
971 }
972 return nil
973}
974
975// Returns a pointer to the underlying variant's property, if present.
976func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetContent() []BetaCodeExecutionOutputBlockParam {
977 if vt := u.OfResultBlock; vt != nil {
978 return vt.Content
979 }
980 return nil
981}
982
983// Returns a pointer to the underlying variant's property, if present.
984func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetReturnCode() *int64 {
985 if vt := u.OfResultBlock; vt != nil {
986 return &vt.ReturnCode
987 }
988 return nil
989}
990
991// Returns a pointer to the underlying variant's property, if present.
992func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetStderr() *string {
993 if vt := u.OfResultBlock; vt != nil {
994 return &vt.Stderr
995 }
996 return nil
997}
998
999// Returns a pointer to the underlying variant's property, if present.
1000func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetStdout() *string {
1001 if vt := u.OfResultBlock; vt != nil {
1002 return &vt.Stdout
1003 }
1004 return nil
1005}
1006
1007// Returns a pointer to the underlying variant's property, if present.
1008func (u BetaCodeExecutionToolResultBlockParamContentUnion) GetType() *string {
1009 if vt := u.OfError; vt != nil {
1010 return (*string)(&vt.Type)
1011 } else if vt := u.OfResultBlock; vt != nil {
1012 return (*string)(&vt.Type)
1013 }
1014 return nil
1015}
1016
1017type BetaCodeExecutionToolResultError struct {
1018 // Any of "invalid_tool_input", "unavailable", "too_many_requests",
1019 // "execution_time_exceeded".
1020 ErrorCode BetaCodeExecutionToolResultErrorCode `json:"error_code,required"`
1021 Type constant.CodeExecutionToolResultError `json:"type,required"`
1022 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1023 JSON struct {
1024 ErrorCode respjson.Field
1025 Type respjson.Field
1026 ExtraFields map[string]respjson.Field
1027 raw string
1028 } `json:"-"`
1029}
1030
1031// Returns the unmodified JSON received from the API
1032func (r BetaCodeExecutionToolResultError) RawJSON() string { return r.JSON.raw }
1033func (r *BetaCodeExecutionToolResultError) UnmarshalJSON(data []byte) error {
1034 return apijson.UnmarshalRoot(data, r)
1035}
1036
1037type BetaCodeExecutionToolResultErrorCode string
1038
1039const (
1040 BetaCodeExecutionToolResultErrorCodeInvalidToolInput BetaCodeExecutionToolResultErrorCode = "invalid_tool_input"
1041 BetaCodeExecutionToolResultErrorCodeUnavailable BetaCodeExecutionToolResultErrorCode = "unavailable"
1042 BetaCodeExecutionToolResultErrorCodeTooManyRequests BetaCodeExecutionToolResultErrorCode = "too_many_requests"
1043 BetaCodeExecutionToolResultErrorCodeExecutionTimeExceeded BetaCodeExecutionToolResultErrorCode = "execution_time_exceeded"
1044)
1045
1046// The properties ErrorCode, Type are required.
1047type BetaCodeExecutionToolResultErrorParam struct {
1048 // Any of "invalid_tool_input", "unavailable", "too_many_requests",
1049 // "execution_time_exceeded".
1050 ErrorCode BetaCodeExecutionToolResultErrorCode `json:"error_code,omitzero,required"`
1051 // This field can be elided, and will marshal its zero value as
1052 // "code_execution_tool_result_error".
1053 Type constant.CodeExecutionToolResultError `json:"type,required"`
1054 paramObj
1055}
1056
1057func (r BetaCodeExecutionToolResultErrorParam) MarshalJSON() (data []byte, err error) {
1058 type shadow BetaCodeExecutionToolResultErrorParam
1059 return param.MarshalObject(r, (*shadow)(&r))
1060}
1061func (r *BetaCodeExecutionToolResultErrorParam) UnmarshalJSON(data []byte) error {
1062 return apijson.UnmarshalRoot(data, r)
1063}
1064
1065// Information about the container used in the request (for the code execution
1066// tool)
1067type BetaContainer struct {
1068 // Identifier for the container used in this request
1069 ID string `json:"id,required"`
1070 // The time at which the container will expire.
1071 ExpiresAt time.Time `json:"expires_at,required" format:"date-time"`
1072 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1073 JSON struct {
1074 ID respjson.Field
1075 ExpiresAt respjson.Field
1076 ExtraFields map[string]respjson.Field
1077 raw string
1078 } `json:"-"`
1079}
1080
1081// Returns the unmodified JSON received from the API
1082func (r BetaContainer) RawJSON() string { return r.JSON.raw }
1083func (r *BetaContainer) UnmarshalJSON(data []byte) error {
1084 return apijson.UnmarshalRoot(data, r)
1085}
1086
1087// Response model for a file uploaded to the container.
1088type BetaContainerUploadBlock struct {
1089 FileID string `json:"file_id,required"`
1090 Type constant.ContainerUpload `json:"type,required"`
1091 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1092 JSON struct {
1093 FileID respjson.Field
1094 Type respjson.Field
1095 ExtraFields map[string]respjson.Field
1096 raw string
1097 } `json:"-"`
1098}
1099
1100// Returns the unmodified JSON received from the API
1101func (r BetaContainerUploadBlock) RawJSON() string { return r.JSON.raw }
1102func (r *BetaContainerUploadBlock) UnmarshalJSON(data []byte) error {
1103 return apijson.UnmarshalRoot(data, r)
1104}
1105
1106// A content block that represents a file to be uploaded to the container Files
1107// uploaded via this block will be available in the container's input directory.
1108//
1109// The properties FileID, Type are required.
1110type BetaContainerUploadBlockParam struct {
1111 FileID string `json:"file_id,required"`
1112 // Create a cache control breakpoint at this content block.
1113 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
1114 // This field can be elided, and will marshal its zero value as "container_upload".
1115 Type constant.ContainerUpload `json:"type,required"`
1116 paramObj
1117}
1118
1119func (r BetaContainerUploadBlockParam) MarshalJSON() (data []byte, err error) {
1120 type shadow BetaContainerUploadBlockParam
1121 return param.MarshalObject(r, (*shadow)(&r))
1122}
1123func (r *BetaContainerUploadBlockParam) UnmarshalJSON(data []byte) error {
1124 return apijson.UnmarshalRoot(data, r)
1125}
1126
1127// BetaContentBlockUnion contains all possible properties and values from
1128// [BetaTextBlock], [BetaToolUseBlock], [BetaServerToolUseBlock],
1129// [BetaWebSearchToolResultBlock], [BetaCodeExecutionToolResultBlock],
1130// [BetaMCPToolUseBlock], [BetaMCPToolResultBlock], [BetaContainerUploadBlock],
1131// [BetaThinkingBlock], [BetaRedactedThinkingBlock].
1132//
1133// Use the [BetaContentBlockUnion.AsAny] method to switch on the variant.
1134//
1135// Use the methods beginning with 'As' to cast the union to one of its variants.
1136type BetaContentBlockUnion struct {
1137 // This field is from variant [BetaTextBlock].
1138 Citations []BetaTextCitationUnion `json:"citations"`
1139 // This field is from variant [BetaTextBlock].
1140 Text string `json:"text"`
1141 // Any of "text", "tool_use", "server_tool_use", "web_search_tool_result",
1142 // "code_execution_tool_result", "mcp_tool_use", "mcp_tool_result",
1143 // "container_upload", "thinking", "redacted_thinking".
1144 Type string `json:"type"`
1145 ID string `json:"id"`
1146 Input json.RawMessage `json:"input"`
1147 Name string `json:"name"`
1148 // This field is a union of [BetaWebSearchToolResultBlockContentUnion],
1149 // [BetaCodeExecutionToolResultBlockContentUnion],
1150 // [BetaMCPToolResultBlockContentUnion]
1151 Content BetaContentBlockUnionContent `json:"content"`
1152 ToolUseID string `json:"tool_use_id"`
1153 // This field is from variant [BetaMCPToolUseBlock].
1154 ServerName string `json:"server_name"`
1155 // This field is from variant [BetaMCPToolResultBlock].
1156 IsError bool `json:"is_error"`
1157 // This field is from variant [BetaContainerUploadBlock].
1158 FileID string `json:"file_id"`
1159 // This field is from variant [BetaThinkingBlock].
1160 Signature string `json:"signature"`
1161 // This field is from variant [BetaThinkingBlock].
1162 Thinking string `json:"thinking"`
1163 // This field is from variant [BetaRedactedThinkingBlock].
1164 Data string `json:"data"`
1165 JSON struct {
1166 Citations respjson.Field
1167 Text respjson.Field
1168 Type respjson.Field
1169 ID respjson.Field
1170 Input respjson.Field
1171 Name respjson.Field
1172 Content respjson.Field
1173 ToolUseID respjson.Field
1174 ServerName respjson.Field
1175 IsError respjson.Field
1176 FileID respjson.Field
1177 Signature respjson.Field
1178 Thinking respjson.Field
1179 Data respjson.Field
1180 raw string
1181 } `json:"-"`
1182}
1183
1184func (r BetaContentBlockUnion) ToParam() BetaContentBlockParamUnion {
1185 switch variant := r.AsAny().(type) {
1186 case BetaTextBlock:
1187 p := variant.ToParam()
1188 return BetaContentBlockParamUnion{OfText: &p}
1189 case BetaToolUseBlock:
1190 p := variant.ToParam()
1191 return BetaContentBlockParamUnion{OfToolUse: &p}
1192 case BetaThinkingBlock:
1193 p := variant.ToParam()
1194 return BetaContentBlockParamUnion{OfThinking: &p}
1195 case BetaRedactedThinkingBlock:
1196 p := variant.ToParam()
1197 return BetaContentBlockParamUnion{OfRedactedThinking: &p}
1198 }
1199 return BetaContentBlockParamUnion{}
1200}
1201
1202// anyBetaContentBlock is implemented by each variant of [BetaContentBlockUnion] to
1203// add type safety for the return type of [BetaContentBlockUnion.AsAny]
1204type anyBetaContentBlock interface {
1205 implBetaContentBlockUnion()
1206}
1207
1208func (BetaTextBlock) implBetaContentBlockUnion() {}
1209func (BetaToolUseBlock) implBetaContentBlockUnion() {}
1210func (BetaServerToolUseBlock) implBetaContentBlockUnion() {}
1211func (BetaWebSearchToolResultBlock) implBetaContentBlockUnion() {}
1212func (BetaCodeExecutionToolResultBlock) implBetaContentBlockUnion() {}
1213func (BetaMCPToolUseBlock) implBetaContentBlockUnion() {}
1214func (BetaMCPToolResultBlock) implBetaContentBlockUnion() {}
1215func (BetaContainerUploadBlock) implBetaContentBlockUnion() {}
1216func (BetaThinkingBlock) implBetaContentBlockUnion() {}
1217func (BetaRedactedThinkingBlock) implBetaContentBlockUnion() {}
1218
1219// Use the following switch statement to find the correct variant
1220//
1221// switch variant := BetaContentBlockUnion.AsAny().(type) {
1222// case anthropic.BetaTextBlock:
1223// case anthropic.BetaToolUseBlock:
1224// case anthropic.BetaServerToolUseBlock:
1225// case anthropic.BetaWebSearchToolResultBlock:
1226// case anthropic.BetaCodeExecutionToolResultBlock:
1227// case anthropic.BetaMCPToolUseBlock:
1228// case anthropic.BetaMCPToolResultBlock:
1229// case anthropic.BetaContainerUploadBlock:
1230// case anthropic.BetaThinkingBlock:
1231// case anthropic.BetaRedactedThinkingBlock:
1232// default:
1233// fmt.Errorf("no variant present")
1234// }
1235func (u BetaContentBlockUnion) AsAny() anyBetaContentBlock {
1236 switch u.Type {
1237 case "text":
1238 return u.AsText()
1239 case "tool_use":
1240 return u.AsToolUse()
1241 case "server_tool_use":
1242 return u.AsServerToolUse()
1243 case "web_search_tool_result":
1244 return u.AsWebSearchToolResult()
1245 case "code_execution_tool_result":
1246 return u.AsCodeExecutionToolResult()
1247 case "mcp_tool_use":
1248 return u.AsMCPToolUse()
1249 case "mcp_tool_result":
1250 return u.AsMCPToolResult()
1251 case "container_upload":
1252 return u.AsContainerUpload()
1253 case "thinking":
1254 return u.AsThinking()
1255 case "redacted_thinking":
1256 return u.AsRedactedThinking()
1257 }
1258 return nil
1259}
1260
1261func (u BetaContentBlockUnion) AsText() (v BetaTextBlock) {
1262 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1263 return
1264}
1265
1266func (u BetaContentBlockUnion) AsToolUse() (v BetaToolUseBlock) {
1267 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1268 return
1269}
1270
1271func (u BetaContentBlockUnion) AsServerToolUse() (v BetaServerToolUseBlock) {
1272 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1273 return
1274}
1275
1276func (u BetaContentBlockUnion) AsWebSearchToolResult() (v BetaWebSearchToolResultBlock) {
1277 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1278 return
1279}
1280
1281func (u BetaContentBlockUnion) AsCodeExecutionToolResult() (v BetaCodeExecutionToolResultBlock) {
1282 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1283 return
1284}
1285
1286func (u BetaContentBlockUnion) AsMCPToolUse() (v BetaMCPToolUseBlock) {
1287 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1288 return
1289}
1290
1291func (u BetaContentBlockUnion) AsMCPToolResult() (v BetaMCPToolResultBlock) {
1292 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1293 return
1294}
1295
1296func (u BetaContentBlockUnion) AsContainerUpload() (v BetaContainerUploadBlock) {
1297 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1298 return
1299}
1300
1301func (u BetaContentBlockUnion) AsThinking() (v BetaThinkingBlock) {
1302 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1303 return
1304}
1305
1306func (u BetaContentBlockUnion) AsRedactedThinking() (v BetaRedactedThinkingBlock) {
1307 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1308 return
1309}
1310
1311// Returns the unmodified JSON received from the API
1312func (u BetaContentBlockUnion) RawJSON() string { return u.JSON.raw }
1313
1314func (r *BetaContentBlockUnion) UnmarshalJSON(data []byte) error {
1315 return apijson.UnmarshalRoot(data, r)
1316}
1317
1318// BetaContentBlockUnionContent is an implicit subunion of [BetaContentBlockUnion].
1319// BetaContentBlockUnionContent provides convenient access to the sub-properties of
1320// the union.
1321//
1322// For type safety it is recommended to directly use a variant of the
1323// [BetaContentBlockUnion].
1324//
1325// If the underlying value is not a json object, one of the following properties
1326// will be valid: OfBetaWebSearchResultBlockArray OfString
1327// OfBetaMCPToolResultBlockContent]
1328type BetaContentBlockUnionContent struct {
1329 // This field will be present if the value is a [[]BetaWebSearchResultBlock]
1330 // instead of an object.
1331 OfBetaWebSearchResultBlockArray []BetaWebSearchResultBlock `json:",inline"`
1332 // This field will be present if the value is a [string] instead of an object.
1333 OfString string `json:",inline"`
1334 // This field will be present if the value is a [[]BetaTextBlock] instead of an
1335 // object.
1336 OfBetaMCPToolResultBlockContent []BetaTextBlock `json:",inline"`
1337 ErrorCode string `json:"error_code"`
1338 Type string `json:"type"`
1339 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
1340 Content []BetaCodeExecutionOutputBlock `json:"content"`
1341 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
1342 ReturnCode int64 `json:"return_code"`
1343 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
1344 Stderr string `json:"stderr"`
1345 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
1346 Stdout string `json:"stdout"`
1347 JSON struct {
1348 OfBetaWebSearchResultBlockArray respjson.Field
1349 OfString respjson.Field
1350 OfBetaMCPToolResultBlockContent respjson.Field
1351 ErrorCode respjson.Field
1352 Type respjson.Field
1353 Content respjson.Field
1354 ReturnCode respjson.Field
1355 Stderr respjson.Field
1356 Stdout respjson.Field
1357 raw string
1358 } `json:"-"`
1359}
1360
1361func (r *BetaContentBlockUnionContent) UnmarshalJSON(data []byte) error {
1362 return apijson.UnmarshalRoot(data, r)
1363}
1364
1365func NewBetaServerToolUseBlock(id string, input any, name BetaServerToolUseBlockParamName) BetaContentBlockParamUnion {
1366 var serverToolUse BetaServerToolUseBlockParam
1367 serverToolUse.ID = id
1368 serverToolUse.Input = input
1369 serverToolUse.Name = name
1370 return BetaContentBlockParamUnion{OfServerToolUse: &serverToolUse}
1371}
1372
1373func NewBetaWebSearchToolResultBlock[
1374 T []BetaWebSearchResultBlockParam | BetaWebSearchToolRequestErrorParam,
1375](content T, toolUseID string) BetaContentBlockParamUnion {
1376 var webSearchToolResult BetaWebSearchToolResultBlockParam
1377 switch v := any(content).(type) {
1378 case []BetaWebSearchResultBlockParam:
1379 webSearchToolResult.Content.OfResultBlock = v
1380 case BetaWebSearchToolRequestErrorParam:
1381 webSearchToolResult.Content.OfError = &v
1382 }
1383 webSearchToolResult.ToolUseID = toolUseID
1384 return BetaContentBlockParamUnion{OfWebSearchToolResult: &webSearchToolResult}
1385}
1386
1387func NewBetaCodeExecutionToolResultBlock[
1388 T BetaCodeExecutionToolResultErrorParam | BetaCodeExecutionResultBlockParam,
1389](content T, toolUseID string) BetaContentBlockParamUnion {
1390 var codeExecutionToolResult BetaCodeExecutionToolResultBlockParam
1391 switch v := any(content).(type) {
1392 case BetaCodeExecutionToolResultErrorParam:
1393 codeExecutionToolResult.Content.OfError = &v
1394 case BetaCodeExecutionResultBlockParam:
1395 codeExecutionToolResult.Content.OfResultBlock = &v
1396 }
1397 codeExecutionToolResult.ToolUseID = toolUseID
1398 return BetaContentBlockParamUnion{OfCodeExecutionToolResult: &codeExecutionToolResult}
1399}
1400
1401func NewBetaMCPToolResultBlock(toolUseID string) BetaContentBlockParamUnion {
1402 var mcpToolResult BetaRequestMCPToolResultBlockParam
1403 mcpToolResult.ToolUseID = toolUseID
1404 return BetaContentBlockParamUnion{OfMCPToolResult: &mcpToolResult}
1405}
1406
1407func NewBetaTextBlock(text string) BetaContentBlockParamUnion {
1408 var variant BetaTextBlockParam
1409 variant.Text = text
1410 return BetaContentBlockParamUnion{OfText: &variant}
1411}
1412
1413func NewBetaImageBlock[
1414 T BetaBase64ImageSourceParam | BetaURLImageSourceParam | BetaFileImageSourceParam,
1415](source T) BetaContentBlockParamUnion {
1416 var image BetaImageBlockParam
1417 switch v := any(source).(type) {
1418 case BetaBase64ImageSourceParam:
1419 image.Source.OfBase64 = &v
1420 case BetaURLImageSourceParam:
1421 image.Source.OfURL = &v
1422 case BetaFileImageSourceParam:
1423 image.Source.OfFile = &v
1424 }
1425 return BetaContentBlockParamUnion{OfImage: &image}
1426}
1427
1428func NewBetaToolUseBlock(id string, input any, name string) BetaContentBlockParamUnion {
1429 var toolUse BetaToolUseBlockParam
1430 toolUse.ID = id
1431 toolUse.Input = input
1432 toolUse.Name = name
1433 return BetaContentBlockParamUnion{OfToolUse: &toolUse}
1434}
1435
1436func NewBetaToolResultBlock(toolUseID string, content string, isError bool) BetaContentBlockParamUnion {
1437 toolResult := BetaToolResultBlockParam{
1438 Content: []BetaToolResultBlockParamContentUnion{
1439 {OfText: &BetaTextBlockParam{Text: content}},
1440 },
1441 ToolUseID: toolUseID,
1442 IsError: Bool(isError),
1443 }
1444 return BetaContentBlockParamUnion{OfToolResult: &toolResult}
1445}
1446
1447func NewBetaDocumentBlock[
1448 T BetaBase64PDFSourceParam | BetaPlainTextSourceParam | BetaContentBlockSourceParam | BetaURLPDFSourceParam | BetaFileDocumentSourceParam,
1449](source T) BetaContentBlockParamUnion {
1450 var document BetaBase64PDFBlockParam
1451 switch v := any(source).(type) {
1452 case BetaBase64PDFSourceParam:
1453 document.Source.OfBase64 = &v
1454 case BetaPlainTextSourceParam:
1455 document.Source.OfText = &v
1456 case BetaContentBlockSourceParam:
1457 document.Source.OfContent = &v
1458 case BetaURLPDFSourceParam:
1459 document.Source.OfURL = &v
1460 case BetaFileDocumentSourceParam:
1461 document.Source.OfFile = &v
1462 }
1463 return BetaContentBlockParamUnion{OfDocument: &document}
1464}
1465
1466func NewBetaThinkingBlock(signature string, thinking string) BetaContentBlockParamUnion {
1467 var variant BetaThinkingBlockParam
1468 variant.Signature = signature
1469 variant.Thinking = thinking
1470 return BetaContentBlockParamUnion{OfThinking: &variant}
1471}
1472
1473func NewBetaRedactedThinkingBlock(data string) BetaContentBlockParamUnion {
1474 var redactedThinking BetaRedactedThinkingBlockParam
1475 redactedThinking.Data = data
1476 return BetaContentBlockParamUnion{OfRedactedThinking: &redactedThinking}
1477}
1478
1479func NewBetaContainerUploadBlock(fileID string) BetaContentBlockParamUnion {
1480 var containerUpload BetaContainerUploadBlockParam
1481 containerUpload.FileID = fileID
1482 return BetaContentBlockParamUnion{OfContainerUpload: &containerUpload}
1483}
1484
1485// Only one field can be non-zero.
1486//
1487// Use [param.IsOmitted] to confirm if a field is set.
1488type BetaContentBlockParamUnion struct {
1489 OfServerToolUse *BetaServerToolUseBlockParam `json:",omitzero,inline"`
1490 OfWebSearchToolResult *BetaWebSearchToolResultBlockParam `json:",omitzero,inline"`
1491 OfCodeExecutionToolResult *BetaCodeExecutionToolResultBlockParam `json:",omitzero,inline"`
1492 OfMCPToolUse *BetaMCPToolUseBlockParam `json:",omitzero,inline"`
1493 OfMCPToolResult *BetaRequestMCPToolResultBlockParam `json:",omitzero,inline"`
1494 OfText *BetaTextBlockParam `json:",omitzero,inline"`
1495 OfImage *BetaImageBlockParam `json:",omitzero,inline"`
1496 OfToolUse *BetaToolUseBlockParam `json:",omitzero,inline"`
1497 OfToolResult *BetaToolResultBlockParam `json:",omitzero,inline"`
1498 OfDocument *BetaBase64PDFBlockParam `json:",omitzero,inline"`
1499 OfThinking *BetaThinkingBlockParam `json:",omitzero,inline"`
1500 OfRedactedThinking *BetaRedactedThinkingBlockParam `json:",omitzero,inline"`
1501 OfContainerUpload *BetaContainerUploadBlockParam `json:",omitzero,inline"`
1502 paramUnion
1503}
1504
1505func (u BetaContentBlockParamUnion) MarshalJSON() ([]byte, error) {
1506 return param.MarshalUnion(u, u.OfServerToolUse,
1507 u.OfWebSearchToolResult,
1508 u.OfCodeExecutionToolResult,
1509 u.OfMCPToolUse,
1510 u.OfMCPToolResult,
1511 u.OfText,
1512 u.OfImage,
1513 u.OfToolUse,
1514 u.OfToolResult,
1515 u.OfDocument,
1516 u.OfThinking,
1517 u.OfRedactedThinking,
1518 u.OfContainerUpload)
1519}
1520func (u *BetaContentBlockParamUnion) UnmarshalJSON(data []byte) error {
1521 return apijson.UnmarshalRoot(data, u)
1522}
1523
1524func (u *BetaContentBlockParamUnion) asAny() any {
1525 if !param.IsOmitted(u.OfServerToolUse) {
1526 return u.OfServerToolUse
1527 } else if !param.IsOmitted(u.OfWebSearchToolResult) {
1528 return u.OfWebSearchToolResult
1529 } else if !param.IsOmitted(u.OfCodeExecutionToolResult) {
1530 return u.OfCodeExecutionToolResult
1531 } else if !param.IsOmitted(u.OfMCPToolUse) {
1532 return u.OfMCPToolUse
1533 } else if !param.IsOmitted(u.OfMCPToolResult) {
1534 return u.OfMCPToolResult
1535 } else if !param.IsOmitted(u.OfText) {
1536 return u.OfText
1537 } else if !param.IsOmitted(u.OfImage) {
1538 return u.OfImage
1539 } else if !param.IsOmitted(u.OfToolUse) {
1540 return u.OfToolUse
1541 } else if !param.IsOmitted(u.OfToolResult) {
1542 return u.OfToolResult
1543 } else if !param.IsOmitted(u.OfDocument) {
1544 return u.OfDocument
1545 } else if !param.IsOmitted(u.OfThinking) {
1546 return u.OfThinking
1547 } else if !param.IsOmitted(u.OfRedactedThinking) {
1548 return u.OfRedactedThinking
1549 } else if !param.IsOmitted(u.OfContainerUpload) {
1550 return u.OfContainerUpload
1551 }
1552 return nil
1553}
1554
1555// Returns a pointer to the underlying variant's property, if present.
1556func (u BetaContentBlockParamUnion) GetServerName() *string {
1557 if vt := u.OfMCPToolUse; vt != nil {
1558 return &vt.ServerName
1559 }
1560 return nil
1561}
1562
1563// Returns a pointer to the underlying variant's property, if present.
1564func (u BetaContentBlockParamUnion) GetText() *string {
1565 if vt := u.OfText; vt != nil {
1566 return &vt.Text
1567 }
1568 return nil
1569}
1570
1571// Returns a pointer to the underlying variant's property, if present.
1572func (u BetaContentBlockParamUnion) GetContext() *string {
1573 if vt := u.OfDocument; vt != nil && vt.Context.Valid() {
1574 return &vt.Context.Value
1575 }
1576 return nil
1577}
1578
1579// Returns a pointer to the underlying variant's property, if present.
1580func (u BetaContentBlockParamUnion) GetTitle() *string {
1581 if vt := u.OfDocument; vt != nil && vt.Title.Valid() {
1582 return &vt.Title.Value
1583 }
1584 return nil
1585}
1586
1587// Returns a pointer to the underlying variant's property, if present.
1588func (u BetaContentBlockParamUnion) GetSignature() *string {
1589 if vt := u.OfThinking; vt != nil {
1590 return &vt.Signature
1591 }
1592 return nil
1593}
1594
1595// Returns a pointer to the underlying variant's property, if present.
1596func (u BetaContentBlockParamUnion) GetThinking() *string {
1597 if vt := u.OfThinking; vt != nil {
1598 return &vt.Thinking
1599 }
1600 return nil
1601}
1602
1603// Returns a pointer to the underlying variant's property, if present.
1604func (u BetaContentBlockParamUnion) GetData() *string {
1605 if vt := u.OfRedactedThinking; vt != nil {
1606 return &vt.Data
1607 }
1608 return nil
1609}
1610
1611// Returns a pointer to the underlying variant's property, if present.
1612func (u BetaContentBlockParamUnion) GetFileID() *string {
1613 if vt := u.OfContainerUpload; vt != nil {
1614 return &vt.FileID
1615 }
1616 return nil
1617}
1618
1619// Returns a pointer to the underlying variant's property, if present.
1620func (u BetaContentBlockParamUnion) GetID() *string {
1621 if vt := u.OfServerToolUse; vt != nil {
1622 return (*string)(&vt.ID)
1623 } else if vt := u.OfMCPToolUse; vt != nil {
1624 return (*string)(&vt.ID)
1625 } else if vt := u.OfToolUse; vt != nil {
1626 return (*string)(&vt.ID)
1627 }
1628 return nil
1629}
1630
1631// Returns a pointer to the underlying variant's property, if present.
1632func (u BetaContentBlockParamUnion) GetName() *string {
1633 if vt := u.OfServerToolUse; vt != nil {
1634 return (*string)(&vt.Name)
1635 } else if vt := u.OfMCPToolUse; vt != nil {
1636 return (*string)(&vt.Name)
1637 } else if vt := u.OfToolUse; vt != nil {
1638 return (*string)(&vt.Name)
1639 }
1640 return nil
1641}
1642
1643// Returns a pointer to the underlying variant's property, if present.
1644func (u BetaContentBlockParamUnion) GetType() *string {
1645 if vt := u.OfServerToolUse; vt != nil {
1646 return (*string)(&vt.Type)
1647 } else if vt := u.OfWebSearchToolResult; vt != nil {
1648 return (*string)(&vt.Type)
1649 } else if vt := u.OfCodeExecutionToolResult; vt != nil {
1650 return (*string)(&vt.Type)
1651 } else if vt := u.OfMCPToolUse; vt != nil {
1652 return (*string)(&vt.Type)
1653 } else if vt := u.OfMCPToolResult; vt != nil {
1654 return (*string)(&vt.Type)
1655 } else if vt := u.OfText; vt != nil {
1656 return (*string)(&vt.Type)
1657 } else if vt := u.OfImage; vt != nil {
1658 return (*string)(&vt.Type)
1659 } else if vt := u.OfToolUse; vt != nil {
1660 return (*string)(&vt.Type)
1661 } else if vt := u.OfToolResult; vt != nil {
1662 return (*string)(&vt.Type)
1663 } else if vt := u.OfDocument; vt != nil {
1664 return (*string)(&vt.Type)
1665 } else if vt := u.OfThinking; vt != nil {
1666 return (*string)(&vt.Type)
1667 } else if vt := u.OfRedactedThinking; vt != nil {
1668 return (*string)(&vt.Type)
1669 } else if vt := u.OfContainerUpload; vt != nil {
1670 return (*string)(&vt.Type)
1671 }
1672 return nil
1673}
1674
1675// Returns a pointer to the underlying variant's property, if present.
1676func (u BetaContentBlockParamUnion) GetToolUseID() *string {
1677 if vt := u.OfWebSearchToolResult; vt != nil {
1678 return (*string)(&vt.ToolUseID)
1679 } else if vt := u.OfCodeExecutionToolResult; vt != nil {
1680 return (*string)(&vt.ToolUseID)
1681 } else if vt := u.OfMCPToolResult; vt != nil {
1682 return (*string)(&vt.ToolUseID)
1683 } else if vt := u.OfToolResult; vt != nil {
1684 return (*string)(&vt.ToolUseID)
1685 }
1686 return nil
1687}
1688
1689// Returns a pointer to the underlying variant's property, if present.
1690func (u BetaContentBlockParamUnion) GetIsError() *bool {
1691 if vt := u.OfMCPToolResult; vt != nil && vt.IsError.Valid() {
1692 return &vt.IsError.Value
1693 } else if vt := u.OfToolResult; vt != nil && vt.IsError.Valid() {
1694 return &vt.IsError.Value
1695 }
1696 return nil
1697}
1698
1699// Returns a pointer to the underlying variant's Input property, if present.
1700func (u BetaContentBlockParamUnion) GetInput() *any {
1701 if vt := u.OfServerToolUse; vt != nil {
1702 return &vt.Input
1703 } else if vt := u.OfMCPToolUse; vt != nil {
1704 return &vt.Input
1705 } else if vt := u.OfToolUse; vt != nil {
1706 return &vt.Input
1707 }
1708 return nil
1709}
1710
1711// Returns a pointer to the underlying variant's CacheControl property, if present.
1712func (u BetaContentBlockParamUnion) GetCacheControl() *BetaCacheControlEphemeralParam {
1713 if vt := u.OfServerToolUse; vt != nil {
1714 return &vt.CacheControl
1715 } else if vt := u.OfWebSearchToolResult; vt != nil {
1716 return &vt.CacheControl
1717 } else if vt := u.OfCodeExecutionToolResult; vt != nil {
1718 return &vt.CacheControl
1719 } else if vt := u.OfMCPToolUse; vt != nil {
1720 return &vt.CacheControl
1721 } else if vt := u.OfMCPToolResult; vt != nil {
1722 return &vt.CacheControl
1723 } else if vt := u.OfText; vt != nil {
1724 return &vt.CacheControl
1725 } else if vt := u.OfImage; vt != nil {
1726 return &vt.CacheControl
1727 } else if vt := u.OfToolUse; vt != nil {
1728 return &vt.CacheControl
1729 } else if vt := u.OfToolResult; vt != nil {
1730 return &vt.CacheControl
1731 } else if vt := u.OfDocument; vt != nil {
1732 return &vt.CacheControl
1733 } else if vt := u.OfContainerUpload; vt != nil {
1734 return &vt.CacheControl
1735 }
1736 return nil
1737}
1738
1739// Returns a subunion which exports methods to access subproperties
1740//
1741// Or use AsAny() to get the underlying value
1742func (u BetaContentBlockParamUnion) GetContent() (res betaContentBlockParamUnionContent) {
1743 if vt := u.OfWebSearchToolResult; vt != nil {
1744 res.any = vt.Content.asAny()
1745 } else if vt := u.OfCodeExecutionToolResult; vt != nil {
1746 res.any = vt.Content.asAny()
1747 } else if vt := u.OfMCPToolResult; vt != nil {
1748 res.any = vt.Content.asAny()
1749 } else if vt := u.OfToolResult; vt != nil {
1750 res.any = &vt.Content
1751 }
1752 return
1753}
1754
1755// Can have the runtime types [*[]BetaWebSearchResultBlockParam],
1756// [*BetaCodeExecutionToolResultErrorParam], [*BetaCodeExecutionResultBlockParam],
1757// [*string], [_[]BetaTextBlockParam], [_[]BetaToolResultBlockParamContentUnion]
1758type betaContentBlockParamUnionContent struct{ any }
1759
1760// Use the following switch statement to get the type of the union:
1761//
1762// switch u.AsAny().(type) {
1763// case *[]anthropic.BetaWebSearchResultBlockParam:
1764// case *anthropic.BetaCodeExecutionToolResultErrorParam:
1765// case *anthropic.BetaCodeExecutionResultBlockParam:
1766// case *string:
1767// case *[]anthropic.BetaTextBlockParam:
1768// case *[]anthropic.BetaToolResultBlockParamContentUnion:
1769// default:
1770// fmt.Errorf("not present")
1771// }
1772func (u betaContentBlockParamUnionContent) AsAny() any { return u.any }
1773
1774// Returns a pointer to the underlying variant's property, if present.
1775func (u betaContentBlockParamUnionContent) GetContent() []BetaCodeExecutionOutputBlockParam {
1776 switch vt := u.any.(type) {
1777 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1778 return vt.GetContent()
1779 }
1780 return nil
1781}
1782
1783// Returns a pointer to the underlying variant's property, if present.
1784func (u betaContentBlockParamUnionContent) GetReturnCode() *int64 {
1785 switch vt := u.any.(type) {
1786 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1787 return vt.GetReturnCode()
1788 }
1789 return nil
1790}
1791
1792// Returns a pointer to the underlying variant's property, if present.
1793func (u betaContentBlockParamUnionContent) GetStderr() *string {
1794 switch vt := u.any.(type) {
1795 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1796 return vt.GetStderr()
1797 }
1798 return nil
1799}
1800
1801// Returns a pointer to the underlying variant's property, if present.
1802func (u betaContentBlockParamUnionContent) GetStdout() *string {
1803 switch vt := u.any.(type) {
1804 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1805 return vt.GetStdout()
1806 }
1807 return nil
1808}
1809
1810// Returns a pointer to the underlying variant's property, if present.
1811func (u betaContentBlockParamUnionContent) GetErrorCode() *string {
1812 switch vt := u.any.(type) {
1813 case *BetaWebSearchToolResultBlockParamContentUnion:
1814 if vt := vt.OfError; vt != nil {
1815 return (*string)(&vt.ErrorCode)
1816 }
1817 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1818 return vt.GetErrorCode()
1819 }
1820 return nil
1821}
1822
1823// Returns a pointer to the underlying variant's property, if present.
1824func (u betaContentBlockParamUnionContent) GetType() *string {
1825 switch vt := u.any.(type) {
1826 case *BetaWebSearchToolResultBlockParamContentUnion:
1827 if vt := vt.OfError; vt != nil {
1828 return (*string)(&vt.Type)
1829 }
1830 case *BetaCodeExecutionToolResultBlockParamContentUnion:
1831 return vt.GetType()
1832 }
1833 return nil
1834}
1835
1836// Returns a subunion which exports methods to access subproperties
1837//
1838// Or use AsAny() to get the underlying value
1839func (u BetaContentBlockParamUnion) GetCitations() (res betaContentBlockParamUnionCitations) {
1840 if vt := u.OfText; vt != nil {
1841 res.any = &vt.Citations
1842 } else if vt := u.OfDocument; vt != nil {
1843 res.any = &vt.Citations
1844 }
1845 return
1846}
1847
1848// Can have the runtime types [*[]BetaTextCitationParamUnion],
1849// [*BetaCitationsConfigParam]
1850type betaContentBlockParamUnionCitations struct{ any }
1851
1852// Use the following switch statement to get the type of the union:
1853//
1854// switch u.AsAny().(type) {
1855// case *[]anthropic.BetaTextCitationParamUnion:
1856// case *anthropic.BetaCitationsConfigParam:
1857// default:
1858// fmt.Errorf("not present")
1859// }
1860func (u betaContentBlockParamUnionCitations) AsAny() any { return u.any }
1861
1862// Returns a subunion which exports methods to access subproperties
1863//
1864// Or use AsAny() to get the underlying value
1865func (u BetaContentBlockParamUnion) GetSource() (res betaContentBlockParamUnionSource) {
1866 if vt := u.OfImage; vt != nil {
1867 res.any = vt.Source.asAny()
1868 } else if vt := u.OfDocument; vt != nil {
1869 res.any = vt.Source.asAny()
1870 }
1871 return
1872}
1873
1874// Can have the runtime types [*BetaBase64ImageSourceParam],
1875// [*BetaURLImageSourceParam], [*BetaFileImageSourceParam],
1876// [*BetaBase64PDFSourceParam], [*BetaPlainTextSourceParam],
1877// [*BetaContentBlockSourceParam], [*BetaURLPDFSourceParam],
1878// [*BetaFileDocumentSourceParam]
1879type betaContentBlockParamUnionSource struct{ any }
1880
1881// Use the following switch statement to get the type of the union:
1882//
1883// switch u.AsAny().(type) {
1884// case *anthropic.BetaBase64ImageSourceParam:
1885// case *anthropic.BetaURLImageSourceParam:
1886// case *anthropic.BetaFileImageSourceParam:
1887// case *anthropic.BetaBase64PDFSourceParam:
1888// case *anthropic.BetaPlainTextSourceParam:
1889// case *anthropic.BetaContentBlockSourceParam:
1890// case *anthropic.BetaURLPDFSourceParam:
1891// case *anthropic.BetaFileDocumentSourceParam:
1892// default:
1893// fmt.Errorf("not present")
1894// }
1895func (u betaContentBlockParamUnionSource) AsAny() any { return u.any }
1896
1897// Returns a pointer to the underlying variant's property, if present.
1898func (u betaContentBlockParamUnionSource) GetContent() *BetaContentBlockSourceContentUnionParam {
1899 switch vt := u.any.(type) {
1900 case *BetaBase64PDFBlockSourceUnionParam:
1901 return vt.GetContent()
1902 }
1903 return nil
1904}
1905
1906// Returns a pointer to the underlying variant's property, if present.
1907func (u betaContentBlockParamUnionSource) GetData() *string {
1908 switch vt := u.any.(type) {
1909 case *BetaImageBlockParamSourceUnion:
1910 return vt.GetData()
1911 case *BetaBase64PDFBlockSourceUnionParam:
1912 return vt.GetData()
1913 }
1914 return nil
1915}
1916
1917// Returns a pointer to the underlying variant's property, if present.
1918func (u betaContentBlockParamUnionSource) GetMediaType() *string {
1919 switch vt := u.any.(type) {
1920 case *BetaImageBlockParamSourceUnion:
1921 return vt.GetMediaType()
1922 case *BetaBase64PDFBlockSourceUnionParam:
1923 return vt.GetMediaType()
1924 }
1925 return nil
1926}
1927
1928// Returns a pointer to the underlying variant's property, if present.
1929func (u betaContentBlockParamUnionSource) GetType() *string {
1930 switch vt := u.any.(type) {
1931 case *BetaImageBlockParamSourceUnion:
1932 return vt.GetType()
1933 case *BetaBase64PDFBlockSourceUnionParam:
1934 return vt.GetType()
1935 }
1936 return nil
1937}
1938
1939// Returns a pointer to the underlying variant's property, if present.
1940func (u betaContentBlockParamUnionSource) GetURL() *string {
1941 switch vt := u.any.(type) {
1942 case *BetaImageBlockParamSourceUnion:
1943 return vt.GetURL()
1944 case *BetaBase64PDFBlockSourceUnionParam:
1945 return vt.GetURL()
1946 }
1947 return nil
1948}
1949
1950// Returns a pointer to the underlying variant's property, if present.
1951func (u betaContentBlockParamUnionSource) GetFileID() *string {
1952 switch vt := u.any.(type) {
1953 case *BetaImageBlockParamSourceUnion:
1954 return vt.GetFileID()
1955 case *BetaBase64PDFBlockSourceUnionParam:
1956 return vt.GetFileID()
1957 }
1958 return nil
1959}
1960
1961// The properties Content, Type are required.
1962type BetaContentBlockSourceParam struct {
1963 Content BetaContentBlockSourceContentUnionParam `json:"content,omitzero,required"`
1964 // This field can be elided, and will marshal its zero value as "content".
1965 Type constant.Content `json:"type,required"`
1966 paramObj
1967}
1968
1969func (r BetaContentBlockSourceParam) MarshalJSON() (data []byte, err error) {
1970 type shadow BetaContentBlockSourceParam
1971 return param.MarshalObject(r, (*shadow)(&r))
1972}
1973func (r *BetaContentBlockSourceParam) UnmarshalJSON(data []byte) error {
1974 return apijson.UnmarshalRoot(data, r)
1975}
1976
1977// Only one field can be non-zero.
1978//
1979// Use [param.IsOmitted] to confirm if a field is set.
1980type BetaContentBlockSourceContentUnionParam struct {
1981 OfString param.Opt[string] `json:",omitzero,inline"`
1982 OfBetaContentBlockSourceContent []BetaContentBlockSourceContentUnionParam `json:",omitzero,inline"`
1983 paramUnion
1984}
1985
1986func (u BetaContentBlockSourceContentUnionParam) MarshalJSON() ([]byte, error) {
1987 return param.MarshalUnion(u, u.OfString, u.OfBetaContentBlockSourceContent)
1988}
1989func (u *BetaContentBlockSourceContentUnionParam) UnmarshalJSON(data []byte) error {
1990 return apijson.UnmarshalRoot(data, u)
1991}
1992
1993func (u *BetaContentBlockSourceContentUnionParam) asAny() any {
1994 if !param.IsOmitted(u.OfString) {
1995 return &u.OfString.Value
1996 } else if !param.IsOmitted(u.OfBetaContentBlockSourceContent) {
1997 return &u.OfBetaContentBlockSourceContent
1998 }
1999 return nil
2000}
2001
2002// The properties FileID, Type are required.
2003type BetaFileDocumentSourceParam struct {
2004 FileID string `json:"file_id,required"`
2005 // This field can be elided, and will marshal its zero value as "file".
2006 Type constant.File `json:"type,required"`
2007 paramObj
2008}
2009
2010func (r BetaFileDocumentSourceParam) MarshalJSON() (data []byte, err error) {
2011 type shadow BetaFileDocumentSourceParam
2012 return param.MarshalObject(r, (*shadow)(&r))
2013}
2014func (r *BetaFileDocumentSourceParam) UnmarshalJSON(data []byte) error {
2015 return apijson.UnmarshalRoot(data, r)
2016}
2017
2018// The properties FileID, Type are required.
2019type BetaFileImageSourceParam struct {
2020 FileID string `json:"file_id,required"`
2021 // This field can be elided, and will marshal its zero value as "file".
2022 Type constant.File `json:"type,required"`
2023 paramObj
2024}
2025
2026func (r BetaFileImageSourceParam) MarshalJSON() (data []byte, err error) {
2027 type shadow BetaFileImageSourceParam
2028 return param.MarshalObject(r, (*shadow)(&r))
2029}
2030func (r *BetaFileImageSourceParam) UnmarshalJSON(data []byte) error {
2031 return apijson.UnmarshalRoot(data, r)
2032}
2033
2034// The properties Source, Type are required.
2035type BetaImageBlockParam struct {
2036 Source BetaImageBlockParamSourceUnion `json:"source,omitzero,required"`
2037 // Create a cache control breakpoint at this content block.
2038 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
2039 // This field can be elided, and will marshal its zero value as "image".
2040 Type constant.Image `json:"type,required"`
2041 paramObj
2042}
2043
2044func (r BetaImageBlockParam) MarshalJSON() (data []byte, err error) {
2045 type shadow BetaImageBlockParam
2046 return param.MarshalObject(r, (*shadow)(&r))
2047}
2048func (r *BetaImageBlockParam) UnmarshalJSON(data []byte) error {
2049 return apijson.UnmarshalRoot(data, r)
2050}
2051
2052// Only one field can be non-zero.
2053//
2054// Use [param.IsOmitted] to confirm if a field is set.
2055type BetaImageBlockParamSourceUnion struct {
2056 OfBase64 *BetaBase64ImageSourceParam `json:",omitzero,inline"`
2057 OfURL *BetaURLImageSourceParam `json:",omitzero,inline"`
2058 OfFile *BetaFileImageSourceParam `json:",omitzero,inline"`
2059 paramUnion
2060}
2061
2062func (u BetaImageBlockParamSourceUnion) MarshalJSON() ([]byte, error) {
2063 return param.MarshalUnion(u, u.OfBase64, u.OfURL, u.OfFile)
2064}
2065func (u *BetaImageBlockParamSourceUnion) UnmarshalJSON(data []byte) error {
2066 return apijson.UnmarshalRoot(data, u)
2067}
2068
2069func (u *BetaImageBlockParamSourceUnion) asAny() any {
2070 if !param.IsOmitted(u.OfBase64) {
2071 return u.OfBase64
2072 } else if !param.IsOmitted(u.OfURL) {
2073 return u.OfURL
2074 } else if !param.IsOmitted(u.OfFile) {
2075 return u.OfFile
2076 }
2077 return nil
2078}
2079
2080// Returns a pointer to the underlying variant's property, if present.
2081func (u BetaImageBlockParamSourceUnion) GetData() *string {
2082 if vt := u.OfBase64; vt != nil {
2083 return &vt.Data
2084 }
2085 return nil
2086}
2087
2088// Returns a pointer to the underlying variant's property, if present.
2089func (u BetaImageBlockParamSourceUnion) GetMediaType() *string {
2090 if vt := u.OfBase64; vt != nil {
2091 return (*string)(&vt.MediaType)
2092 }
2093 return nil
2094}
2095
2096// Returns a pointer to the underlying variant's property, if present.
2097func (u BetaImageBlockParamSourceUnion) GetURL() *string {
2098 if vt := u.OfURL; vt != nil {
2099 return &vt.URL
2100 }
2101 return nil
2102}
2103
2104// Returns a pointer to the underlying variant's property, if present.
2105func (u BetaImageBlockParamSourceUnion) GetFileID() *string {
2106 if vt := u.OfFile; vt != nil {
2107 return &vt.FileID
2108 }
2109 return nil
2110}
2111
2112// Returns a pointer to the underlying variant's property, if present.
2113func (u BetaImageBlockParamSourceUnion) GetType() *string {
2114 if vt := u.OfBase64; vt != nil {
2115 return (*string)(&vt.Type)
2116 } else if vt := u.OfURL; vt != nil {
2117 return (*string)(&vt.Type)
2118 } else if vt := u.OfFile; vt != nil {
2119 return (*string)(&vt.Type)
2120 }
2121 return nil
2122}
2123
2124type BetaInputJSONDelta struct {
2125 PartialJSON string `json:"partial_json,required"`
2126 Type constant.InputJSONDelta `json:"type,required"`
2127 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2128 JSON struct {
2129 PartialJSON respjson.Field
2130 Type respjson.Field
2131 ExtraFields map[string]respjson.Field
2132 raw string
2133 } `json:"-"`
2134}
2135
2136// Returns the unmodified JSON received from the API
2137func (r BetaInputJSONDelta) RawJSON() string { return r.JSON.raw }
2138func (r *BetaInputJSONDelta) UnmarshalJSON(data []byte) error {
2139 return apijson.UnmarshalRoot(data, r)
2140}
2141
2142type BetaMCPToolResultBlock struct {
2143 Content BetaMCPToolResultBlockContentUnion `json:"content,required"`
2144 IsError bool `json:"is_error,required"`
2145 ToolUseID string `json:"tool_use_id,required"`
2146 Type constant.MCPToolResult `json:"type,required"`
2147 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2148 JSON struct {
2149 Content respjson.Field
2150 IsError respjson.Field
2151 ToolUseID respjson.Field
2152 Type respjson.Field
2153 ExtraFields map[string]respjson.Field
2154 raw string
2155 } `json:"-"`
2156}
2157
2158// Returns the unmodified JSON received from the API
2159func (r BetaMCPToolResultBlock) RawJSON() string { return r.JSON.raw }
2160func (r *BetaMCPToolResultBlock) UnmarshalJSON(data []byte) error {
2161 return apijson.UnmarshalRoot(data, r)
2162}
2163
2164// BetaMCPToolResultBlockContentUnion contains all possible properties and values
2165// from [string], [[]BetaTextBlock].
2166//
2167// Use the methods beginning with 'As' to cast the union to one of its variants.
2168//
2169// If the underlying value is not a json object, one of the following properties
2170// will be valid: OfString OfBetaMCPToolResultBlockContent]
2171type BetaMCPToolResultBlockContentUnion struct {
2172 // This field will be present if the value is a [string] instead of an object.
2173 OfString string `json:",inline"`
2174 // This field will be present if the value is a [[]BetaTextBlock] instead of an
2175 // object.
2176 OfBetaMCPToolResultBlockContent []BetaTextBlock `json:",inline"`
2177 JSON struct {
2178 OfString respjson.Field
2179 OfBetaMCPToolResultBlockContent respjson.Field
2180 raw string
2181 } `json:"-"`
2182}
2183
2184func (u BetaMCPToolResultBlockContentUnion) AsString() (v string) {
2185 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2186 return
2187}
2188
2189func (u BetaMCPToolResultBlockContentUnion) AsBetaMCPToolResultBlockContent() (v []BetaTextBlock) {
2190 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2191 return
2192}
2193
2194// Returns the unmodified JSON received from the API
2195func (u BetaMCPToolResultBlockContentUnion) RawJSON() string { return u.JSON.raw }
2196
2197func (r *BetaMCPToolResultBlockContentUnion) UnmarshalJSON(data []byte) error {
2198 return apijson.UnmarshalRoot(data, r)
2199}
2200
2201type BetaMCPToolUseBlock struct {
2202 ID string `json:"id,required"`
2203 Input any `json:"input,required"`
2204 // The name of the MCP tool
2205 Name string `json:"name,required"`
2206 // The name of the MCP server
2207 ServerName string `json:"server_name,required"`
2208 Type constant.MCPToolUse `json:"type,required"`
2209 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2210 JSON struct {
2211 ID respjson.Field
2212 Input respjson.Field
2213 Name respjson.Field
2214 ServerName respjson.Field
2215 Type respjson.Field
2216 ExtraFields map[string]respjson.Field
2217 raw string
2218 } `json:"-"`
2219}
2220
2221// Returns the unmodified JSON received from the API
2222func (r BetaMCPToolUseBlock) RawJSON() string { return r.JSON.raw }
2223func (r *BetaMCPToolUseBlock) UnmarshalJSON(data []byte) error {
2224 return apijson.UnmarshalRoot(data, r)
2225}
2226
2227// The properties ID, Input, Name, ServerName, Type are required.
2228type BetaMCPToolUseBlockParam struct {
2229 ID string `json:"id,required"`
2230 Input any `json:"input,omitzero,required"`
2231 Name string `json:"name,required"`
2232 // The name of the MCP server
2233 ServerName string `json:"server_name,required"`
2234 // Create a cache control breakpoint at this content block.
2235 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
2236 // This field can be elided, and will marshal its zero value as "mcp_tool_use".
2237 Type constant.MCPToolUse `json:"type,required"`
2238 paramObj
2239}
2240
2241func (r BetaMCPToolUseBlockParam) MarshalJSON() (data []byte, err error) {
2242 type shadow BetaMCPToolUseBlockParam
2243 return param.MarshalObject(r, (*shadow)(&r))
2244}
2245func (r *BetaMCPToolUseBlockParam) UnmarshalJSON(data []byte) error {
2246 return apijson.UnmarshalRoot(data, r)
2247}
2248
2249type BetaMessage struct {
2250 // Unique object identifier.
2251 //
2252 // The format and length of IDs may change over time.
2253 ID string `json:"id,required"`
2254 // Information about the container used in the request (for the code execution
2255 // tool)
2256 Container BetaContainer `json:"container,required"`
2257 // Content generated by the model.
2258 //
2259 // This is an array of content blocks, each of which has a `type` that determines
2260 // its shape.
2261 //
2262 // Example:
2263 //
2264 // ```json
2265 // [{ "type": "text", "text": "Hi, I'm Claude." }]
2266 // ```
2267 //
2268 // If the request input `messages` ended with an `assistant` turn, then the
2269 // response `content` will continue directly from that last turn. You can use this
2270 // to constrain the model's output.
2271 //
2272 // For example, if the input `messages` were:
2273 //
2274 // ```json
2275 // [
2276 //
2277 // {
2278 // "role": "user",
2279 // "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
2280 // },
2281 // { "role": "assistant", "content": "The best answer is (" }
2282 //
2283 // ]
2284 // ```
2285 //
2286 // Then the response `content` might be:
2287 //
2288 // ```json
2289 // [{ "type": "text", "text": "B)" }]
2290 // ```
2291 Content []BetaContentBlockUnion `json:"content,required"`
2292 // The model that will complete your prompt.\n\nSee
2293 // [models](https://docs.anthropic.com/en/docs/models-overview) for additional
2294 // details and options.
2295 Model Model `json:"model,required"`
2296 // Conversational role of the generated message.
2297 //
2298 // This will always be `"assistant"`.
2299 Role constant.Assistant `json:"role,required"`
2300 // The reason that we stopped.
2301 //
2302 // This may be one the following values:
2303 //
2304 // - `"end_turn"`: the model reached a natural stopping point
2305 // - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
2306 // - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
2307 // - `"tool_use"`: the model invoked one or more tools
2308 //
2309 // In non-streaming mode this value is always non-null. In streaming mode, it is
2310 // null in the `message_start` event and non-null otherwise.
2311 //
2312 // Any of "end_turn", "max_tokens", "stop_sequence", "tool_use", "pause_turn",
2313 // "refusal".
2314 StopReason BetaStopReason `json:"stop_reason,required"`
2315 // Which custom stop sequence was generated, if any.
2316 //
2317 // This value will be a non-null string if one of your custom stop sequences was
2318 // generated.
2319 StopSequence string `json:"stop_sequence,required"`
2320 // Object type.
2321 //
2322 // For Messages, this is always `"message"`.
2323 Type constant.Message `json:"type,required"`
2324 // Billing and rate-limit usage.
2325 //
2326 // Anthropic's API bills and rate-limits by token counts, as tokens represent the
2327 // underlying cost to our systems.
2328 //
2329 // Under the hood, the API transforms requests into a format suitable for the
2330 // model. The model's output then goes through a parsing stage before becoming an
2331 // API response. As a result, the token counts in `usage` will not match one-to-one
2332 // with the exact visible content of an API request or response.
2333 //
2334 // For example, `output_tokens` will be non-zero, even for an empty string response
2335 // from Claude.
2336 //
2337 // Total input tokens in a request is the summation of `input_tokens`,
2338 // `cache_creation_input_tokens`, and `cache_read_input_tokens`.
2339 Usage BetaUsage `json:"usage,required"`
2340 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2341 JSON struct {
2342 ID respjson.Field
2343 Container respjson.Field
2344 Content respjson.Field
2345 Model respjson.Field
2346 Role respjson.Field
2347 StopReason respjson.Field
2348 StopSequence respjson.Field
2349 Type respjson.Field
2350 Usage respjson.Field
2351 ExtraFields map[string]respjson.Field
2352 raw string
2353 } `json:"-"`
2354}
2355
2356// Returns the unmodified JSON received from the API
2357func (r BetaMessage) RawJSON() string { return r.JSON.raw }
2358func (r *BetaMessage) UnmarshalJSON(data []byte) error {
2359 return apijson.UnmarshalRoot(data, r)
2360}
2361
2362func (r BetaMessage) ToParam() BetaMessageParam {
2363 var p BetaMessageParam
2364 p.Role = BetaMessageParamRole(r.Role)
2365 p.Content = make([]BetaContentBlockParamUnion, len(r.Content))
2366 for i, c := range r.Content {
2367 contentParams := c.ToParam()
2368 p.Content[i] = contentParams
2369 }
2370 return p
2371}
2372
2373// The reason that we stopped.
2374//
2375// This may be one the following values:
2376//
2377// - `"end_turn"`: the model reached a natural stopping point
2378// - `"max_tokens"`: we exceeded the requested `max_tokens` or the model's maximum
2379// - `"stop_sequence"`: one of your provided custom `stop_sequences` was generated
2380// - `"tool_use"`: the model invoked one or more tools
2381//
2382// In non-streaming mode this value is always non-null. In streaming mode, it is
2383// null in the `message_start` event and non-null otherwise.
2384type BetaMessageStopReason string
2385
2386const (
2387 BetaMessageStopReasonEndTurn BetaMessageStopReason = "end_turn"
2388 BetaMessageStopReasonMaxTokens BetaMessageStopReason = "max_tokens"
2389 BetaMessageStopReasonStopSequence BetaMessageStopReason = "stop_sequence"
2390 BetaMessageStopReasonToolUse BetaMessageStopReason = "tool_use"
2391)
2392
2393type BetaMessageDeltaUsage struct {
2394 // The cumulative number of input tokens used to create the cache entry.
2395 CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,required"`
2396 // The cumulative number of input tokens read from the cache.
2397 CacheReadInputTokens int64 `json:"cache_read_input_tokens,required"`
2398 // The cumulative number of input tokens which were used.
2399 InputTokens int64 `json:"input_tokens,required"`
2400 // The cumulative number of output tokens which were used.
2401 OutputTokens int64 `json:"output_tokens,required"`
2402 // The number of server tool requests.
2403 ServerToolUse BetaServerToolUsage `json:"server_tool_use,required"`
2404 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2405 JSON struct {
2406 CacheCreationInputTokens respjson.Field
2407 CacheReadInputTokens respjson.Field
2408 InputTokens respjson.Field
2409 OutputTokens respjson.Field
2410 ServerToolUse respjson.Field
2411 ExtraFields map[string]respjson.Field
2412 raw string
2413 } `json:"-"`
2414}
2415
2416// Returns the unmodified JSON received from the API
2417func (r BetaMessageDeltaUsage) RawJSON() string { return r.JSON.raw }
2418func (r *BetaMessageDeltaUsage) UnmarshalJSON(data []byte) error {
2419 return apijson.UnmarshalRoot(data, r)
2420}
2421
2422// The properties Content, Role are required.
2423type BetaMessageParam struct {
2424 Content []BetaContentBlockParamUnion `json:"content,omitzero,required"`
2425 // Any of "user", "assistant".
2426 Role BetaMessageParamRole `json:"role,omitzero,required"`
2427 paramObj
2428}
2429
2430func NewBetaUserMessage(blocks ...BetaContentBlockParamUnion) BetaMessageParam {
2431 return BetaMessageParam{
2432 Role: BetaMessageParamRoleUser,
2433 Content: blocks,
2434 }
2435}
2436
2437func (r BetaMessageParam) MarshalJSON() (data []byte, err error) {
2438 type shadow BetaMessageParam
2439 return param.MarshalObject(r, (*shadow)(&r))
2440}
2441func (r *BetaMessageParam) UnmarshalJSON(data []byte) error {
2442 return apijson.UnmarshalRoot(data, r)
2443}
2444
2445type BetaMessageParamRole string
2446
2447const (
2448 BetaMessageParamRoleUser BetaMessageParamRole = "user"
2449 BetaMessageParamRoleAssistant BetaMessageParamRole = "assistant"
2450)
2451
2452type BetaMessageTokensCount struct {
2453 // The total number of tokens across the provided list of messages, system prompt,
2454 // and tools.
2455 InputTokens int64 `json:"input_tokens,required"`
2456 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2457 JSON struct {
2458 InputTokens respjson.Field
2459 ExtraFields map[string]respjson.Field
2460 raw string
2461 } `json:"-"`
2462}
2463
2464// Returns the unmodified JSON received from the API
2465func (r BetaMessageTokensCount) RawJSON() string { return r.JSON.raw }
2466func (r *BetaMessageTokensCount) UnmarshalJSON(data []byte) error {
2467 return apijson.UnmarshalRoot(data, r)
2468}
2469
2470type BetaMetadataParam struct {
2471 // An external identifier for the user who is associated with the request.
2472 //
2473 // This should be a uuid, hash value, or other opaque identifier. Anthropic may use
2474 // this id to help detect abuse. Do not include any identifying information such as
2475 // name, email address, or phone number.
2476 UserID param.Opt[string] `json:"user_id,omitzero"`
2477 paramObj
2478}
2479
2480func (r BetaMetadataParam) MarshalJSON() (data []byte, err error) {
2481 type shadow BetaMetadataParam
2482 return param.MarshalObject(r, (*shadow)(&r))
2483}
2484func (r *BetaMetadataParam) UnmarshalJSON(data []byte) error {
2485 return apijson.UnmarshalRoot(data, r)
2486}
2487
2488// The properties Data, MediaType, Type are required.
2489type BetaPlainTextSourceParam struct {
2490 Data string `json:"data,required"`
2491 // This field can be elided, and will marshal its zero value as "text/plain".
2492 MediaType constant.TextPlain `json:"media_type,required"`
2493 // This field can be elided, and will marshal its zero value as "text".
2494 Type constant.Text `json:"type,required"`
2495 paramObj
2496}
2497
2498func (r BetaPlainTextSourceParam) MarshalJSON() (data []byte, err error) {
2499 type shadow BetaPlainTextSourceParam
2500 return param.MarshalObject(r, (*shadow)(&r))
2501}
2502func (r *BetaPlainTextSourceParam) UnmarshalJSON(data []byte) error {
2503 return apijson.UnmarshalRoot(data, r)
2504}
2505
2506// BetaRawContentBlockDeltaUnion contains all possible properties and values from
2507// [BetaTextDelta], [BetaInputJSONDelta], [BetaCitationsDelta],
2508// [BetaThinkingDelta], [BetaSignatureDelta].
2509//
2510// Use the [BetaRawContentBlockDeltaUnion.AsAny] method to switch on the variant.
2511//
2512// Use the methods beginning with 'As' to cast the union to one of its variants.
2513type BetaRawContentBlockDeltaUnion struct {
2514 // This field is from variant [BetaTextDelta].
2515 Text string `json:"text"`
2516 // Any of "text_delta", "input_json_delta", "citations_delta", "thinking_delta",
2517 // "signature_delta".
2518 Type string `json:"type"`
2519 // This field is from variant [BetaInputJSONDelta].
2520 PartialJSON string `json:"partial_json"`
2521 // This field is from variant [BetaCitationsDelta].
2522 Citation BetaCitationsDeltaCitationUnion `json:"citation"`
2523 // This field is from variant [BetaThinkingDelta].
2524 Thinking string `json:"thinking"`
2525 // This field is from variant [BetaSignatureDelta].
2526 Signature string `json:"signature"`
2527 JSON struct {
2528 Text respjson.Field
2529 Type respjson.Field
2530 PartialJSON respjson.Field
2531 Citation respjson.Field
2532 Thinking respjson.Field
2533 Signature respjson.Field
2534 raw string
2535 } `json:"-"`
2536}
2537
2538// anyBetaRawContentBlockDelta is implemented by each variant of
2539// [BetaRawContentBlockDeltaUnion] to add type safety for the return type of
2540// [BetaRawContentBlockDeltaUnion.AsAny]
2541type anyBetaRawContentBlockDelta interface {
2542 implBetaRawContentBlockDeltaUnion()
2543}
2544
2545func (BetaTextDelta) implBetaRawContentBlockDeltaUnion() {}
2546func (BetaInputJSONDelta) implBetaRawContentBlockDeltaUnion() {}
2547func (BetaCitationsDelta) implBetaRawContentBlockDeltaUnion() {}
2548func (BetaThinkingDelta) implBetaRawContentBlockDeltaUnion() {}
2549func (BetaSignatureDelta) implBetaRawContentBlockDeltaUnion() {}
2550
2551// Use the following switch statement to find the correct variant
2552//
2553// switch variant := BetaRawContentBlockDeltaUnion.AsAny().(type) {
2554// case anthropic.BetaTextDelta:
2555// case anthropic.BetaInputJSONDelta:
2556// case anthropic.BetaCitationsDelta:
2557// case anthropic.BetaThinkingDelta:
2558// case anthropic.BetaSignatureDelta:
2559// default:
2560// fmt.Errorf("no variant present")
2561// }
2562func (u BetaRawContentBlockDeltaUnion) AsAny() anyBetaRawContentBlockDelta {
2563 switch u.Type {
2564 case "text_delta":
2565 return u.AsTextDelta()
2566 case "input_json_delta":
2567 return u.AsInputJSONDelta()
2568 case "citations_delta":
2569 return u.AsCitationsDelta()
2570 case "thinking_delta":
2571 return u.AsThinkingDelta()
2572 case "signature_delta":
2573 return u.AsSignatureDelta()
2574 }
2575 return nil
2576}
2577
2578func (u BetaRawContentBlockDeltaUnion) AsTextDelta() (v BetaTextDelta) {
2579 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2580 return
2581}
2582
2583func (u BetaRawContentBlockDeltaUnion) AsInputJSONDelta() (v BetaInputJSONDelta) {
2584 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2585 return
2586}
2587
2588func (u BetaRawContentBlockDeltaUnion) AsCitationsDelta() (v BetaCitationsDelta) {
2589 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2590 return
2591}
2592
2593func (u BetaRawContentBlockDeltaUnion) AsThinkingDelta() (v BetaThinkingDelta) {
2594 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2595 return
2596}
2597
2598func (u BetaRawContentBlockDeltaUnion) AsSignatureDelta() (v BetaSignatureDelta) {
2599 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2600 return
2601}
2602
2603// Returns the unmodified JSON received from the API
2604func (u BetaRawContentBlockDeltaUnion) RawJSON() string { return u.JSON.raw }
2605
2606func (r *BetaRawContentBlockDeltaUnion) UnmarshalJSON(data []byte) error {
2607 return apijson.UnmarshalRoot(data, r)
2608}
2609
2610type BetaRawContentBlockDeltaEvent struct {
2611 Delta BetaRawContentBlockDeltaUnion `json:"delta,required"`
2612 Index int64 `json:"index,required"`
2613 Type constant.ContentBlockDelta `json:"type,required"`
2614 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2615 JSON struct {
2616 Delta respjson.Field
2617 Index respjson.Field
2618 Type respjson.Field
2619 ExtraFields map[string]respjson.Field
2620 raw string
2621 } `json:"-"`
2622}
2623
2624// Returns the unmodified JSON received from the API
2625func (r BetaRawContentBlockDeltaEvent) RawJSON() string { return r.JSON.raw }
2626func (r *BetaRawContentBlockDeltaEvent) UnmarshalJSON(data []byte) error {
2627 return apijson.UnmarshalRoot(data, r)
2628}
2629
2630type BetaRawContentBlockStartEvent struct {
2631 // Response model for a file uploaded to the container.
2632 ContentBlock BetaRawContentBlockStartEventContentBlockUnion `json:"content_block,required"`
2633 Index int64 `json:"index,required"`
2634 Type constant.ContentBlockStart `json:"type,required"`
2635 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2636 JSON struct {
2637 ContentBlock respjson.Field
2638 Index respjson.Field
2639 Type respjson.Field
2640 ExtraFields map[string]respjson.Field
2641 raw string
2642 } `json:"-"`
2643}
2644
2645// Returns the unmodified JSON received from the API
2646func (r BetaRawContentBlockStartEvent) RawJSON() string { return r.JSON.raw }
2647func (r *BetaRawContentBlockStartEvent) UnmarshalJSON(data []byte) error {
2648 return apijson.UnmarshalRoot(data, r)
2649}
2650
2651// BetaRawContentBlockStartEventContentBlockUnion contains all possible properties
2652// and values from [BetaTextBlock], [BetaToolUseBlock], [BetaServerToolUseBlock],
2653// [BetaWebSearchToolResultBlock], [BetaCodeExecutionToolResultBlock],
2654// [BetaMCPToolUseBlock], [BetaMCPToolResultBlock], [BetaContainerUploadBlock],
2655// [BetaThinkingBlock], [BetaRedactedThinkingBlock].
2656//
2657// Use the [BetaRawContentBlockStartEventContentBlockUnion.AsAny] method to switch
2658// on the variant.
2659//
2660// Use the methods beginning with 'As' to cast the union to one of its variants.
2661type BetaRawContentBlockStartEventContentBlockUnion struct {
2662 // This field is from variant [BetaTextBlock].
2663 Citations []BetaTextCitationUnion `json:"citations"`
2664 // This field is from variant [BetaTextBlock].
2665 Text string `json:"text"`
2666 // Any of "text", "tool_use", "server_tool_use", "web_search_tool_result",
2667 // "code_execution_tool_result", "mcp_tool_use", "mcp_tool_result",
2668 // "container_upload", "thinking", "redacted_thinking".
2669 Type string `json:"type"`
2670 ID string `json:"id"`
2671 Input any `json:"input"`
2672 Name string `json:"name"`
2673 // This field is a union of [BetaWebSearchToolResultBlockContentUnion],
2674 // [BetaCodeExecutionToolResultBlockContentUnion],
2675 // [BetaMCPToolResultBlockContentUnion]
2676 Content BetaRawContentBlockStartEventContentBlockUnionContent `json:"content"`
2677 ToolUseID string `json:"tool_use_id"`
2678 // This field is from variant [BetaMCPToolUseBlock].
2679 ServerName string `json:"server_name"`
2680 // This field is from variant [BetaMCPToolResultBlock].
2681 IsError bool `json:"is_error"`
2682 // This field is from variant [BetaContainerUploadBlock].
2683 FileID string `json:"file_id"`
2684 // This field is from variant [BetaThinkingBlock].
2685 Signature string `json:"signature"`
2686 // This field is from variant [BetaThinkingBlock].
2687 Thinking string `json:"thinking"`
2688 // This field is from variant [BetaRedactedThinkingBlock].
2689 Data string `json:"data"`
2690 JSON struct {
2691 Citations respjson.Field
2692 Text respjson.Field
2693 Type respjson.Field
2694 ID respjson.Field
2695 Input respjson.Field
2696 Name respjson.Field
2697 Content respjson.Field
2698 ToolUseID respjson.Field
2699 ServerName respjson.Field
2700 IsError respjson.Field
2701 FileID respjson.Field
2702 Signature respjson.Field
2703 Thinking respjson.Field
2704 Data respjson.Field
2705 raw string
2706 } `json:"-"`
2707}
2708
2709// anyBetaRawContentBlockStartEventContentBlock is implemented by each variant of
2710// [BetaRawContentBlockStartEventContentBlockUnion] to add type safety for the
2711// return type of [BetaRawContentBlockStartEventContentBlockUnion.AsAny]
2712type anyBetaRawContentBlockStartEventContentBlock interface {
2713 implBetaRawContentBlockStartEventContentBlockUnion()
2714}
2715
2716func (BetaTextBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2717func (BetaToolUseBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2718func (BetaServerToolUseBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2719func (BetaWebSearchToolResultBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2720func (BetaCodeExecutionToolResultBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2721func (BetaMCPToolUseBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2722func (BetaMCPToolResultBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2723func (BetaContainerUploadBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2724func (BetaThinkingBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2725func (BetaRedactedThinkingBlock) implBetaRawContentBlockStartEventContentBlockUnion() {}
2726
2727// Use the following switch statement to find the correct variant
2728//
2729// switch variant := BetaRawContentBlockStartEventContentBlockUnion.AsAny().(type) {
2730// case anthropic.BetaTextBlock:
2731// case anthropic.BetaToolUseBlock:
2732// case anthropic.BetaServerToolUseBlock:
2733// case anthropic.BetaWebSearchToolResultBlock:
2734// case anthropic.BetaCodeExecutionToolResultBlock:
2735// case anthropic.BetaMCPToolUseBlock:
2736// case anthropic.BetaMCPToolResultBlock:
2737// case anthropic.BetaContainerUploadBlock:
2738// case anthropic.BetaThinkingBlock:
2739// case anthropic.BetaRedactedThinkingBlock:
2740// default:
2741// fmt.Errorf("no variant present")
2742// }
2743func (u BetaRawContentBlockStartEventContentBlockUnion) AsAny() anyBetaRawContentBlockStartEventContentBlock {
2744 switch u.Type {
2745 case "text":
2746 return u.AsText()
2747 case "tool_use":
2748 return u.AsToolUse()
2749 case "server_tool_use":
2750 return u.AsServerToolUse()
2751 case "web_search_tool_result":
2752 return u.AsWebSearchToolResult()
2753 case "code_execution_tool_result":
2754 return u.AsCodeExecutionToolResult()
2755 case "mcp_tool_use":
2756 return u.AsMCPToolUse()
2757 case "mcp_tool_result":
2758 return u.AsMCPToolResult()
2759 case "container_upload":
2760 return u.AsContainerUpload()
2761 case "thinking":
2762 return u.AsThinking()
2763 case "redacted_thinking":
2764 return u.AsRedactedThinking()
2765 }
2766 return nil
2767}
2768
2769func (u BetaRawContentBlockStartEventContentBlockUnion) AsText() (v BetaTextBlock) {
2770 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2771 return
2772}
2773
2774func (u BetaRawContentBlockStartEventContentBlockUnion) AsToolUse() (v BetaToolUseBlock) {
2775 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2776 return
2777}
2778
2779func (u BetaRawContentBlockStartEventContentBlockUnion) AsServerToolUse() (v BetaServerToolUseBlock) {
2780 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2781 return
2782}
2783
2784func (u BetaRawContentBlockStartEventContentBlockUnion) AsWebSearchToolResult() (v BetaWebSearchToolResultBlock) {
2785 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2786 return
2787}
2788
2789func (u BetaRawContentBlockStartEventContentBlockUnion) AsCodeExecutionToolResult() (v BetaCodeExecutionToolResultBlock) {
2790 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2791 return
2792}
2793
2794func (u BetaRawContentBlockStartEventContentBlockUnion) AsMCPToolUse() (v BetaMCPToolUseBlock) {
2795 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2796 return
2797}
2798
2799func (u BetaRawContentBlockStartEventContentBlockUnion) AsMCPToolResult() (v BetaMCPToolResultBlock) {
2800 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2801 return
2802}
2803
2804func (u BetaRawContentBlockStartEventContentBlockUnion) AsContainerUpload() (v BetaContainerUploadBlock) {
2805 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2806 return
2807}
2808
2809func (u BetaRawContentBlockStartEventContentBlockUnion) AsThinking() (v BetaThinkingBlock) {
2810 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2811 return
2812}
2813
2814func (u BetaRawContentBlockStartEventContentBlockUnion) AsRedactedThinking() (v BetaRedactedThinkingBlock) {
2815 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
2816 return
2817}
2818
2819// Returns the unmodified JSON received from the API
2820func (u BetaRawContentBlockStartEventContentBlockUnion) RawJSON() string { return u.JSON.raw }
2821
2822func (r *BetaRawContentBlockStartEventContentBlockUnion) UnmarshalJSON(data []byte) error {
2823 return apijson.UnmarshalRoot(data, r)
2824}
2825
2826// BetaRawContentBlockStartEventContentBlockUnionContent is an implicit subunion of
2827// [BetaRawContentBlockStartEventContentBlockUnion].
2828// BetaRawContentBlockStartEventContentBlockUnionContent provides convenient access
2829// to the sub-properties of the union.
2830//
2831// For type safety it is recommended to directly use a variant of the
2832// [BetaRawContentBlockStartEventContentBlockUnion].
2833//
2834// If the underlying value is not a json object, one of the following properties
2835// will be valid: OfBetaWebSearchResultBlockArray OfString
2836// OfBetaMCPToolResultBlockContent]
2837type BetaRawContentBlockStartEventContentBlockUnionContent struct {
2838 // This field will be present if the value is a [[]BetaWebSearchResultBlock]
2839 // instead of an object.
2840 OfBetaWebSearchResultBlockArray []BetaWebSearchResultBlock `json:",inline"`
2841 // This field will be present if the value is a [string] instead of an object.
2842 OfString string `json:",inline"`
2843 // This field will be present if the value is a [[]BetaTextBlock] instead of an
2844 // object.
2845 OfBetaMCPToolResultBlockContent []BetaTextBlock `json:",inline"`
2846 ErrorCode string `json:"error_code"`
2847 Type string `json:"type"`
2848 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
2849 Content []BetaCodeExecutionOutputBlock `json:"content"`
2850 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
2851 ReturnCode int64 `json:"return_code"`
2852 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
2853 Stderr string `json:"stderr"`
2854 // This field is from variant [BetaCodeExecutionToolResultBlockContentUnion].
2855 Stdout string `json:"stdout"`
2856 JSON struct {
2857 OfBetaWebSearchResultBlockArray respjson.Field
2858 OfString respjson.Field
2859 OfBetaMCPToolResultBlockContent respjson.Field
2860 ErrorCode respjson.Field
2861 Type respjson.Field
2862 Content respjson.Field
2863 ReturnCode respjson.Field
2864 Stderr respjson.Field
2865 Stdout respjson.Field
2866 raw string
2867 } `json:"-"`
2868}
2869
2870func (r *BetaRawContentBlockStartEventContentBlockUnionContent) UnmarshalJSON(data []byte) error {
2871 return apijson.UnmarshalRoot(data, r)
2872}
2873
2874type BetaRawContentBlockStopEvent struct {
2875 Index int64 `json:"index,required"`
2876 Type constant.ContentBlockStop `json:"type,required"`
2877 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2878 JSON struct {
2879 Index respjson.Field
2880 Type respjson.Field
2881 ExtraFields map[string]respjson.Field
2882 raw string
2883 } `json:"-"`
2884}
2885
2886// Returns the unmodified JSON received from the API
2887func (r BetaRawContentBlockStopEvent) RawJSON() string { return r.JSON.raw }
2888func (r *BetaRawContentBlockStopEvent) UnmarshalJSON(data []byte) error {
2889 return apijson.UnmarshalRoot(data, r)
2890}
2891
2892type BetaRawMessageDeltaEvent struct {
2893 Delta BetaRawMessageDeltaEventDelta `json:"delta,required"`
2894 Type constant.MessageDelta `json:"type,required"`
2895 // Billing and rate-limit usage.
2896 //
2897 // Anthropic's API bills and rate-limits by token counts, as tokens represent the
2898 // underlying cost to our systems.
2899 //
2900 // Under the hood, the API transforms requests into a format suitable for the
2901 // model. The model's output then goes through a parsing stage before becoming an
2902 // API response. As a result, the token counts in `usage` will not match one-to-one
2903 // with the exact visible content of an API request or response.
2904 //
2905 // For example, `output_tokens` will be non-zero, even for an empty string response
2906 // from Claude.
2907 //
2908 // Total input tokens in a request is the summation of `input_tokens`,
2909 // `cache_creation_input_tokens`, and `cache_read_input_tokens`.
2910 Usage BetaMessageDeltaUsage `json:"usage,required"`
2911 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2912 JSON struct {
2913 Delta respjson.Field
2914 Type respjson.Field
2915 Usage respjson.Field
2916 ExtraFields map[string]respjson.Field
2917 raw string
2918 } `json:"-"`
2919}
2920
2921// Returns the unmodified JSON received from the API
2922func (r BetaRawMessageDeltaEvent) RawJSON() string { return r.JSON.raw }
2923func (r *BetaRawMessageDeltaEvent) UnmarshalJSON(data []byte) error {
2924 return apijson.UnmarshalRoot(data, r)
2925}
2926
2927type BetaRawMessageDeltaEventDelta struct {
2928 // Information about the container used in the request (for the code execution
2929 // tool)
2930 Container BetaContainer `json:"container,required"`
2931 // Any of "end_turn", "max_tokens", "stop_sequence", "tool_use", "pause_turn",
2932 // "refusal".
2933 StopReason BetaStopReason `json:"stop_reason,required"`
2934 StopSequence string `json:"stop_sequence,required"`
2935 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2936 JSON struct {
2937 Container respjson.Field
2938 StopReason respjson.Field
2939 StopSequence respjson.Field
2940 ExtraFields map[string]respjson.Field
2941 raw string
2942 } `json:"-"`
2943}
2944
2945// Returns the unmodified JSON received from the API
2946func (r BetaRawMessageDeltaEventDelta) RawJSON() string { return r.JSON.raw }
2947func (r *BetaRawMessageDeltaEventDelta) UnmarshalJSON(data []byte) error {
2948 return apijson.UnmarshalRoot(data, r)
2949}
2950
2951type BetaRawMessageStartEvent struct {
2952 Message BetaMessage `json:"message,required"`
2953 Type constant.MessageStart `json:"type,required"`
2954 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2955 JSON struct {
2956 Message respjson.Field
2957 Type respjson.Field
2958 ExtraFields map[string]respjson.Field
2959 raw string
2960 } `json:"-"`
2961}
2962
2963// Returns the unmodified JSON received from the API
2964func (r BetaRawMessageStartEvent) RawJSON() string { return r.JSON.raw }
2965func (r *BetaRawMessageStartEvent) UnmarshalJSON(data []byte) error {
2966 return apijson.UnmarshalRoot(data, r)
2967}
2968
2969type BetaRawMessageStopEvent struct {
2970 Type constant.MessageStop `json:"type,required"`
2971 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
2972 JSON struct {
2973 Type respjson.Field
2974 ExtraFields map[string]respjson.Field
2975 raw string
2976 } `json:"-"`
2977}
2978
2979// Returns the unmodified JSON received from the API
2980func (r BetaRawMessageStopEvent) RawJSON() string { return r.JSON.raw }
2981func (r *BetaRawMessageStopEvent) UnmarshalJSON(data []byte) error {
2982 return apijson.UnmarshalRoot(data, r)
2983}
2984
2985// BetaRawMessageStreamEventUnion contains all possible properties and values from
2986// [BetaRawMessageStartEvent], [BetaRawMessageDeltaEvent],
2987// [BetaRawMessageStopEvent], [BetaRawContentBlockStartEvent],
2988// [BetaRawContentBlockDeltaEvent], [BetaRawContentBlockStopEvent].
2989//
2990// Use the [BetaRawMessageStreamEventUnion.AsAny] method to switch on the variant.
2991//
2992// Use the methods beginning with 'As' to cast the union to one of its variants.
2993type BetaRawMessageStreamEventUnion struct {
2994 // This field is from variant [BetaRawMessageStartEvent].
2995 Message BetaMessage `json:"message"`
2996 // Any of "message_start", "message_delta", "message_stop", "content_block_start",
2997 // "content_block_delta", "content_block_stop".
2998 Type string `json:"type"`
2999 // This field is a union of [BetaRawMessageDeltaEventDelta],
3000 // [BetaRawContentBlockDeltaUnion]
3001 Delta BetaRawMessageStreamEventUnionDelta `json:"delta"`
3002 // This field is from variant [BetaRawMessageDeltaEvent].
3003 Usage BetaMessageDeltaUsage `json:"usage"`
3004 // This field is from variant [BetaRawContentBlockStartEvent].
3005 ContentBlock BetaRawContentBlockStartEventContentBlockUnion `json:"content_block"`
3006 Index int64 `json:"index"`
3007 JSON struct {
3008 Message respjson.Field
3009 Type respjson.Field
3010 Delta respjson.Field
3011 Usage respjson.Field
3012 ContentBlock respjson.Field
3013 Index respjson.Field
3014 raw string
3015 } `json:"-"`
3016}
3017
3018// anyBetaRawMessageStreamEvent is implemented by each variant of
3019// [BetaRawMessageStreamEventUnion] to add type safety for the return type of
3020// [BetaRawMessageStreamEventUnion.AsAny]
3021type anyBetaRawMessageStreamEvent interface {
3022 implBetaRawMessageStreamEventUnion()
3023}
3024
3025func (BetaRawMessageStartEvent) implBetaRawMessageStreamEventUnion() {}
3026func (BetaRawMessageDeltaEvent) implBetaRawMessageStreamEventUnion() {}
3027func (BetaRawMessageStopEvent) implBetaRawMessageStreamEventUnion() {}
3028func (BetaRawContentBlockStartEvent) implBetaRawMessageStreamEventUnion() {}
3029func (BetaRawContentBlockDeltaEvent) implBetaRawMessageStreamEventUnion() {}
3030func (BetaRawContentBlockStopEvent) implBetaRawMessageStreamEventUnion() {}
3031
3032// Use the following switch statement to find the correct variant
3033//
3034// switch variant := BetaRawMessageStreamEventUnion.AsAny().(type) {
3035// case anthropic.BetaRawMessageStartEvent:
3036// case anthropic.BetaRawMessageDeltaEvent:
3037// case anthropic.BetaRawMessageStopEvent:
3038// case anthropic.BetaRawContentBlockStartEvent:
3039// case anthropic.BetaRawContentBlockDeltaEvent:
3040// case anthropic.BetaRawContentBlockStopEvent:
3041// default:
3042// fmt.Errorf("no variant present")
3043// }
3044func (u BetaRawMessageStreamEventUnion) AsAny() anyBetaRawMessageStreamEvent {
3045 switch u.Type {
3046 case "message_start":
3047 return u.AsMessageStart()
3048 case "message_delta":
3049 return u.AsMessageDelta()
3050 case "message_stop":
3051 return u.AsMessageStop()
3052 case "content_block_start":
3053 return u.AsContentBlockStart()
3054 case "content_block_delta":
3055 return u.AsContentBlockDelta()
3056 case "content_block_stop":
3057 return u.AsContentBlockStop()
3058 }
3059 return nil
3060}
3061
3062func (u BetaRawMessageStreamEventUnion) AsMessageStart() (v BetaRawMessageStartEvent) {
3063 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3064 return
3065}
3066
3067func (u BetaRawMessageStreamEventUnion) AsMessageDelta() (v BetaRawMessageDeltaEvent) {
3068 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3069 return
3070}
3071
3072func (u BetaRawMessageStreamEventUnion) AsMessageStop() (v BetaRawMessageStopEvent) {
3073 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3074 return
3075}
3076
3077func (u BetaRawMessageStreamEventUnion) AsContentBlockStart() (v BetaRawContentBlockStartEvent) {
3078 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3079 return
3080}
3081
3082func (u BetaRawMessageStreamEventUnion) AsContentBlockDelta() (v BetaRawContentBlockDeltaEvent) {
3083 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3084 return
3085}
3086
3087func (u BetaRawMessageStreamEventUnion) AsContentBlockStop() (v BetaRawContentBlockStopEvent) {
3088 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3089 return
3090}
3091
3092// Returns the unmodified JSON received from the API
3093func (u BetaRawMessageStreamEventUnion) RawJSON() string { return u.JSON.raw }
3094
3095func (r *BetaRawMessageStreamEventUnion) UnmarshalJSON(data []byte) error {
3096 return apijson.UnmarshalRoot(data, r)
3097}
3098
3099// BetaRawMessageStreamEventUnionDelta is an implicit subunion of
3100// [BetaRawMessageStreamEventUnion]. BetaRawMessageStreamEventUnionDelta provides
3101// convenient access to the sub-properties of the union.
3102//
3103// For type safety it is recommended to directly use a variant of the
3104// [BetaRawMessageStreamEventUnion].
3105type BetaRawMessageStreamEventUnionDelta struct {
3106 // This field is from variant [BetaRawMessageDeltaEventDelta].
3107 Container BetaContainer `json:"container"`
3108 // This field is from variant [BetaRawMessageDeltaEventDelta].
3109 StopReason BetaStopReason `json:"stop_reason"`
3110 // This field is from variant [BetaRawMessageDeltaEventDelta].
3111 StopSequence string `json:"stop_sequence"`
3112 // This field is from variant [BetaRawContentBlockDeltaUnion].
3113 Text string `json:"text"`
3114 Type string `json:"type"`
3115 // This field is from variant [BetaRawContentBlockDeltaUnion].
3116 PartialJSON string `json:"partial_json"`
3117 // This field is from variant [BetaRawContentBlockDeltaUnion].
3118 Citation BetaCitationsDeltaCitationUnion `json:"citation"`
3119 // This field is from variant [BetaRawContentBlockDeltaUnion].
3120 Thinking string `json:"thinking"`
3121 // This field is from variant [BetaRawContentBlockDeltaUnion].
3122 Signature string `json:"signature"`
3123 JSON struct {
3124 Container respjson.Field
3125 StopReason respjson.Field
3126 StopSequence respjson.Field
3127 Text respjson.Field
3128 Type respjson.Field
3129 PartialJSON respjson.Field
3130 Citation respjson.Field
3131 Thinking respjson.Field
3132 Signature respjson.Field
3133 raw string
3134 } `json:"-"`
3135}
3136
3137func (r *BetaRawMessageStreamEventUnionDelta) UnmarshalJSON(data []byte) error {
3138 return apijson.UnmarshalRoot(data, r)
3139}
3140
3141// Accumulate builds up the Message incrementally from a MessageStreamEvent. The Message then can be used as
3142// any other Message, except with the caveat that the Message.JSON field which normally can be used to inspect
3143// the JSON sent over the network may not be populated fully.
3144//
3145// message := anthropic.Message{}
3146// for stream.Next() {
3147// event := stream.Current()
3148// message.Accumulate(event)
3149// }
3150func (acc *BetaMessage) Accumulate(event BetaRawMessageStreamEventUnion) error {
3151 if acc == nil {
3152 return fmt.Errorf("accumulate: cannot accumlate into nil Message")
3153 }
3154
3155 switch event := event.AsAny().(type) {
3156 case BetaRawMessageStartEvent:
3157 *acc = event.Message
3158 case BetaRawMessageDeltaEvent:
3159 acc.StopReason = event.Delta.StopReason
3160 acc.StopSequence = event.Delta.StopSequence
3161 acc.Usage.OutputTokens = event.Usage.OutputTokens
3162 case BetaRawMessageStopEvent:
3163 accJson, err := json.Marshal(acc)
3164 if err != nil {
3165 return fmt.Errorf("error converting content block to JSON: %w", err)
3166 }
3167 acc.JSON.raw = string(accJson)
3168 case BetaRawContentBlockStartEvent:
3169 acc.Content = append(acc.Content, BetaContentBlockUnion{})
3170 err := acc.Content[len(acc.Content)-1].UnmarshalJSON([]byte(event.ContentBlock.RawJSON()))
3171 if err != nil {
3172 return err
3173 }
3174 case BetaRawContentBlockDeltaEvent:
3175 if len(acc.Content) == 0 {
3176 return fmt.Errorf("received event of type %s but there was no content block", event.Type)
3177 }
3178 cb := &acc.Content[len(acc.Content)-1]
3179 switch delta := event.Delta.AsAny().(type) {
3180 case BetaTextDelta:
3181 cb.Text += delta.Text
3182 case BetaInputJSONDelta:
3183 if len(delta.PartialJSON) != 0 {
3184 if string(cb.Input) == "{}" {
3185 cb.Input = []byte(delta.PartialJSON)
3186 } else {
3187 cb.Input = append(cb.Input, []byte(delta.PartialJSON)...)
3188 }
3189 }
3190 case BetaThinkingDelta:
3191 cb.Thinking += delta.Thinking
3192 case BetaSignatureDelta:
3193 cb.Signature += delta.Signature
3194 case BetaCitationsDelta:
3195 citation := BetaTextCitationUnion{}
3196 err := citation.UnmarshalJSON([]byte(delta.Citation.RawJSON()))
3197 if err != nil {
3198 return fmt.Errorf("could not unmarshal citation delta into citation type: %w", err)
3199 }
3200 cb.Citations = append(cb.Citations, citation)
3201 }
3202 case BetaRawContentBlockStopEvent:
3203 if len(acc.Content) == 0 {
3204 return fmt.Errorf("received event of type %s but there was no content block", event.Type)
3205 }
3206 contentBlock := &acc.Content[len(acc.Content)-1]
3207 cbJson, err := json.Marshal(contentBlock)
3208 if err != nil {
3209 return fmt.Errorf("error converting content block to JSON: %w", err)
3210 }
3211 contentBlock.JSON.raw = string(cbJson)
3212 }
3213
3214 return nil
3215}
3216
3217type BetaRedactedThinkingBlock struct {
3218 Data string `json:"data,required"`
3219 Type constant.RedactedThinking `json:"type,required"`
3220 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3221 JSON struct {
3222 Data respjson.Field
3223 Type respjson.Field
3224 ExtraFields map[string]respjson.Field
3225 raw string
3226 } `json:"-"`
3227}
3228
3229// Returns the unmodified JSON received from the API
3230func (r BetaRedactedThinkingBlock) RawJSON() string { return r.JSON.raw }
3231func (r *BetaRedactedThinkingBlock) UnmarshalJSON(data []byte) error {
3232 return apijson.UnmarshalRoot(data, r)
3233}
3234
3235func (r BetaRedactedThinkingBlock) ToParam() BetaRedactedThinkingBlockParam {
3236 var p BetaRedactedThinkingBlockParam
3237 p.Type = r.Type
3238 p.Data = r.Data
3239 return p
3240}
3241
3242// The properties Data, Type are required.
3243type BetaRedactedThinkingBlockParam struct {
3244 Data string `json:"data,required"`
3245 // This field can be elided, and will marshal its zero value as
3246 // "redacted_thinking".
3247 Type constant.RedactedThinking `json:"type,required"`
3248 paramObj
3249}
3250
3251func (r BetaRedactedThinkingBlockParam) MarshalJSON() (data []byte, err error) {
3252 type shadow BetaRedactedThinkingBlockParam
3253 return param.MarshalObject(r, (*shadow)(&r))
3254}
3255func (r *BetaRedactedThinkingBlockParam) UnmarshalJSON(data []byte) error {
3256 return apijson.UnmarshalRoot(data, r)
3257}
3258
3259type BetaRequestMCPServerToolConfigurationParam struct {
3260 Enabled param.Opt[bool] `json:"enabled,omitzero"`
3261 AllowedTools []string `json:"allowed_tools,omitzero"`
3262 paramObj
3263}
3264
3265func (r BetaRequestMCPServerToolConfigurationParam) MarshalJSON() (data []byte, err error) {
3266 type shadow BetaRequestMCPServerToolConfigurationParam
3267 return param.MarshalObject(r, (*shadow)(&r))
3268}
3269func (r *BetaRequestMCPServerToolConfigurationParam) UnmarshalJSON(data []byte) error {
3270 return apijson.UnmarshalRoot(data, r)
3271}
3272
3273// The properties Name, Type, URL are required.
3274type BetaRequestMCPServerURLDefinitionParam struct {
3275 Name string `json:"name,required"`
3276 URL string `json:"url,required"`
3277 AuthorizationToken param.Opt[string] `json:"authorization_token,omitzero"`
3278 ToolConfiguration BetaRequestMCPServerToolConfigurationParam `json:"tool_configuration,omitzero"`
3279 // This field can be elided, and will marshal its zero value as "url".
3280 Type constant.URL `json:"type,required"`
3281 paramObj
3282}
3283
3284func (r BetaRequestMCPServerURLDefinitionParam) MarshalJSON() (data []byte, err error) {
3285 type shadow BetaRequestMCPServerURLDefinitionParam
3286 return param.MarshalObject(r, (*shadow)(&r))
3287}
3288func (r *BetaRequestMCPServerURLDefinitionParam) UnmarshalJSON(data []byte) error {
3289 return apijson.UnmarshalRoot(data, r)
3290}
3291
3292// The properties ToolUseID, Type are required.
3293type BetaRequestMCPToolResultBlockParam struct {
3294 ToolUseID string `json:"tool_use_id,required"`
3295 IsError param.Opt[bool] `json:"is_error,omitzero"`
3296 // Create a cache control breakpoint at this content block.
3297 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
3298 Content BetaRequestMCPToolResultBlockParamContentUnion `json:"content,omitzero"`
3299 // This field can be elided, and will marshal its zero value as "mcp_tool_result".
3300 Type constant.MCPToolResult `json:"type,required"`
3301 paramObj
3302}
3303
3304func (r BetaRequestMCPToolResultBlockParam) MarshalJSON() (data []byte, err error) {
3305 type shadow BetaRequestMCPToolResultBlockParam
3306 return param.MarshalObject(r, (*shadow)(&r))
3307}
3308func (r *BetaRequestMCPToolResultBlockParam) UnmarshalJSON(data []byte) error {
3309 return apijson.UnmarshalRoot(data, r)
3310}
3311
3312// Only one field can be non-zero.
3313//
3314// Use [param.IsOmitted] to confirm if a field is set.
3315type BetaRequestMCPToolResultBlockParamContentUnion struct {
3316 OfString param.Opt[string] `json:",omitzero,inline"`
3317 OfBetaMCPToolResultBlockContent []BetaTextBlockParam `json:",omitzero,inline"`
3318 paramUnion
3319}
3320
3321func (u BetaRequestMCPToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
3322 return param.MarshalUnion(u, u.OfString, u.OfBetaMCPToolResultBlockContent)
3323}
3324func (u *BetaRequestMCPToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
3325 return apijson.UnmarshalRoot(data, u)
3326}
3327
3328func (u *BetaRequestMCPToolResultBlockParamContentUnion) asAny() any {
3329 if !param.IsOmitted(u.OfString) {
3330 return &u.OfString.Value
3331 } else if !param.IsOmitted(u.OfBetaMCPToolResultBlockContent) {
3332 return &u.OfBetaMCPToolResultBlockContent
3333 }
3334 return nil
3335}
3336
3337type BetaServerToolUsage struct {
3338 // The number of web search tool requests.
3339 WebSearchRequests int64 `json:"web_search_requests,required"`
3340 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3341 JSON struct {
3342 WebSearchRequests respjson.Field
3343 ExtraFields map[string]respjson.Field
3344 raw string
3345 } `json:"-"`
3346}
3347
3348// Returns the unmodified JSON received from the API
3349func (r BetaServerToolUsage) RawJSON() string { return r.JSON.raw }
3350func (r *BetaServerToolUsage) UnmarshalJSON(data []byte) error {
3351 return apijson.UnmarshalRoot(data, r)
3352}
3353
3354type BetaServerToolUseBlock struct {
3355 ID string `json:"id,required"`
3356 Input any `json:"input,required"`
3357 // Any of "web_search", "code_execution".
3358 Name BetaServerToolUseBlockName `json:"name,required"`
3359 Type constant.ServerToolUse `json:"type,required"`
3360 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3361 JSON struct {
3362 ID respjson.Field
3363 Input respjson.Field
3364 Name respjson.Field
3365 Type respjson.Field
3366 ExtraFields map[string]respjson.Field
3367 raw string
3368 } `json:"-"`
3369}
3370
3371// Returns the unmodified JSON received from the API
3372func (r BetaServerToolUseBlock) RawJSON() string { return r.JSON.raw }
3373func (r *BetaServerToolUseBlock) UnmarshalJSON(data []byte) error {
3374 return apijson.UnmarshalRoot(data, r)
3375}
3376
3377type BetaServerToolUseBlockName string
3378
3379const (
3380 BetaServerToolUseBlockNameWebSearch BetaServerToolUseBlockName = "web_search"
3381 BetaServerToolUseBlockNameCodeExecution BetaServerToolUseBlockName = "code_execution"
3382)
3383
3384// The properties ID, Input, Name, Type are required.
3385type BetaServerToolUseBlockParam struct {
3386 ID string `json:"id,required"`
3387 Input any `json:"input,omitzero,required"`
3388 // Any of "web_search", "code_execution".
3389 Name BetaServerToolUseBlockParamName `json:"name,omitzero,required"`
3390 // Create a cache control breakpoint at this content block.
3391 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
3392 // This field can be elided, and will marshal its zero value as "server_tool_use".
3393 Type constant.ServerToolUse `json:"type,required"`
3394 paramObj
3395}
3396
3397func (r BetaServerToolUseBlockParam) MarshalJSON() (data []byte, err error) {
3398 type shadow BetaServerToolUseBlockParam
3399 return param.MarshalObject(r, (*shadow)(&r))
3400}
3401func (r *BetaServerToolUseBlockParam) UnmarshalJSON(data []byte) error {
3402 return apijson.UnmarshalRoot(data, r)
3403}
3404
3405type BetaServerToolUseBlockParamName string
3406
3407const (
3408 BetaServerToolUseBlockParamNameWebSearch BetaServerToolUseBlockParamName = "web_search"
3409 BetaServerToolUseBlockParamNameCodeExecution BetaServerToolUseBlockParamName = "code_execution"
3410)
3411
3412type BetaSignatureDelta struct {
3413 Signature string `json:"signature,required"`
3414 Type constant.SignatureDelta `json:"type,required"`
3415 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3416 JSON struct {
3417 Signature respjson.Field
3418 Type respjson.Field
3419 ExtraFields map[string]respjson.Field
3420 raw string
3421 } `json:"-"`
3422}
3423
3424// Returns the unmodified JSON received from the API
3425func (r BetaSignatureDelta) RawJSON() string { return r.JSON.raw }
3426func (r *BetaSignatureDelta) UnmarshalJSON(data []byte) error {
3427 return apijson.UnmarshalRoot(data, r)
3428}
3429
3430type BetaStopReason string
3431
3432const (
3433 BetaStopReasonEndTurn BetaStopReason = "end_turn"
3434 BetaStopReasonMaxTokens BetaStopReason = "max_tokens"
3435 BetaStopReasonStopSequence BetaStopReason = "stop_sequence"
3436 BetaStopReasonToolUse BetaStopReason = "tool_use"
3437 BetaStopReasonPauseTurn BetaStopReason = "pause_turn"
3438 BetaStopReasonRefusal BetaStopReason = "refusal"
3439)
3440
3441type BetaTextBlock struct {
3442 // Citations supporting the text block.
3443 //
3444 // The type of citation returned will depend on the type of document being cited.
3445 // Citing a PDF results in `page_location`, plain text results in `char_location`,
3446 // and content document results in `content_block_location`.
3447 Citations []BetaTextCitationUnion `json:"citations,required"`
3448 Text string `json:"text,required"`
3449 Type constant.Text `json:"type,required"`
3450 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3451 JSON struct {
3452 Citations respjson.Field
3453 Text respjson.Field
3454 Type respjson.Field
3455 ExtraFields map[string]respjson.Field
3456 raw string
3457 } `json:"-"`
3458}
3459
3460// Returns the unmodified JSON received from the API
3461func (r BetaTextBlock) RawJSON() string { return r.JSON.raw }
3462func (r *BetaTextBlock) UnmarshalJSON(data []byte) error {
3463 return apijson.UnmarshalRoot(data, r)
3464}
3465
3466func (r BetaTextBlock) ToParam() BetaTextBlockParam {
3467 var p BetaTextBlockParam
3468 p.Type = r.Type
3469 p.Text = r.Text
3470
3471 // Distinguish between a nil and zero length slice, since some compatible
3472 // APIs may not require citations.
3473 if r.Citations != nil {
3474 p.Citations = make([]BetaTextCitationParamUnion, len(r.Citations))
3475 }
3476
3477 for i, citation := range r.Citations {
3478 switch citationVariant := citation.AsAny().(type) {
3479 case BetaCitationCharLocation:
3480 var citationParam BetaCitationCharLocationParam
3481 citationParam.Type = citationVariant.Type
3482 citationParam.DocumentTitle = paramutil.ToOpt(citationVariant.DocumentTitle, citationVariant.JSON.DocumentTitle)
3483 citationParam.CitedText = citationVariant.CitedText
3484 citationParam.DocumentIndex = citationVariant.DocumentIndex
3485 citationParam.EndCharIndex = citationVariant.EndCharIndex
3486 citationParam.StartCharIndex = citationVariant.StartCharIndex
3487 p.Citations[i] = BetaTextCitationParamUnion{OfCharLocation: &citationParam}
3488 case BetaCitationPageLocation:
3489 var citationParam BetaCitationPageLocationParam
3490 citationParam.Type = citationVariant.Type
3491 citationParam.DocumentTitle = paramutil.ToOpt(citationVariant.DocumentTitle, citationVariant.JSON.DocumentTitle)
3492 citationParam.DocumentIndex = citationVariant.DocumentIndex
3493 citationParam.EndPageNumber = citationVariant.EndPageNumber
3494 citationParam.StartPageNumber = citationVariant.StartPageNumber
3495 p.Citations[i] = BetaTextCitationParamUnion{OfPageLocation: &citationParam}
3496 case BetaCitationContentBlockLocation:
3497 var citationParam BetaCitationContentBlockLocationParam
3498 citationParam.Type = citationVariant.Type
3499 citationParam.DocumentTitle = paramutil.ToOpt(citationVariant.DocumentTitle, citationVariant.JSON.DocumentTitle)
3500 citationParam.CitedText = citationVariant.CitedText
3501 citationParam.DocumentIndex = citationVariant.DocumentIndex
3502 citationParam.EndBlockIndex = citationVariant.EndBlockIndex
3503 citationParam.StartBlockIndex = citationVariant.StartBlockIndex
3504 p.Citations[i] = BetaTextCitationParamUnion{OfContentBlockLocation: &citationParam}
3505 }
3506 }
3507 return p
3508}
3509
3510// The properties Text, Type are required.
3511type BetaTextBlockParam struct {
3512 Text string `json:"text,required"`
3513 Citations []BetaTextCitationParamUnion `json:"citations,omitzero"`
3514 // Create a cache control breakpoint at this content block.
3515 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
3516 // This field can be elided, and will marshal its zero value as "text".
3517 Type constant.Text `json:"type,required"`
3518 paramObj
3519}
3520
3521func (r BetaTextBlockParam) MarshalJSON() (data []byte, err error) {
3522 type shadow BetaTextBlockParam
3523 return param.MarshalObject(r, (*shadow)(&r))
3524}
3525func (r *BetaTextBlockParam) UnmarshalJSON(data []byte) error {
3526 return apijson.UnmarshalRoot(data, r)
3527}
3528
3529// BetaTextCitationUnion contains all possible properties and values from
3530// [BetaCitationCharLocation], [BetaCitationPageLocation],
3531// [BetaCitationContentBlockLocation], [BetaCitationsWebSearchResultLocation].
3532//
3533// Use the [BetaTextCitationUnion.AsAny] method to switch on the variant.
3534//
3535// Use the methods beginning with 'As' to cast the union to one of its variants.
3536type BetaTextCitationUnion struct {
3537 CitedText string `json:"cited_text"`
3538 DocumentIndex int64 `json:"document_index"`
3539 DocumentTitle string `json:"document_title"`
3540 // This field is from variant [BetaCitationCharLocation].
3541 EndCharIndex int64 `json:"end_char_index"`
3542 // This field is from variant [BetaCitationCharLocation].
3543 StartCharIndex int64 `json:"start_char_index"`
3544 // Any of "char_location", "page_location", "content_block_location",
3545 // "web_search_result_location".
3546 Type string `json:"type"`
3547 // This field is from variant [BetaCitationPageLocation].
3548 EndPageNumber int64 `json:"end_page_number"`
3549 // This field is from variant [BetaCitationPageLocation].
3550 StartPageNumber int64 `json:"start_page_number"`
3551 // This field is from variant [BetaCitationContentBlockLocation].
3552 EndBlockIndex int64 `json:"end_block_index"`
3553 // This field is from variant [BetaCitationContentBlockLocation].
3554 StartBlockIndex int64 `json:"start_block_index"`
3555 // This field is from variant [BetaCitationsWebSearchResultLocation].
3556 EncryptedIndex string `json:"encrypted_index"`
3557 // This field is from variant [BetaCitationsWebSearchResultLocation].
3558 Title string `json:"title"`
3559 // This field is from variant [BetaCitationsWebSearchResultLocation].
3560 URL string `json:"url"`
3561 JSON struct {
3562 CitedText respjson.Field
3563 DocumentIndex respjson.Field
3564 DocumentTitle respjson.Field
3565 EndCharIndex respjson.Field
3566 StartCharIndex respjson.Field
3567 Type respjson.Field
3568 EndPageNumber respjson.Field
3569 StartPageNumber respjson.Field
3570 EndBlockIndex respjson.Field
3571 StartBlockIndex respjson.Field
3572 EncryptedIndex respjson.Field
3573 Title respjson.Field
3574 URL respjson.Field
3575 raw string
3576 } `json:"-"`
3577}
3578
3579// anyBetaTextCitation is implemented by each variant of [BetaTextCitationUnion] to
3580// add type safety for the return type of [BetaTextCitationUnion.AsAny]
3581type anyBetaTextCitation interface {
3582 implBetaTextCitationUnion()
3583}
3584
3585func (BetaCitationCharLocation) implBetaTextCitationUnion() {}
3586func (BetaCitationPageLocation) implBetaTextCitationUnion() {}
3587func (BetaCitationContentBlockLocation) implBetaTextCitationUnion() {}
3588func (BetaCitationsWebSearchResultLocation) implBetaTextCitationUnion() {}
3589
3590// Use the following switch statement to find the correct variant
3591//
3592// switch variant := BetaTextCitationUnion.AsAny().(type) {
3593// case anthropic.BetaCitationCharLocation:
3594// case anthropic.BetaCitationPageLocation:
3595// case anthropic.BetaCitationContentBlockLocation:
3596// case anthropic.BetaCitationsWebSearchResultLocation:
3597// default:
3598// fmt.Errorf("no variant present")
3599// }
3600func (u BetaTextCitationUnion) AsAny() anyBetaTextCitation {
3601 switch u.Type {
3602 case "char_location":
3603 return u.AsCharLocation()
3604 case "page_location":
3605 return u.AsPageLocation()
3606 case "content_block_location":
3607 return u.AsContentBlockLocation()
3608 case "web_search_result_location":
3609 return u.AsWebSearchResultLocation()
3610 }
3611 return nil
3612}
3613
3614func (u BetaTextCitationUnion) AsCharLocation() (v BetaCitationCharLocation) {
3615 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3616 return
3617}
3618
3619func (u BetaTextCitationUnion) AsPageLocation() (v BetaCitationPageLocation) {
3620 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3621 return
3622}
3623
3624func (u BetaTextCitationUnion) AsContentBlockLocation() (v BetaCitationContentBlockLocation) {
3625 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3626 return
3627}
3628
3629func (u BetaTextCitationUnion) AsWebSearchResultLocation() (v BetaCitationsWebSearchResultLocation) {
3630 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
3631 return
3632}
3633
3634// Returns the unmodified JSON received from the API
3635func (u BetaTextCitationUnion) RawJSON() string { return u.JSON.raw }
3636
3637func (r *BetaTextCitationUnion) UnmarshalJSON(data []byte) error {
3638 return apijson.UnmarshalRoot(data, r)
3639}
3640
3641// Only one field can be non-zero.
3642//
3643// Use [param.IsOmitted] to confirm if a field is set.
3644type BetaTextCitationParamUnion struct {
3645 OfCharLocation *BetaCitationCharLocationParam `json:",omitzero,inline"`
3646 OfPageLocation *BetaCitationPageLocationParam `json:",omitzero,inline"`
3647 OfContentBlockLocation *BetaCitationContentBlockLocationParam `json:",omitzero,inline"`
3648 OfWebSearchResultLocation *BetaCitationWebSearchResultLocationParam `json:",omitzero,inline"`
3649 paramUnion
3650}
3651
3652func (u BetaTextCitationParamUnion) MarshalJSON() ([]byte, error) {
3653 return param.MarshalUnion(u, u.OfCharLocation, u.OfPageLocation, u.OfContentBlockLocation, u.OfWebSearchResultLocation)
3654}
3655func (u *BetaTextCitationParamUnion) UnmarshalJSON(data []byte) error {
3656 return apijson.UnmarshalRoot(data, u)
3657}
3658
3659func (u *BetaTextCitationParamUnion) asAny() any {
3660 if !param.IsOmitted(u.OfCharLocation) {
3661 return u.OfCharLocation
3662 } else if !param.IsOmitted(u.OfPageLocation) {
3663 return u.OfPageLocation
3664 } else if !param.IsOmitted(u.OfContentBlockLocation) {
3665 return u.OfContentBlockLocation
3666 } else if !param.IsOmitted(u.OfWebSearchResultLocation) {
3667 return u.OfWebSearchResultLocation
3668 }
3669 return nil
3670}
3671
3672// Returns a pointer to the underlying variant's property, if present.
3673func (u BetaTextCitationParamUnion) GetEndCharIndex() *int64 {
3674 if vt := u.OfCharLocation; vt != nil {
3675 return &vt.EndCharIndex
3676 }
3677 return nil
3678}
3679
3680// Returns a pointer to the underlying variant's property, if present.
3681func (u BetaTextCitationParamUnion) GetStartCharIndex() *int64 {
3682 if vt := u.OfCharLocation; vt != nil {
3683 return &vt.StartCharIndex
3684 }
3685 return nil
3686}
3687
3688// Returns a pointer to the underlying variant's property, if present.
3689func (u BetaTextCitationParamUnion) GetEndPageNumber() *int64 {
3690 if vt := u.OfPageLocation; vt != nil {
3691 return &vt.EndPageNumber
3692 }
3693 return nil
3694}
3695
3696// Returns a pointer to the underlying variant's property, if present.
3697func (u BetaTextCitationParamUnion) GetStartPageNumber() *int64 {
3698 if vt := u.OfPageLocation; vt != nil {
3699 return &vt.StartPageNumber
3700 }
3701 return nil
3702}
3703
3704// Returns a pointer to the underlying variant's property, if present.
3705func (u BetaTextCitationParamUnion) GetEndBlockIndex() *int64 {
3706 if vt := u.OfContentBlockLocation; vt != nil {
3707 return &vt.EndBlockIndex
3708 }
3709 return nil
3710}
3711
3712// Returns a pointer to the underlying variant's property, if present.
3713func (u BetaTextCitationParamUnion) GetStartBlockIndex() *int64 {
3714 if vt := u.OfContentBlockLocation; vt != nil {
3715 return &vt.StartBlockIndex
3716 }
3717 return nil
3718}
3719
3720// Returns a pointer to the underlying variant's property, if present.
3721func (u BetaTextCitationParamUnion) GetEncryptedIndex() *string {
3722 if vt := u.OfWebSearchResultLocation; vt != nil {
3723 return &vt.EncryptedIndex
3724 }
3725 return nil
3726}
3727
3728// Returns a pointer to the underlying variant's property, if present.
3729func (u BetaTextCitationParamUnion) GetTitle() *string {
3730 if vt := u.OfWebSearchResultLocation; vt != nil && vt.Title.Valid() {
3731 return &vt.Title.Value
3732 }
3733 return nil
3734}
3735
3736// Returns a pointer to the underlying variant's property, if present.
3737func (u BetaTextCitationParamUnion) GetURL() *string {
3738 if vt := u.OfWebSearchResultLocation; vt != nil {
3739 return &vt.URL
3740 }
3741 return nil
3742}
3743
3744// Returns a pointer to the underlying variant's property, if present.
3745func (u BetaTextCitationParamUnion) GetCitedText() *string {
3746 if vt := u.OfCharLocation; vt != nil {
3747 return (*string)(&vt.CitedText)
3748 } else if vt := u.OfPageLocation; vt != nil {
3749 return (*string)(&vt.CitedText)
3750 } else if vt := u.OfContentBlockLocation; vt != nil {
3751 return (*string)(&vt.CitedText)
3752 } else if vt := u.OfWebSearchResultLocation; vt != nil {
3753 return (*string)(&vt.CitedText)
3754 }
3755 return nil
3756}
3757
3758// Returns a pointer to the underlying variant's property, if present.
3759func (u BetaTextCitationParamUnion) GetDocumentIndex() *int64 {
3760 if vt := u.OfCharLocation; vt != nil {
3761 return (*int64)(&vt.DocumentIndex)
3762 } else if vt := u.OfPageLocation; vt != nil {
3763 return (*int64)(&vt.DocumentIndex)
3764 } else if vt := u.OfContentBlockLocation; vt != nil {
3765 return (*int64)(&vt.DocumentIndex)
3766 }
3767 return nil
3768}
3769
3770// Returns a pointer to the underlying variant's property, if present.
3771func (u BetaTextCitationParamUnion) GetDocumentTitle() *string {
3772 if vt := u.OfCharLocation; vt != nil && vt.DocumentTitle.Valid() {
3773 return &vt.DocumentTitle.Value
3774 } else if vt := u.OfPageLocation; vt != nil && vt.DocumentTitle.Valid() {
3775 return &vt.DocumentTitle.Value
3776 } else if vt := u.OfContentBlockLocation; vt != nil && vt.DocumentTitle.Valid() {
3777 return &vt.DocumentTitle.Value
3778 }
3779 return nil
3780}
3781
3782// Returns a pointer to the underlying variant's property, if present.
3783func (u BetaTextCitationParamUnion) GetType() *string {
3784 if vt := u.OfCharLocation; vt != nil {
3785 return (*string)(&vt.Type)
3786 } else if vt := u.OfPageLocation; vt != nil {
3787 return (*string)(&vt.Type)
3788 } else if vt := u.OfContentBlockLocation; vt != nil {
3789 return (*string)(&vt.Type)
3790 } else if vt := u.OfWebSearchResultLocation; vt != nil {
3791 return (*string)(&vt.Type)
3792 }
3793 return nil
3794}
3795
3796type BetaTextDelta struct {
3797 Text string `json:"text,required"`
3798 Type constant.TextDelta `json:"type,required"`
3799 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3800 JSON struct {
3801 Text respjson.Field
3802 Type respjson.Field
3803 ExtraFields map[string]respjson.Field
3804 raw string
3805 } `json:"-"`
3806}
3807
3808// Returns the unmodified JSON received from the API
3809func (r BetaTextDelta) RawJSON() string { return r.JSON.raw }
3810func (r *BetaTextDelta) UnmarshalJSON(data []byte) error {
3811 return apijson.UnmarshalRoot(data, r)
3812}
3813
3814type BetaThinkingBlock struct {
3815 Signature string `json:"signature,required"`
3816 Thinking string `json:"thinking,required"`
3817 Type constant.Thinking `json:"type,required"`
3818 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3819 JSON struct {
3820 Signature respjson.Field
3821 Thinking respjson.Field
3822 Type respjson.Field
3823 ExtraFields map[string]respjson.Field
3824 raw string
3825 } `json:"-"`
3826}
3827
3828// Returns the unmodified JSON received from the API
3829func (r BetaThinkingBlock) RawJSON() string { return r.JSON.raw }
3830func (r *BetaThinkingBlock) UnmarshalJSON(data []byte) error {
3831 return apijson.UnmarshalRoot(data, r)
3832}
3833
3834func (r BetaThinkingBlock) ToParam() BetaThinkingBlockParam {
3835 var p BetaThinkingBlockParam
3836 p.Type = r.Type
3837 p.Signature = r.Signature
3838 p.Thinking = r.Thinking
3839 return p
3840}
3841
3842// The properties Signature, Thinking, Type are required.
3843type BetaThinkingBlockParam struct {
3844 Signature string `json:"signature,required"`
3845 Thinking string `json:"thinking,required"`
3846 // This field can be elided, and will marshal its zero value as "thinking".
3847 Type constant.Thinking `json:"type,required"`
3848 paramObj
3849}
3850
3851func (r BetaThinkingBlockParam) MarshalJSON() (data []byte, err error) {
3852 type shadow BetaThinkingBlockParam
3853 return param.MarshalObject(r, (*shadow)(&r))
3854}
3855func (r *BetaThinkingBlockParam) UnmarshalJSON(data []byte) error {
3856 return apijson.UnmarshalRoot(data, r)
3857}
3858
3859func NewBetaThinkingConfigDisabledParam() BetaThinkingConfigDisabledParam {
3860 return BetaThinkingConfigDisabledParam{
3861 Type: "disabled",
3862 }
3863}
3864
3865// This struct has a constant value, construct it with
3866// [NewBetaThinkingConfigDisabledParam].
3867type BetaThinkingConfigDisabledParam struct {
3868 Type constant.Disabled `json:"type,required"`
3869 paramObj
3870}
3871
3872func (r BetaThinkingConfigDisabledParam) MarshalJSON() (data []byte, err error) {
3873 type shadow BetaThinkingConfigDisabledParam
3874 return param.MarshalObject(r, (*shadow)(&r))
3875}
3876func (r *BetaThinkingConfigDisabledParam) UnmarshalJSON(data []byte) error {
3877 return apijson.UnmarshalRoot(data, r)
3878}
3879
3880// The properties BudgetTokens, Type are required.
3881type BetaThinkingConfigEnabledParam struct {
3882 // Determines how many tokens Claude can use for its internal reasoning process.
3883 // Larger budgets can enable more thorough analysis for complex problems, improving
3884 // response quality.
3885 //
3886 // Must be ≥1024 and less than `max_tokens`.
3887 //
3888 // See
3889 // [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
3890 // for details.
3891 BudgetTokens int64 `json:"budget_tokens,required"`
3892 // This field can be elided, and will marshal its zero value as "enabled".
3893 Type constant.Enabled `json:"type,required"`
3894 paramObj
3895}
3896
3897func (r BetaThinkingConfigEnabledParam) MarshalJSON() (data []byte, err error) {
3898 type shadow BetaThinkingConfigEnabledParam
3899 return param.MarshalObject(r, (*shadow)(&r))
3900}
3901func (r *BetaThinkingConfigEnabledParam) UnmarshalJSON(data []byte) error {
3902 return apijson.UnmarshalRoot(data, r)
3903}
3904
3905func BetaThinkingConfigParamOfEnabled(budgetTokens int64) BetaThinkingConfigParamUnion {
3906 var enabled BetaThinkingConfigEnabledParam
3907 enabled.BudgetTokens = budgetTokens
3908 return BetaThinkingConfigParamUnion{OfEnabled: &enabled}
3909}
3910
3911// Only one field can be non-zero.
3912//
3913// Use [param.IsOmitted] to confirm if a field is set.
3914type BetaThinkingConfigParamUnion struct {
3915 OfEnabled *BetaThinkingConfigEnabledParam `json:",omitzero,inline"`
3916 OfDisabled *BetaThinkingConfigDisabledParam `json:",omitzero,inline"`
3917 paramUnion
3918}
3919
3920func (u BetaThinkingConfigParamUnion) MarshalJSON() ([]byte, error) {
3921 return param.MarshalUnion(u, u.OfEnabled, u.OfDisabled)
3922}
3923func (u *BetaThinkingConfigParamUnion) UnmarshalJSON(data []byte) error {
3924 return apijson.UnmarshalRoot(data, u)
3925}
3926
3927func (u *BetaThinkingConfigParamUnion) asAny() any {
3928 if !param.IsOmitted(u.OfEnabled) {
3929 return u.OfEnabled
3930 } else if !param.IsOmitted(u.OfDisabled) {
3931 return u.OfDisabled
3932 }
3933 return nil
3934}
3935
3936// Returns a pointer to the underlying variant's property, if present.
3937func (u BetaThinkingConfigParamUnion) GetBudgetTokens() *int64 {
3938 if vt := u.OfEnabled; vt != nil {
3939 return &vt.BudgetTokens
3940 }
3941 return nil
3942}
3943
3944// Returns a pointer to the underlying variant's property, if present.
3945func (u BetaThinkingConfigParamUnion) GetType() *string {
3946 if vt := u.OfEnabled; vt != nil {
3947 return (*string)(&vt.Type)
3948 } else if vt := u.OfDisabled; vt != nil {
3949 return (*string)(&vt.Type)
3950 }
3951 return nil
3952}
3953
3954type BetaThinkingDelta struct {
3955 Thinking string `json:"thinking,required"`
3956 Type constant.ThinkingDelta `json:"type,required"`
3957 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
3958 JSON struct {
3959 Thinking respjson.Field
3960 Type respjson.Field
3961 ExtraFields map[string]respjson.Field
3962 raw string
3963 } `json:"-"`
3964}
3965
3966// Returns the unmodified JSON received from the API
3967func (r BetaThinkingDelta) RawJSON() string { return r.JSON.raw }
3968func (r *BetaThinkingDelta) UnmarshalJSON(data []byte) error {
3969 return apijson.UnmarshalRoot(data, r)
3970}
3971
3972// The properties InputSchema, Name are required.
3973type BetaToolParam struct {
3974 // [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
3975 //
3976 // This defines the shape of the `input` that your tool accepts and that the model
3977 // will produce.
3978 InputSchema BetaToolInputSchemaParam `json:"input_schema,omitzero,required"`
3979 // Name of the tool.
3980 //
3981 // This is how the tool will be called by the model and in `tool_use` blocks.
3982 Name string `json:"name,required"`
3983 // Description of what this tool does.
3984 //
3985 // Tool descriptions should be as detailed as possible. The more information that
3986 // the model has about what the tool is and how to use it, the better it will
3987 // perform. You can use natural language descriptions to reinforce important
3988 // aspects of the tool input JSON schema.
3989 Description param.Opt[string] `json:"description,omitzero"`
3990 // Any of "custom".
3991 Type BetaToolType `json:"type,omitzero"`
3992 // Create a cache control breakpoint at this content block.
3993 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
3994 paramObj
3995}
3996
3997func (r BetaToolParam) MarshalJSON() (data []byte, err error) {
3998 type shadow BetaToolParam
3999 return param.MarshalObject(r, (*shadow)(&r))
4000}
4001func (r *BetaToolParam) UnmarshalJSON(data []byte) error {
4002 return apijson.UnmarshalRoot(data, r)
4003}
4004
4005// [JSON schema](https://json-schema.org/draft/2020-12) for this tool's input.
4006//
4007// This defines the shape of the `input` that your tool accepts and that the model
4008// will produce.
4009//
4010// The property Type is required.
4011type BetaToolInputSchemaParam struct {
4012 Properties any `json:"properties,omitzero"`
4013 Required []string `json:"required,omitzero"`
4014 // This field can be elided, and will marshal its zero value as "object".
4015 Type constant.Object `json:"type,required"`
4016 ExtraFields map[string]any `json:"-"`
4017 paramObj
4018}
4019
4020func (r BetaToolInputSchemaParam) MarshalJSON() (data []byte, err error) {
4021 type shadow BetaToolInputSchemaParam
4022 return param.MarshalWithExtras(r, (*shadow)(&r), r.ExtraFields)
4023}
4024func (r *BetaToolInputSchemaParam) UnmarshalJSON(data []byte) error {
4025 return apijson.UnmarshalRoot(data, r)
4026}
4027
4028type BetaToolType string
4029
4030const (
4031 BetaToolTypeCustom BetaToolType = "custom"
4032)
4033
4034// The properties Name, Type are required.
4035type BetaToolBash20241022Param struct {
4036 // Create a cache control breakpoint at this content block.
4037 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4038 // Name of the tool.
4039 //
4040 // This is how the tool will be called by the model and in `tool_use` blocks.
4041 //
4042 // This field can be elided, and will marshal its zero value as "bash".
4043 Name constant.Bash `json:"name,required"`
4044 // This field can be elided, and will marshal its zero value as "bash_20241022".
4045 Type constant.Bash20241022 `json:"type,required"`
4046 paramObj
4047}
4048
4049func (r BetaToolBash20241022Param) MarshalJSON() (data []byte, err error) {
4050 type shadow BetaToolBash20241022Param
4051 return param.MarshalObject(r, (*shadow)(&r))
4052}
4053func (r *BetaToolBash20241022Param) UnmarshalJSON(data []byte) error {
4054 return apijson.UnmarshalRoot(data, r)
4055}
4056
4057// The properties Name, Type are required.
4058type BetaToolBash20250124Param struct {
4059 // Create a cache control breakpoint at this content block.
4060 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4061 // Name of the tool.
4062 //
4063 // This is how the tool will be called by the model and in `tool_use` blocks.
4064 //
4065 // This field can be elided, and will marshal its zero value as "bash".
4066 Name constant.Bash `json:"name,required"`
4067 // This field can be elided, and will marshal its zero value as "bash_20250124".
4068 Type constant.Bash20250124 `json:"type,required"`
4069 paramObj
4070}
4071
4072func (r BetaToolBash20250124Param) MarshalJSON() (data []byte, err error) {
4073 type shadow BetaToolBash20250124Param
4074 return param.MarshalObject(r, (*shadow)(&r))
4075}
4076func (r *BetaToolBash20250124Param) UnmarshalJSON(data []byte) error {
4077 return apijson.UnmarshalRoot(data, r)
4078}
4079
4080func BetaToolChoiceParamOfTool(name string) BetaToolChoiceUnionParam {
4081 var tool BetaToolChoiceToolParam
4082 tool.Name = name
4083 return BetaToolChoiceUnionParam{OfTool: &tool}
4084}
4085
4086// Only one field can be non-zero.
4087//
4088// Use [param.IsOmitted] to confirm if a field is set.
4089type BetaToolChoiceUnionParam struct {
4090 OfAuto *BetaToolChoiceAutoParam `json:",omitzero,inline"`
4091 OfAny *BetaToolChoiceAnyParam `json:",omitzero,inline"`
4092 OfTool *BetaToolChoiceToolParam `json:",omitzero,inline"`
4093 OfNone *BetaToolChoiceNoneParam `json:",omitzero,inline"`
4094 paramUnion
4095}
4096
4097func (u BetaToolChoiceUnionParam) MarshalJSON() ([]byte, error) {
4098 return param.MarshalUnion(u, u.OfAuto, u.OfAny, u.OfTool, u.OfNone)
4099}
4100func (u *BetaToolChoiceUnionParam) UnmarshalJSON(data []byte) error {
4101 return apijson.UnmarshalRoot(data, u)
4102}
4103
4104func (u *BetaToolChoiceUnionParam) asAny() any {
4105 if !param.IsOmitted(u.OfAuto) {
4106 return u.OfAuto
4107 } else if !param.IsOmitted(u.OfAny) {
4108 return u.OfAny
4109 } else if !param.IsOmitted(u.OfTool) {
4110 return u.OfTool
4111 } else if !param.IsOmitted(u.OfNone) {
4112 return u.OfNone
4113 }
4114 return nil
4115}
4116
4117// Returns a pointer to the underlying variant's property, if present.
4118func (u BetaToolChoiceUnionParam) GetName() *string {
4119 if vt := u.OfTool; vt != nil {
4120 return &vt.Name
4121 }
4122 return nil
4123}
4124
4125// Returns a pointer to the underlying variant's property, if present.
4126func (u BetaToolChoiceUnionParam) GetType() *string {
4127 if vt := u.OfAuto; vt != nil {
4128 return (*string)(&vt.Type)
4129 } else if vt := u.OfAny; vt != nil {
4130 return (*string)(&vt.Type)
4131 } else if vt := u.OfTool; vt != nil {
4132 return (*string)(&vt.Type)
4133 } else if vt := u.OfNone; vt != nil {
4134 return (*string)(&vt.Type)
4135 }
4136 return nil
4137}
4138
4139// Returns a pointer to the underlying variant's property, if present.
4140func (u BetaToolChoiceUnionParam) GetDisableParallelToolUse() *bool {
4141 if vt := u.OfAuto; vt != nil && vt.DisableParallelToolUse.Valid() {
4142 return &vt.DisableParallelToolUse.Value
4143 } else if vt := u.OfAny; vt != nil && vt.DisableParallelToolUse.Valid() {
4144 return &vt.DisableParallelToolUse.Value
4145 } else if vt := u.OfTool; vt != nil && vt.DisableParallelToolUse.Valid() {
4146 return &vt.DisableParallelToolUse.Value
4147 }
4148 return nil
4149}
4150
4151// The model will use any available tools.
4152//
4153// The property Type is required.
4154type BetaToolChoiceAnyParam struct {
4155 // Whether to disable parallel tool use.
4156 //
4157 // Defaults to `false`. If set to `true`, the model will output exactly one tool
4158 // use.
4159 DisableParallelToolUse param.Opt[bool] `json:"disable_parallel_tool_use,omitzero"`
4160 // This field can be elided, and will marshal its zero value as "any".
4161 Type constant.Any `json:"type,required"`
4162 paramObj
4163}
4164
4165func (r BetaToolChoiceAnyParam) MarshalJSON() (data []byte, err error) {
4166 type shadow BetaToolChoiceAnyParam
4167 return param.MarshalObject(r, (*shadow)(&r))
4168}
4169func (r *BetaToolChoiceAnyParam) UnmarshalJSON(data []byte) error {
4170 return apijson.UnmarshalRoot(data, r)
4171}
4172
4173// The model will automatically decide whether to use tools.
4174//
4175// The property Type is required.
4176type BetaToolChoiceAutoParam struct {
4177 // Whether to disable parallel tool use.
4178 //
4179 // Defaults to `false`. If set to `true`, the model will output at most one tool
4180 // use.
4181 DisableParallelToolUse param.Opt[bool] `json:"disable_parallel_tool_use,omitzero"`
4182 // This field can be elided, and will marshal its zero value as "auto".
4183 Type constant.Auto `json:"type,required"`
4184 paramObj
4185}
4186
4187func (r BetaToolChoiceAutoParam) MarshalJSON() (data []byte, err error) {
4188 type shadow BetaToolChoiceAutoParam
4189 return param.MarshalObject(r, (*shadow)(&r))
4190}
4191func (r *BetaToolChoiceAutoParam) UnmarshalJSON(data []byte) error {
4192 return apijson.UnmarshalRoot(data, r)
4193}
4194
4195func NewBetaToolChoiceNoneParam() BetaToolChoiceNoneParam {
4196 return BetaToolChoiceNoneParam{
4197 Type: "none",
4198 }
4199}
4200
4201// The model will not be allowed to use tools.
4202//
4203// This struct has a constant value, construct it with
4204// [NewBetaToolChoiceNoneParam].
4205type BetaToolChoiceNoneParam struct {
4206 Type constant.None `json:"type,required"`
4207 paramObj
4208}
4209
4210func (r BetaToolChoiceNoneParam) MarshalJSON() (data []byte, err error) {
4211 type shadow BetaToolChoiceNoneParam
4212 return param.MarshalObject(r, (*shadow)(&r))
4213}
4214func (r *BetaToolChoiceNoneParam) UnmarshalJSON(data []byte) error {
4215 return apijson.UnmarshalRoot(data, r)
4216}
4217
4218// The model will use the specified tool with `tool_choice.name`.
4219//
4220// The properties Name, Type are required.
4221type BetaToolChoiceToolParam struct {
4222 // The name of the tool to use.
4223 Name string `json:"name,required"`
4224 // Whether to disable parallel tool use.
4225 //
4226 // Defaults to `false`. If set to `true`, the model will output exactly one tool
4227 // use.
4228 DisableParallelToolUse param.Opt[bool] `json:"disable_parallel_tool_use,omitzero"`
4229 // This field can be elided, and will marshal its zero value as "tool".
4230 Type constant.Tool `json:"type,required"`
4231 paramObj
4232}
4233
4234func (r BetaToolChoiceToolParam) MarshalJSON() (data []byte, err error) {
4235 type shadow BetaToolChoiceToolParam
4236 return param.MarshalObject(r, (*shadow)(&r))
4237}
4238func (r *BetaToolChoiceToolParam) UnmarshalJSON(data []byte) error {
4239 return apijson.UnmarshalRoot(data, r)
4240}
4241
4242// The properties DisplayHeightPx, DisplayWidthPx, Name, Type are required.
4243type BetaToolComputerUse20241022Param struct {
4244 // The height of the display in pixels.
4245 DisplayHeightPx int64 `json:"display_height_px,required"`
4246 // The width of the display in pixels.
4247 DisplayWidthPx int64 `json:"display_width_px,required"`
4248 // The X11 display number (e.g. 0, 1) for the display.
4249 DisplayNumber param.Opt[int64] `json:"display_number,omitzero"`
4250 // Create a cache control breakpoint at this content block.
4251 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4252 // Name of the tool.
4253 //
4254 // This is how the tool will be called by the model and in `tool_use` blocks.
4255 //
4256 // This field can be elided, and will marshal its zero value as "computer".
4257 Name constant.Computer `json:"name,required"`
4258 // This field can be elided, and will marshal its zero value as
4259 // "computer_20241022".
4260 Type constant.Computer20241022 `json:"type,required"`
4261 paramObj
4262}
4263
4264func (r BetaToolComputerUse20241022Param) MarshalJSON() (data []byte, err error) {
4265 type shadow BetaToolComputerUse20241022Param
4266 return param.MarshalObject(r, (*shadow)(&r))
4267}
4268func (r *BetaToolComputerUse20241022Param) UnmarshalJSON(data []byte) error {
4269 return apijson.UnmarshalRoot(data, r)
4270}
4271
4272// The properties DisplayHeightPx, DisplayWidthPx, Name, Type are required.
4273type BetaToolComputerUse20250124Param struct {
4274 // The height of the display in pixels.
4275 DisplayHeightPx int64 `json:"display_height_px,required"`
4276 // The width of the display in pixels.
4277 DisplayWidthPx int64 `json:"display_width_px,required"`
4278 // The X11 display number (e.g. 0, 1) for the display.
4279 DisplayNumber param.Opt[int64] `json:"display_number,omitzero"`
4280 // Create a cache control breakpoint at this content block.
4281 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4282 // Name of the tool.
4283 //
4284 // This is how the tool will be called by the model and in `tool_use` blocks.
4285 //
4286 // This field can be elided, and will marshal its zero value as "computer".
4287 Name constant.Computer `json:"name,required"`
4288 // This field can be elided, and will marshal its zero value as
4289 // "computer_20250124".
4290 Type constant.Computer20250124 `json:"type,required"`
4291 paramObj
4292}
4293
4294func (r BetaToolComputerUse20250124Param) MarshalJSON() (data []byte, err error) {
4295 type shadow BetaToolComputerUse20250124Param
4296 return param.MarshalObject(r, (*shadow)(&r))
4297}
4298func (r *BetaToolComputerUse20250124Param) UnmarshalJSON(data []byte) error {
4299 return apijson.UnmarshalRoot(data, r)
4300}
4301
4302// The properties ToolUseID, Type are required.
4303type BetaToolResultBlockParam struct {
4304 ToolUseID string `json:"tool_use_id,required"`
4305 IsError param.Opt[bool] `json:"is_error,omitzero"`
4306 // Create a cache control breakpoint at this content block.
4307 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4308 Content []BetaToolResultBlockParamContentUnion `json:"content,omitzero"`
4309 // This field can be elided, and will marshal its zero value as "tool_result".
4310 Type constant.ToolResult `json:"type,required"`
4311 paramObj
4312}
4313
4314func (r BetaToolResultBlockParam) MarshalJSON() (data []byte, err error) {
4315 type shadow BetaToolResultBlockParam
4316 return param.MarshalObject(r, (*shadow)(&r))
4317}
4318func (r *BetaToolResultBlockParam) UnmarshalJSON(data []byte) error {
4319 return apijson.UnmarshalRoot(data, r)
4320}
4321
4322// Only one field can be non-zero.
4323//
4324// Use [param.IsOmitted] to confirm if a field is set.
4325type BetaToolResultBlockParamContentUnion struct {
4326 OfText *BetaTextBlockParam `json:",omitzero,inline"`
4327 OfImage *BetaImageBlockParam `json:",omitzero,inline"`
4328 paramUnion
4329}
4330
4331func (u BetaToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
4332 return param.MarshalUnion(u, u.OfText, u.OfImage)
4333}
4334func (u *BetaToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
4335 return apijson.UnmarshalRoot(data, u)
4336}
4337
4338func (u *BetaToolResultBlockParamContentUnion) asAny() any {
4339 if !param.IsOmitted(u.OfText) {
4340 return u.OfText
4341 } else if !param.IsOmitted(u.OfImage) {
4342 return u.OfImage
4343 }
4344 return nil
4345}
4346
4347// Returns a pointer to the underlying variant's property, if present.
4348func (u BetaToolResultBlockParamContentUnion) GetText() *string {
4349 if vt := u.OfText; vt != nil {
4350 return &vt.Text
4351 }
4352 return nil
4353}
4354
4355// Returns a pointer to the underlying variant's property, if present.
4356func (u BetaToolResultBlockParamContentUnion) GetCitations() []BetaTextCitationParamUnion {
4357 if vt := u.OfText; vt != nil {
4358 return vt.Citations
4359 }
4360 return nil
4361}
4362
4363// Returns a pointer to the underlying variant's property, if present.
4364func (u BetaToolResultBlockParamContentUnion) GetSource() *BetaImageBlockParamSourceUnion {
4365 if vt := u.OfImage; vt != nil {
4366 return &vt.Source
4367 }
4368 return nil
4369}
4370
4371// Returns a pointer to the underlying variant's property, if present.
4372func (u BetaToolResultBlockParamContentUnion) GetType() *string {
4373 if vt := u.OfText; vt != nil {
4374 return (*string)(&vt.Type)
4375 } else if vt := u.OfImage; vt != nil {
4376 return (*string)(&vt.Type)
4377 }
4378 return nil
4379}
4380
4381// Returns a pointer to the underlying variant's CacheControl property, if present.
4382func (u BetaToolResultBlockParamContentUnion) GetCacheControl() *BetaCacheControlEphemeralParam {
4383 if vt := u.OfText; vt != nil {
4384 return &vt.CacheControl
4385 } else if vt := u.OfImage; vt != nil {
4386 return &vt.CacheControl
4387 }
4388 return nil
4389}
4390
4391// The properties Name, Type are required.
4392type BetaToolTextEditor20241022Param struct {
4393 // Create a cache control breakpoint at this content block.
4394 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4395 // Name of the tool.
4396 //
4397 // This is how the tool will be called by the model and in `tool_use` blocks.
4398 //
4399 // This field can be elided, and will marshal its zero value as
4400 // "str_replace_editor".
4401 Name constant.StrReplaceEditor `json:"name,required"`
4402 // This field can be elided, and will marshal its zero value as
4403 // "text_editor_20241022".
4404 Type constant.TextEditor20241022 `json:"type,required"`
4405 paramObj
4406}
4407
4408func (r BetaToolTextEditor20241022Param) MarshalJSON() (data []byte, err error) {
4409 type shadow BetaToolTextEditor20241022Param
4410 return param.MarshalObject(r, (*shadow)(&r))
4411}
4412func (r *BetaToolTextEditor20241022Param) UnmarshalJSON(data []byte) error {
4413 return apijson.UnmarshalRoot(data, r)
4414}
4415
4416// The properties Name, Type are required.
4417type BetaToolTextEditor20250124Param struct {
4418 // Create a cache control breakpoint at this content block.
4419 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4420 // Name of the tool.
4421 //
4422 // This is how the tool will be called by the model and in `tool_use` blocks.
4423 //
4424 // This field can be elided, and will marshal its zero value as
4425 // "str_replace_editor".
4426 Name constant.StrReplaceEditor `json:"name,required"`
4427 // This field can be elided, and will marshal its zero value as
4428 // "text_editor_20250124".
4429 Type constant.TextEditor20250124 `json:"type,required"`
4430 paramObj
4431}
4432
4433func (r BetaToolTextEditor20250124Param) MarshalJSON() (data []byte, err error) {
4434 type shadow BetaToolTextEditor20250124Param
4435 return param.MarshalObject(r, (*shadow)(&r))
4436}
4437func (r *BetaToolTextEditor20250124Param) UnmarshalJSON(data []byte) error {
4438 return apijson.UnmarshalRoot(data, r)
4439}
4440
4441// The properties Name, Type are required.
4442type BetaToolTextEditor20250429Param struct {
4443 // Create a cache control breakpoint at this content block.
4444 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4445 // Name of the tool.
4446 //
4447 // This is how the tool will be called by the model and in `tool_use` blocks.
4448 //
4449 // This field can be elided, and will marshal its zero value as
4450 // "str_replace_based_edit_tool".
4451 Name constant.StrReplaceBasedEditTool `json:"name,required"`
4452 // This field can be elided, and will marshal its zero value as
4453 // "text_editor_20250429".
4454 Type constant.TextEditor20250429 `json:"type,required"`
4455 paramObj
4456}
4457
4458func (r BetaToolTextEditor20250429Param) MarshalJSON() (data []byte, err error) {
4459 type shadow BetaToolTextEditor20250429Param
4460 return param.MarshalObject(r, (*shadow)(&r))
4461}
4462func (r *BetaToolTextEditor20250429Param) UnmarshalJSON(data []byte) error {
4463 return apijson.UnmarshalRoot(data, r)
4464}
4465
4466func BetaToolUnionParamOfTool(inputSchema BetaToolInputSchemaParam, name string) BetaToolUnionParam {
4467 var variant BetaToolParam
4468 variant.InputSchema = inputSchema
4469 variant.Name = name
4470 return BetaToolUnionParam{OfTool: &variant}
4471}
4472
4473func BetaToolUnionParamOfComputerUseTool20241022(displayHeightPx int64, displayWidthPx int64) BetaToolUnionParam {
4474 var variant BetaToolComputerUse20241022Param
4475 variant.DisplayHeightPx = displayHeightPx
4476 variant.DisplayWidthPx = displayWidthPx
4477 return BetaToolUnionParam{OfComputerUseTool20241022: &variant}
4478}
4479
4480func BetaToolUnionParamOfComputerUseTool20250124(displayHeightPx int64, displayWidthPx int64) BetaToolUnionParam {
4481 var variant BetaToolComputerUse20250124Param
4482 variant.DisplayHeightPx = displayHeightPx
4483 variant.DisplayWidthPx = displayWidthPx
4484 return BetaToolUnionParam{OfComputerUseTool20250124: &variant}
4485}
4486
4487// Only one field can be non-zero.
4488//
4489// Use [param.IsOmitted] to confirm if a field is set.
4490type BetaToolUnionParam struct {
4491 OfTool *BetaToolParam `json:",omitzero,inline"`
4492 OfComputerUseTool20241022 *BetaToolComputerUse20241022Param `json:",omitzero,inline"`
4493 OfBashTool20241022 *BetaToolBash20241022Param `json:",omitzero,inline"`
4494 OfTextEditor20241022 *BetaToolTextEditor20241022Param `json:",omitzero,inline"`
4495 OfComputerUseTool20250124 *BetaToolComputerUse20250124Param `json:",omitzero,inline"`
4496 OfBashTool20250124 *BetaToolBash20250124Param `json:",omitzero,inline"`
4497 OfTextEditor20250124 *BetaToolTextEditor20250124Param `json:",omitzero,inline"`
4498 OfTextEditor20250429 *BetaToolTextEditor20250429Param `json:",omitzero,inline"`
4499 OfWebSearchTool20250305 *BetaWebSearchTool20250305Param `json:",omitzero,inline"`
4500 OfCodeExecutionTool20250522 *BetaCodeExecutionTool20250522Param `json:",omitzero,inline"`
4501 paramUnion
4502}
4503
4504func (u BetaToolUnionParam) MarshalJSON() ([]byte, error) {
4505 return param.MarshalUnion(u, u.OfTool,
4506 u.OfComputerUseTool20241022,
4507 u.OfBashTool20241022,
4508 u.OfTextEditor20241022,
4509 u.OfComputerUseTool20250124,
4510 u.OfBashTool20250124,
4511 u.OfTextEditor20250124,
4512 u.OfTextEditor20250429,
4513 u.OfWebSearchTool20250305,
4514 u.OfCodeExecutionTool20250522)
4515}
4516func (u *BetaToolUnionParam) UnmarshalJSON(data []byte) error {
4517 return apijson.UnmarshalRoot(data, u)
4518}
4519
4520func (u *BetaToolUnionParam) asAny() any {
4521 if !param.IsOmitted(u.OfTool) {
4522 return u.OfTool
4523 } else if !param.IsOmitted(u.OfComputerUseTool20241022) {
4524 return u.OfComputerUseTool20241022
4525 } else if !param.IsOmitted(u.OfBashTool20241022) {
4526 return u.OfBashTool20241022
4527 } else if !param.IsOmitted(u.OfTextEditor20241022) {
4528 return u.OfTextEditor20241022
4529 } else if !param.IsOmitted(u.OfComputerUseTool20250124) {
4530 return u.OfComputerUseTool20250124
4531 } else if !param.IsOmitted(u.OfBashTool20250124) {
4532 return u.OfBashTool20250124
4533 } else if !param.IsOmitted(u.OfTextEditor20250124) {
4534 return u.OfTextEditor20250124
4535 } else if !param.IsOmitted(u.OfTextEditor20250429) {
4536 return u.OfTextEditor20250429
4537 } else if !param.IsOmitted(u.OfWebSearchTool20250305) {
4538 return u.OfWebSearchTool20250305
4539 } else if !param.IsOmitted(u.OfCodeExecutionTool20250522) {
4540 return u.OfCodeExecutionTool20250522
4541 }
4542 return nil
4543}
4544
4545// Returns a pointer to the underlying variant's property, if present.
4546func (u BetaToolUnionParam) GetInputSchema() *BetaToolInputSchemaParam {
4547 if vt := u.OfTool; vt != nil {
4548 return &vt.InputSchema
4549 }
4550 return nil
4551}
4552
4553// Returns a pointer to the underlying variant's property, if present.
4554func (u BetaToolUnionParam) GetDescription() *string {
4555 if vt := u.OfTool; vt != nil && vt.Description.Valid() {
4556 return &vt.Description.Value
4557 }
4558 return nil
4559}
4560
4561// Returns a pointer to the underlying variant's property, if present.
4562func (u BetaToolUnionParam) GetAllowedDomains() []string {
4563 if vt := u.OfWebSearchTool20250305; vt != nil {
4564 return vt.AllowedDomains
4565 }
4566 return nil
4567}
4568
4569// Returns a pointer to the underlying variant's property, if present.
4570func (u BetaToolUnionParam) GetBlockedDomains() []string {
4571 if vt := u.OfWebSearchTool20250305; vt != nil {
4572 return vt.BlockedDomains
4573 }
4574 return nil
4575}
4576
4577// Returns a pointer to the underlying variant's property, if present.
4578func (u BetaToolUnionParam) GetMaxUses() *int64 {
4579 if vt := u.OfWebSearchTool20250305; vt != nil && vt.MaxUses.Valid() {
4580 return &vt.MaxUses.Value
4581 }
4582 return nil
4583}
4584
4585// Returns a pointer to the underlying variant's property, if present.
4586func (u BetaToolUnionParam) GetUserLocation() *BetaWebSearchTool20250305UserLocationParam {
4587 if vt := u.OfWebSearchTool20250305; vt != nil {
4588 return &vt.UserLocation
4589 }
4590 return nil
4591}
4592
4593// Returns a pointer to the underlying variant's property, if present.
4594func (u BetaToolUnionParam) GetName() *string {
4595 if vt := u.OfTool; vt != nil {
4596 return (*string)(&vt.Name)
4597 } else if vt := u.OfComputerUseTool20241022; vt != nil {
4598 return (*string)(&vt.Name)
4599 } else if vt := u.OfBashTool20241022; vt != nil {
4600 return (*string)(&vt.Name)
4601 } else if vt := u.OfTextEditor20241022; vt != nil {
4602 return (*string)(&vt.Name)
4603 } else if vt := u.OfComputerUseTool20250124; vt != nil {
4604 return (*string)(&vt.Name)
4605 } else if vt := u.OfBashTool20250124; vt != nil {
4606 return (*string)(&vt.Name)
4607 } else if vt := u.OfTextEditor20250124; vt != nil {
4608 return (*string)(&vt.Name)
4609 } else if vt := u.OfTextEditor20250429; vt != nil {
4610 return (*string)(&vt.Name)
4611 } else if vt := u.OfWebSearchTool20250305; vt != nil {
4612 return (*string)(&vt.Name)
4613 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
4614 return (*string)(&vt.Name)
4615 }
4616 return nil
4617}
4618
4619// Returns a pointer to the underlying variant's property, if present.
4620func (u BetaToolUnionParam) GetType() *string {
4621 if vt := u.OfTool; vt != nil {
4622 return (*string)(&vt.Type)
4623 } else if vt := u.OfComputerUseTool20241022; vt != nil {
4624 return (*string)(&vt.Type)
4625 } else if vt := u.OfBashTool20241022; vt != nil {
4626 return (*string)(&vt.Type)
4627 } else if vt := u.OfTextEditor20241022; vt != nil {
4628 return (*string)(&vt.Type)
4629 } else if vt := u.OfComputerUseTool20250124; vt != nil {
4630 return (*string)(&vt.Type)
4631 } else if vt := u.OfBashTool20250124; vt != nil {
4632 return (*string)(&vt.Type)
4633 } else if vt := u.OfTextEditor20250124; vt != nil {
4634 return (*string)(&vt.Type)
4635 } else if vt := u.OfTextEditor20250429; vt != nil {
4636 return (*string)(&vt.Type)
4637 } else if vt := u.OfWebSearchTool20250305; vt != nil {
4638 return (*string)(&vt.Type)
4639 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
4640 return (*string)(&vt.Type)
4641 }
4642 return nil
4643}
4644
4645// Returns a pointer to the underlying variant's property, if present.
4646func (u BetaToolUnionParam) GetDisplayHeightPx() *int64 {
4647 if vt := u.OfComputerUseTool20241022; vt != nil {
4648 return (*int64)(&vt.DisplayHeightPx)
4649 } else if vt := u.OfComputerUseTool20250124; vt != nil {
4650 return (*int64)(&vt.DisplayHeightPx)
4651 }
4652 return nil
4653}
4654
4655// Returns a pointer to the underlying variant's property, if present.
4656func (u BetaToolUnionParam) GetDisplayWidthPx() *int64 {
4657 if vt := u.OfComputerUseTool20241022; vt != nil {
4658 return (*int64)(&vt.DisplayWidthPx)
4659 } else if vt := u.OfComputerUseTool20250124; vt != nil {
4660 return (*int64)(&vt.DisplayWidthPx)
4661 }
4662 return nil
4663}
4664
4665// Returns a pointer to the underlying variant's property, if present.
4666func (u BetaToolUnionParam) GetDisplayNumber() *int64 {
4667 if vt := u.OfComputerUseTool20241022; vt != nil && vt.DisplayNumber.Valid() {
4668 return &vt.DisplayNumber.Value
4669 } else if vt := u.OfComputerUseTool20250124; vt != nil && vt.DisplayNumber.Valid() {
4670 return &vt.DisplayNumber.Value
4671 }
4672 return nil
4673}
4674
4675// Returns a pointer to the underlying variant's CacheControl property, if present.
4676func (u BetaToolUnionParam) GetCacheControl() *BetaCacheControlEphemeralParam {
4677 if vt := u.OfTool; vt != nil {
4678 return &vt.CacheControl
4679 } else if vt := u.OfComputerUseTool20241022; vt != nil {
4680 return &vt.CacheControl
4681 } else if vt := u.OfBashTool20241022; vt != nil {
4682 return &vt.CacheControl
4683 } else if vt := u.OfTextEditor20241022; vt != nil {
4684 return &vt.CacheControl
4685 } else if vt := u.OfComputerUseTool20250124; vt != nil {
4686 return &vt.CacheControl
4687 } else if vt := u.OfBashTool20250124; vt != nil {
4688 return &vt.CacheControl
4689 } else if vt := u.OfTextEditor20250124; vt != nil {
4690 return &vt.CacheControl
4691 } else if vt := u.OfTextEditor20250429; vt != nil {
4692 return &vt.CacheControl
4693 } else if vt := u.OfWebSearchTool20250305; vt != nil {
4694 return &vt.CacheControl
4695 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
4696 return &vt.CacheControl
4697 }
4698 return nil
4699}
4700
4701type BetaToolUseBlock struct {
4702 ID string `json:"id,required"`
4703 Input any `json:"input,required"`
4704 Name string `json:"name,required"`
4705 Type constant.ToolUse `json:"type,required"`
4706 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
4707 JSON struct {
4708 ID respjson.Field
4709 Input respjson.Field
4710 Name respjson.Field
4711 Type respjson.Field
4712 ExtraFields map[string]respjson.Field
4713 raw string
4714 } `json:"-"`
4715}
4716
4717// Returns the unmodified JSON received from the API
4718func (r BetaToolUseBlock) RawJSON() string { return r.JSON.raw }
4719func (r *BetaToolUseBlock) UnmarshalJSON(data []byte) error {
4720 return apijson.UnmarshalRoot(data, r)
4721}
4722
4723func (r BetaToolUseBlock) ToParam() BetaToolUseBlockParam {
4724 var p BetaToolUseBlockParam
4725 p.Type = r.Type
4726 p.ID = r.ID
4727 p.Input = r.Input
4728 p.Name = r.Name
4729 return p
4730}
4731
4732// The properties ID, Input, Name, Type are required.
4733type BetaToolUseBlockParam struct {
4734 ID string `json:"id,required"`
4735 Input any `json:"input,omitzero,required"`
4736 Name string `json:"name,required"`
4737 // Create a cache control breakpoint at this content block.
4738 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4739 // This field can be elided, and will marshal its zero value as "tool_use".
4740 Type constant.ToolUse `json:"type,required"`
4741 paramObj
4742}
4743
4744func (r BetaToolUseBlockParam) MarshalJSON() (data []byte, err error) {
4745 type shadow BetaToolUseBlockParam
4746 return param.MarshalObject(r, (*shadow)(&r))
4747}
4748func (r *BetaToolUseBlockParam) UnmarshalJSON(data []byte) error {
4749 return apijson.UnmarshalRoot(data, r)
4750}
4751
4752// The properties Type, URL are required.
4753type BetaURLImageSourceParam struct {
4754 URL string `json:"url,required"`
4755 // This field can be elided, and will marshal its zero value as "url".
4756 Type constant.URL `json:"type,required"`
4757 paramObj
4758}
4759
4760func (r BetaURLImageSourceParam) MarshalJSON() (data []byte, err error) {
4761 type shadow BetaURLImageSourceParam
4762 return param.MarshalObject(r, (*shadow)(&r))
4763}
4764func (r *BetaURLImageSourceParam) UnmarshalJSON(data []byte) error {
4765 return apijson.UnmarshalRoot(data, r)
4766}
4767
4768// The properties Type, URL are required.
4769type BetaURLPDFSourceParam struct {
4770 URL string `json:"url,required"`
4771 // This field can be elided, and will marshal its zero value as "url".
4772 Type constant.URL `json:"type,required"`
4773 paramObj
4774}
4775
4776func (r BetaURLPDFSourceParam) MarshalJSON() (data []byte, err error) {
4777 type shadow BetaURLPDFSourceParam
4778 return param.MarshalObject(r, (*shadow)(&r))
4779}
4780func (r *BetaURLPDFSourceParam) UnmarshalJSON(data []byte) error {
4781 return apijson.UnmarshalRoot(data, r)
4782}
4783
4784type BetaUsage struct {
4785 // Breakdown of cached tokens by TTL
4786 CacheCreation BetaCacheCreation `json:"cache_creation,required"`
4787 // The number of input tokens used to create the cache entry.
4788 CacheCreationInputTokens int64 `json:"cache_creation_input_tokens,required"`
4789 // The number of input tokens read from the cache.
4790 CacheReadInputTokens int64 `json:"cache_read_input_tokens,required"`
4791 // The number of input tokens which were used.
4792 InputTokens int64 `json:"input_tokens,required"`
4793 // The number of output tokens which were used.
4794 OutputTokens int64 `json:"output_tokens,required"`
4795 // The number of server tool requests.
4796 ServerToolUse BetaServerToolUsage `json:"server_tool_use,required"`
4797 // If the request used the priority, standard, or batch tier.
4798 //
4799 // Any of "standard", "priority", "batch".
4800 ServiceTier BetaUsageServiceTier `json:"service_tier,required"`
4801 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
4802 JSON struct {
4803 CacheCreation respjson.Field
4804 CacheCreationInputTokens respjson.Field
4805 CacheReadInputTokens respjson.Field
4806 InputTokens respjson.Field
4807 OutputTokens respjson.Field
4808 ServerToolUse respjson.Field
4809 ServiceTier respjson.Field
4810 ExtraFields map[string]respjson.Field
4811 raw string
4812 } `json:"-"`
4813}
4814
4815// Returns the unmodified JSON received from the API
4816func (r BetaUsage) RawJSON() string { return r.JSON.raw }
4817func (r *BetaUsage) UnmarshalJSON(data []byte) error {
4818 return apijson.UnmarshalRoot(data, r)
4819}
4820
4821// If the request used the priority, standard, or batch tier.
4822type BetaUsageServiceTier string
4823
4824const (
4825 BetaUsageServiceTierStandard BetaUsageServiceTier = "standard"
4826 BetaUsageServiceTierPriority BetaUsageServiceTier = "priority"
4827 BetaUsageServiceTierBatch BetaUsageServiceTier = "batch"
4828)
4829
4830type BetaWebSearchResultBlock struct {
4831 EncryptedContent string `json:"encrypted_content,required"`
4832 PageAge string `json:"page_age,required"`
4833 Title string `json:"title,required"`
4834 Type constant.WebSearchResult `json:"type,required"`
4835 URL string `json:"url,required"`
4836 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
4837 JSON struct {
4838 EncryptedContent respjson.Field
4839 PageAge respjson.Field
4840 Title respjson.Field
4841 Type respjson.Field
4842 URL respjson.Field
4843 ExtraFields map[string]respjson.Field
4844 raw string
4845 } `json:"-"`
4846}
4847
4848// Returns the unmodified JSON received from the API
4849func (r BetaWebSearchResultBlock) RawJSON() string { return r.JSON.raw }
4850func (r *BetaWebSearchResultBlock) UnmarshalJSON(data []byte) error {
4851 return apijson.UnmarshalRoot(data, r)
4852}
4853
4854// The properties EncryptedContent, Title, Type, URL are required.
4855type BetaWebSearchResultBlockParam struct {
4856 EncryptedContent string `json:"encrypted_content,required"`
4857 Title string `json:"title,required"`
4858 URL string `json:"url,required"`
4859 PageAge param.Opt[string] `json:"page_age,omitzero"`
4860 // This field can be elided, and will marshal its zero value as
4861 // "web_search_result".
4862 Type constant.WebSearchResult `json:"type,required"`
4863 paramObj
4864}
4865
4866func (r BetaWebSearchResultBlockParam) MarshalJSON() (data []byte, err error) {
4867 type shadow BetaWebSearchResultBlockParam
4868 return param.MarshalObject(r, (*shadow)(&r))
4869}
4870func (r *BetaWebSearchResultBlockParam) UnmarshalJSON(data []byte) error {
4871 return apijson.UnmarshalRoot(data, r)
4872}
4873
4874// The properties Name, Type are required.
4875type BetaWebSearchTool20250305Param struct {
4876 // Maximum number of times the tool can be used in the API request.
4877 MaxUses param.Opt[int64] `json:"max_uses,omitzero"`
4878 // If provided, only these domains will be included in results. Cannot be used
4879 // alongside `blocked_domains`.
4880 AllowedDomains []string `json:"allowed_domains,omitzero"`
4881 // If provided, these domains will never appear in results. Cannot be used
4882 // alongside `allowed_domains`.
4883 BlockedDomains []string `json:"blocked_domains,omitzero"`
4884 // Parameters for the user's location. Used to provide more relevant search
4885 // results.
4886 UserLocation BetaWebSearchTool20250305UserLocationParam `json:"user_location,omitzero"`
4887 // Create a cache control breakpoint at this content block.
4888 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
4889 // Name of the tool.
4890 //
4891 // This is how the tool will be called by the model and in `tool_use` blocks.
4892 //
4893 // This field can be elided, and will marshal its zero value as "web_search".
4894 Name constant.WebSearch `json:"name,required"`
4895 // This field can be elided, and will marshal its zero value as
4896 // "web_search_20250305".
4897 Type constant.WebSearch20250305 `json:"type,required"`
4898 paramObj
4899}
4900
4901func (r BetaWebSearchTool20250305Param) MarshalJSON() (data []byte, err error) {
4902 type shadow BetaWebSearchTool20250305Param
4903 return param.MarshalObject(r, (*shadow)(&r))
4904}
4905func (r *BetaWebSearchTool20250305Param) UnmarshalJSON(data []byte) error {
4906 return apijson.UnmarshalRoot(data, r)
4907}
4908
4909// Parameters for the user's location. Used to provide more relevant search
4910// results.
4911//
4912// The property Type is required.
4913type BetaWebSearchTool20250305UserLocationParam struct {
4914 // The city of the user.
4915 City param.Opt[string] `json:"city,omitzero"`
4916 // The two letter
4917 // [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the
4918 // user.
4919 Country param.Opt[string] `json:"country,omitzero"`
4920 // The region of the user.
4921 Region param.Opt[string] `json:"region,omitzero"`
4922 // The [IANA timezone](https://nodatime.org/TimeZones) of the user.
4923 Timezone param.Opt[string] `json:"timezone,omitzero"`
4924 // This field can be elided, and will marshal its zero value as "approximate".
4925 Type constant.Approximate `json:"type,required"`
4926 paramObj
4927}
4928
4929func (r BetaWebSearchTool20250305UserLocationParam) MarshalJSON() (data []byte, err error) {
4930 type shadow BetaWebSearchTool20250305UserLocationParam
4931 return param.MarshalObject(r, (*shadow)(&r))
4932}
4933func (r *BetaWebSearchTool20250305UserLocationParam) UnmarshalJSON(data []byte) error {
4934 return apijson.UnmarshalRoot(data, r)
4935}
4936
4937// The properties ErrorCode, Type are required.
4938type BetaWebSearchToolRequestErrorParam struct {
4939 // Any of "invalid_tool_input", "unavailable", "max_uses_exceeded",
4940 // "too_many_requests", "query_too_long".
4941 ErrorCode BetaWebSearchToolResultErrorCode `json:"error_code,omitzero,required"`
4942 // This field can be elided, and will marshal its zero value as
4943 // "web_search_tool_result_error".
4944 Type constant.WebSearchToolResultError `json:"type,required"`
4945 paramObj
4946}
4947
4948func (r BetaWebSearchToolRequestErrorParam) MarshalJSON() (data []byte, err error) {
4949 type shadow BetaWebSearchToolRequestErrorParam
4950 return param.MarshalObject(r, (*shadow)(&r))
4951}
4952func (r *BetaWebSearchToolRequestErrorParam) UnmarshalJSON(data []byte) error {
4953 return apijson.UnmarshalRoot(data, r)
4954}
4955
4956type BetaWebSearchToolResultBlock struct {
4957 Content BetaWebSearchToolResultBlockContentUnion `json:"content,required"`
4958 ToolUseID string `json:"tool_use_id,required"`
4959 Type constant.WebSearchToolResult `json:"type,required"`
4960 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
4961 JSON struct {
4962 Content respjson.Field
4963 ToolUseID respjson.Field
4964 Type respjson.Field
4965 ExtraFields map[string]respjson.Field
4966 raw string
4967 } `json:"-"`
4968}
4969
4970// Returns the unmodified JSON received from the API
4971func (r BetaWebSearchToolResultBlock) RawJSON() string { return r.JSON.raw }
4972func (r *BetaWebSearchToolResultBlock) UnmarshalJSON(data []byte) error {
4973 return apijson.UnmarshalRoot(data, r)
4974}
4975
4976// BetaWebSearchToolResultBlockContentUnion contains all possible properties and
4977// values from [BetaWebSearchToolResultError], [[]BetaWebSearchResultBlock].
4978//
4979// Use the methods beginning with 'As' to cast the union to one of its variants.
4980//
4981// If the underlying value is not a json object, one of the following properties
4982// will be valid: OfBetaWebSearchResultBlockArray]
4983type BetaWebSearchToolResultBlockContentUnion struct {
4984 // This field will be present if the value is a [[]BetaWebSearchResultBlock]
4985 // instead of an object.
4986 OfBetaWebSearchResultBlockArray []BetaWebSearchResultBlock `json:",inline"`
4987 // This field is from variant [BetaWebSearchToolResultError].
4988 ErrorCode BetaWebSearchToolResultErrorCode `json:"error_code"`
4989 // This field is from variant [BetaWebSearchToolResultError].
4990 Type constant.WebSearchToolResultError `json:"type"`
4991 JSON struct {
4992 OfBetaWebSearchResultBlockArray respjson.Field
4993 ErrorCode respjson.Field
4994 Type respjson.Field
4995 raw string
4996 } `json:"-"`
4997}
4998
4999func (u BetaWebSearchToolResultBlockContentUnion) AsResponseWebSearchToolResultError() (v BetaWebSearchToolResultError) {
5000 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
5001 return
5002}
5003
5004func (u BetaWebSearchToolResultBlockContentUnion) AsBetaWebSearchResultBlockArray() (v []BetaWebSearchResultBlock) {
5005 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
5006 return
5007}
5008
5009// Returns the unmodified JSON received from the API
5010func (u BetaWebSearchToolResultBlockContentUnion) RawJSON() string { return u.JSON.raw }
5011
5012func (r *BetaWebSearchToolResultBlockContentUnion) UnmarshalJSON(data []byte) error {
5013 return apijson.UnmarshalRoot(data, r)
5014}
5015
5016// The properties Content, ToolUseID, Type are required.
5017type BetaWebSearchToolResultBlockParam struct {
5018 Content BetaWebSearchToolResultBlockParamContentUnion `json:"content,omitzero,required"`
5019 ToolUseID string `json:"tool_use_id,required"`
5020 // Create a cache control breakpoint at this content block.
5021 CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
5022 // This field can be elided, and will marshal its zero value as
5023 // "web_search_tool_result".
5024 Type constant.WebSearchToolResult `json:"type,required"`
5025 paramObj
5026}
5027
5028func (r BetaWebSearchToolResultBlockParam) MarshalJSON() (data []byte, err error) {
5029 type shadow BetaWebSearchToolResultBlockParam
5030 return param.MarshalObject(r, (*shadow)(&r))
5031}
5032func (r *BetaWebSearchToolResultBlockParam) UnmarshalJSON(data []byte) error {
5033 return apijson.UnmarshalRoot(data, r)
5034}
5035
5036func BetaNewWebSearchToolRequestError(errorCode BetaWebSearchToolResultErrorCode) BetaWebSearchToolResultBlockParamContentUnion {
5037 var variant BetaWebSearchToolRequestErrorParam
5038 variant.ErrorCode = errorCode
5039 return BetaWebSearchToolResultBlockParamContentUnion{OfError: &variant}
5040}
5041
5042// Only one field can be non-zero.
5043//
5044// Use [param.IsOmitted] to confirm if a field is set.
5045type BetaWebSearchToolResultBlockParamContentUnion struct {
5046 OfResultBlock []BetaWebSearchResultBlockParam `json:",omitzero,inline"`
5047 OfError *BetaWebSearchToolRequestErrorParam `json:",omitzero,inline"`
5048 paramUnion
5049}
5050
5051func (u BetaWebSearchToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
5052 return param.MarshalUnion(u, u.OfResultBlock, u.OfError)
5053}
5054func (u *BetaWebSearchToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
5055 return apijson.UnmarshalRoot(data, u)
5056}
5057
5058func (u *BetaWebSearchToolResultBlockParamContentUnion) asAny() any {
5059 if !param.IsOmitted(u.OfResultBlock) {
5060 return &u.OfResultBlock
5061 } else if !param.IsOmitted(u.OfError) {
5062 return u.OfError
5063 }
5064 return nil
5065}
5066
5067type BetaWebSearchToolResultError struct {
5068 // Any of "invalid_tool_input", "unavailable", "max_uses_exceeded",
5069 // "too_many_requests", "query_too_long".
5070 ErrorCode BetaWebSearchToolResultErrorCode `json:"error_code,required"`
5071 Type constant.WebSearchToolResultError `json:"type,required"`
5072 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
5073 JSON struct {
5074 ErrorCode respjson.Field
5075 Type respjson.Field
5076 ExtraFields map[string]respjson.Field
5077 raw string
5078 } `json:"-"`
5079}
5080
5081// Returns the unmodified JSON received from the API
5082func (r BetaWebSearchToolResultError) RawJSON() string { return r.JSON.raw }
5083func (r *BetaWebSearchToolResultError) UnmarshalJSON(data []byte) error {
5084 return apijson.UnmarshalRoot(data, r)
5085}
5086
5087type BetaWebSearchToolResultErrorCode string
5088
5089const (
5090 BetaWebSearchToolResultErrorCodeInvalidToolInput BetaWebSearchToolResultErrorCode = "invalid_tool_input"
5091 BetaWebSearchToolResultErrorCodeUnavailable BetaWebSearchToolResultErrorCode = "unavailable"
5092 BetaWebSearchToolResultErrorCodeMaxUsesExceeded BetaWebSearchToolResultErrorCode = "max_uses_exceeded"
5093 BetaWebSearchToolResultErrorCodeTooManyRequests BetaWebSearchToolResultErrorCode = "too_many_requests"
5094 BetaWebSearchToolResultErrorCodeQueryTooLong BetaWebSearchToolResultErrorCode = "query_too_long"
5095)
5096
5097type BetaMessageNewParams struct {
5098 // The maximum number of tokens to generate before stopping.
5099 //
5100 // Note that our models may stop _before_ reaching this maximum. This parameter
5101 // only specifies the absolute maximum number of tokens to generate.
5102 //
5103 // Different models have different maximum values for this parameter. See
5104 // [models](https://docs.anthropic.com/en/docs/models-overview) for details.
5105 MaxTokens int64 `json:"max_tokens,required"`
5106 // Input messages.
5107 //
5108 // Our models are trained to operate on alternating `user` and `assistant`
5109 // conversational turns. When creating a new `Message`, you specify the prior
5110 // conversational turns with the `messages` parameter, and the model then generates
5111 // the next `Message` in the conversation. Consecutive `user` or `assistant` turns
5112 // in your request will be combined into a single turn.
5113 //
5114 // Each input message must be an object with a `role` and `content`. You can
5115 // specify a single `user`-role message, or you can include multiple `user` and
5116 // `assistant` messages.
5117 //
5118 // If the final message uses the `assistant` role, the response content will
5119 // continue immediately from the content in that message. This can be used to
5120 // constrain part of the model's response.
5121 //
5122 // Example with a single `user` message:
5123 //
5124 // ```json
5125 // [{ "role": "user", "content": "Hello, Claude" }]
5126 // ```
5127 //
5128 // Example with multiple conversational turns:
5129 //
5130 // ```json
5131 // [
5132 //
5133 // { "role": "user", "content": "Hello there." },
5134 // { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
5135 // { "role": "user", "content": "Can you explain LLMs in plain English?" }
5136 //
5137 // ]
5138 // ```
5139 //
5140 // Example with a partially-filled response from Claude:
5141 //
5142 // ```json
5143 // [
5144 //
5145 // {
5146 // "role": "user",
5147 // "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
5148 // },
5149 // { "role": "assistant", "content": "The best answer is (" }
5150 //
5151 // ]
5152 // ```
5153 //
5154 // Each input message `content` may be either a single `string` or an array of
5155 // content blocks, where each block has a specific `type`. Using a `string` for
5156 // `content` is shorthand for an array of one content block of type `"text"`. The
5157 // following input messages are equivalent:
5158 //
5159 // ```json
5160 // { "role": "user", "content": "Hello, Claude" }
5161 // ```
5162 //
5163 // ```json
5164 // { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
5165 // ```
5166 //
5167 // Starting with Claude 3 models, you can also send image content blocks:
5168 //
5169 // ```json
5170 //
5171 // {
5172 // "role": "user",
5173 // "content": [
5174 // {
5175 // "type": "image",
5176 // "source": {
5177 // "type": "base64",
5178 // "media_type": "image/jpeg",
5179 // "data": "/9j/4AAQSkZJRg..."
5180 // }
5181 // },
5182 // { "type": "text", "text": "What is in this image?" }
5183 // ]
5184 // }
5185 //
5186 // ```
5187 //
5188 // We currently support the `base64` source type for images, and the `image/jpeg`,
5189 // `image/png`, `image/gif`, and `image/webp` media types.
5190 //
5191 // See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
5192 // more input examples.
5193 //
5194 // Note that if you want to include a
5195 // [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
5196 // the top-level `system` parameter — there is no `"system"` role for input
5197 // messages in the Messages API.
5198 //
5199 // There is a limit of 100000 messages in a single request.
5200 Messages []BetaMessageParam `json:"messages,omitzero,required"`
5201 // The model that will complete your prompt.\n\nSee
5202 // [models](https://docs.anthropic.com/en/docs/models-overview) for additional
5203 // details and options.
5204 Model Model `json:"model,omitzero,required"`
5205 // Container identifier for reuse across requests.
5206 Container param.Opt[string] `json:"container,omitzero"`
5207 // Amount of randomness injected into the response.
5208 //
5209 // Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
5210 // for analytical / multiple choice, and closer to `1.0` for creative and
5211 // generative tasks.
5212 //
5213 // Note that even with `temperature` of `0.0`, the results will not be fully
5214 // deterministic.
5215 Temperature param.Opt[float64] `json:"temperature,omitzero"`
5216 // Only sample from the top K options for each subsequent token.
5217 //
5218 // Used to remove "long tail" low probability responses.
5219 // [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
5220 //
5221 // Recommended for advanced use cases only. You usually only need to use
5222 // `temperature`.
5223 TopK param.Opt[int64] `json:"top_k,omitzero"`
5224 // Use nucleus sampling.
5225 //
5226 // In nucleus sampling, we compute the cumulative distribution over all the options
5227 // for each subsequent token in decreasing probability order and cut it off once it
5228 // reaches a particular probability specified by `top_p`. You should either alter
5229 // `temperature` or `top_p`, but not both.
5230 //
5231 // Recommended for advanced use cases only. You usually only need to use
5232 // `temperature`.
5233 TopP param.Opt[float64] `json:"top_p,omitzero"`
5234 // MCP servers to be utilized in this request
5235 MCPServers []BetaRequestMCPServerURLDefinitionParam `json:"mcp_servers,omitzero"`
5236 // An object describing metadata about the request.
5237 Metadata BetaMetadataParam `json:"metadata,omitzero"`
5238 // Determines whether to use priority capacity (if available) or standard capacity
5239 // for this request.
5240 //
5241 // Anthropic offers different levels of service for your API requests. See
5242 // [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
5243 //
5244 // Any of "auto", "standard_only".
5245 ServiceTier BetaMessageNewParamsServiceTier `json:"service_tier,omitzero"`
5246 // Custom text sequences that will cause the model to stop generating.
5247 //
5248 // Our models will normally stop when they have naturally completed their turn,
5249 // which will result in a response `stop_reason` of `"end_turn"`.
5250 //
5251 // If you want the model to stop generating when it encounters custom strings of
5252 // text, you can use the `stop_sequences` parameter. If the model encounters one of
5253 // the custom sequences, the response `stop_reason` value will be `"stop_sequence"`
5254 // and the response `stop_sequence` value will contain the matched stop sequence.
5255 StopSequences []string `json:"stop_sequences,omitzero"`
5256 // System prompt.
5257 //
5258 // A system prompt is a way of providing context and instructions to Claude, such
5259 // as specifying a particular goal or role. See our
5260 // [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
5261 System []BetaTextBlockParam `json:"system,omitzero"`
5262 // Configuration for enabling Claude's extended thinking.
5263 //
5264 // When enabled, responses include `thinking` content blocks showing Claude's
5265 // thinking process before the final answer. Requires a minimum budget of 1,024
5266 // tokens and counts towards your `max_tokens` limit.
5267 //
5268 // See
5269 // [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
5270 // for details.
5271 Thinking BetaThinkingConfigParamUnion `json:"thinking,omitzero"`
5272 // How the model should use the provided tools. The model can use a specific tool,
5273 // any available tool, decide by itself, or not use tools at all.
5274 ToolChoice BetaToolChoiceUnionParam `json:"tool_choice,omitzero"`
5275 // Definitions of tools that the model may use.
5276 //
5277 // If you include `tools` in your API request, the model may return `tool_use`
5278 // content blocks that represent the model's use of those tools. You can then run
5279 // those tools using the tool input generated by the model and then optionally
5280 // return results back to the model using `tool_result` content blocks.
5281 //
5282 // Each tool definition includes:
5283 //
5284 // - `name`: Name of the tool.
5285 // - `description`: Optional, but strongly-recommended description of the tool.
5286 // - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
5287 // tool `input` shape that the model will produce in `tool_use` output content
5288 // blocks.
5289 //
5290 // For example, if you defined `tools` as:
5291 //
5292 // ```json
5293 // [
5294 //
5295 // {
5296 // "name": "get_stock_price",
5297 // "description": "Get the current stock price for a given ticker symbol.",
5298 // "input_schema": {
5299 // "type": "object",
5300 // "properties": {
5301 // "ticker": {
5302 // "type": "string",
5303 // "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
5304 // }
5305 // },
5306 // "required": ["ticker"]
5307 // }
5308 // }
5309 //
5310 // ]
5311 // ```
5312 //
5313 // And then asked the model "What's the S&P 500 at today?", the model might produce
5314 // `tool_use` content blocks in the response like this:
5315 //
5316 // ```json
5317 // [
5318 //
5319 // {
5320 // "type": "tool_use",
5321 // "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
5322 // "name": "get_stock_price",
5323 // "input": { "ticker": "^GSPC" }
5324 // }
5325 //
5326 // ]
5327 // ```
5328 //
5329 // You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
5330 // input, and return the following back to the model in a subsequent `user`
5331 // message:
5332 //
5333 // ```json
5334 // [
5335 //
5336 // {
5337 // "type": "tool_result",
5338 // "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
5339 // "content": "259.75 USD"
5340 // }
5341 //
5342 // ]
5343 // ```
5344 //
5345 // Tools can be used for workflows that include running client-side tools and
5346 // functions, or more generally whenever you want the model to produce a particular
5347 // JSON structure of output.
5348 //
5349 // See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
5350 Tools []BetaToolUnionParam `json:"tools,omitzero"`
5351 // Optional header to specify the beta version(s) you want to use.
5352 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
5353 paramObj
5354}
5355
5356func (r BetaMessageNewParams) MarshalJSON() (data []byte, err error) {
5357 type shadow BetaMessageNewParams
5358 return param.MarshalObject(r, (*shadow)(&r))
5359}
5360func (r *BetaMessageNewParams) UnmarshalJSON(data []byte) error {
5361 return apijson.UnmarshalRoot(data, r)
5362}
5363
5364// Determines whether to use priority capacity (if available) or standard capacity
5365// for this request.
5366//
5367// Anthropic offers different levels of service for your API requests. See
5368// [service-tiers](https://docs.anthropic.com/en/api/service-tiers) for details.
5369type BetaMessageNewParamsServiceTier string
5370
5371const (
5372 BetaMessageNewParamsServiceTierAuto BetaMessageNewParamsServiceTier = "auto"
5373 BetaMessageNewParamsServiceTierStandardOnly BetaMessageNewParamsServiceTier = "standard_only"
5374)
5375
5376type BetaMessageCountTokensParams struct {
5377 // Input messages.
5378 //
5379 // Our models are trained to operate on alternating `user` and `assistant`
5380 // conversational turns. When creating a new `Message`, you specify the prior
5381 // conversational turns with the `messages` parameter, and the model then generates
5382 // the next `Message` in the conversation. Consecutive `user` or `assistant` turns
5383 // in your request will be combined into a single turn.
5384 //
5385 // Each input message must be an object with a `role` and `content`. You can
5386 // specify a single `user`-role message, or you can include multiple `user` and
5387 // `assistant` messages.
5388 //
5389 // If the final message uses the `assistant` role, the response content will
5390 // continue immediately from the content in that message. This can be used to
5391 // constrain part of the model's response.
5392 //
5393 // Example with a single `user` message:
5394 //
5395 // ```json
5396 // [{ "role": "user", "content": "Hello, Claude" }]
5397 // ```
5398 //
5399 // Example with multiple conversational turns:
5400 //
5401 // ```json
5402 // [
5403 //
5404 // { "role": "user", "content": "Hello there." },
5405 // { "role": "assistant", "content": "Hi, I'm Claude. How can I help you?" },
5406 // { "role": "user", "content": "Can you explain LLMs in plain English?" }
5407 //
5408 // ]
5409 // ```
5410 //
5411 // Example with a partially-filled response from Claude:
5412 //
5413 // ```json
5414 // [
5415 //
5416 // {
5417 // "role": "user",
5418 // "content": "What's the Greek name for Sun? (A) Sol (B) Helios (C) Sun"
5419 // },
5420 // { "role": "assistant", "content": "The best answer is (" }
5421 //
5422 // ]
5423 // ```
5424 //
5425 // Each input message `content` may be either a single `string` or an array of
5426 // content blocks, where each block has a specific `type`. Using a `string` for
5427 // `content` is shorthand for an array of one content block of type `"text"`. The
5428 // following input messages are equivalent:
5429 //
5430 // ```json
5431 // { "role": "user", "content": "Hello, Claude" }
5432 // ```
5433 //
5434 // ```json
5435 // { "role": "user", "content": [{ "type": "text", "text": "Hello, Claude" }] }
5436 // ```
5437 //
5438 // Starting with Claude 3 models, you can also send image content blocks:
5439 //
5440 // ```json
5441 //
5442 // {
5443 // "role": "user",
5444 // "content": [
5445 // {
5446 // "type": "image",
5447 // "source": {
5448 // "type": "base64",
5449 // "media_type": "image/jpeg",
5450 // "data": "/9j/4AAQSkZJRg..."
5451 // }
5452 // },
5453 // { "type": "text", "text": "What is in this image?" }
5454 // ]
5455 // }
5456 //
5457 // ```
5458 //
5459 // We currently support the `base64` source type for images, and the `image/jpeg`,
5460 // `image/png`, `image/gif`, and `image/webp` media types.
5461 //
5462 // See [examples](https://docs.anthropic.com/en/api/messages-examples#vision) for
5463 // more input examples.
5464 //
5465 // Note that if you want to include a
5466 // [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
5467 // the top-level `system` parameter — there is no `"system"` role for input
5468 // messages in the Messages API.
5469 //
5470 // There is a limit of 100000 messages in a single request.
5471 Messages []BetaMessageParam `json:"messages,omitzero,required"`
5472 // The model that will complete your prompt.\n\nSee
5473 // [models](https://docs.anthropic.com/en/docs/models-overview) for additional
5474 // details and options.
5475 Model Model `json:"model,omitzero,required"`
5476 // MCP servers to be utilized in this request
5477 MCPServers []BetaRequestMCPServerURLDefinitionParam `json:"mcp_servers,omitzero"`
5478 // System prompt.
5479 //
5480 // A system prompt is a way of providing context and instructions to Claude, such
5481 // as specifying a particular goal or role. See our
5482 // [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
5483 System BetaMessageCountTokensParamsSystemUnion `json:"system,omitzero"`
5484 // Configuration for enabling Claude's extended thinking.
5485 //
5486 // When enabled, responses include `thinking` content blocks showing Claude's
5487 // thinking process before the final answer. Requires a minimum budget of 1,024
5488 // tokens and counts towards your `max_tokens` limit.
5489 //
5490 // See
5491 // [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)
5492 // for details.
5493 Thinking BetaThinkingConfigParamUnion `json:"thinking,omitzero"`
5494 // How the model should use the provided tools. The model can use a specific tool,
5495 // any available tool, decide by itself, or not use tools at all.
5496 ToolChoice BetaToolChoiceUnionParam `json:"tool_choice,omitzero"`
5497 // Definitions of tools that the model may use.
5498 //
5499 // If you include `tools` in your API request, the model may return `tool_use`
5500 // content blocks that represent the model's use of those tools. You can then run
5501 // those tools using the tool input generated by the model and then optionally
5502 // return results back to the model using `tool_result` content blocks.
5503 //
5504 // Each tool definition includes:
5505 //
5506 // - `name`: Name of the tool.
5507 // - `description`: Optional, but strongly-recommended description of the tool.
5508 // - `input_schema`: [JSON schema](https://json-schema.org/draft/2020-12) for the
5509 // tool `input` shape that the model will produce in `tool_use` output content
5510 // blocks.
5511 //
5512 // For example, if you defined `tools` as:
5513 //
5514 // ```json
5515 // [
5516 //
5517 // {
5518 // "name": "get_stock_price",
5519 // "description": "Get the current stock price for a given ticker symbol.",
5520 // "input_schema": {
5521 // "type": "object",
5522 // "properties": {
5523 // "ticker": {
5524 // "type": "string",
5525 // "description": "The stock ticker symbol, e.g. AAPL for Apple Inc."
5526 // }
5527 // },
5528 // "required": ["ticker"]
5529 // }
5530 // }
5531 //
5532 // ]
5533 // ```
5534 //
5535 // And then asked the model "What's the S&P 500 at today?", the model might produce
5536 // `tool_use` content blocks in the response like this:
5537 //
5538 // ```json
5539 // [
5540 //
5541 // {
5542 // "type": "tool_use",
5543 // "id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
5544 // "name": "get_stock_price",
5545 // "input": { "ticker": "^GSPC" }
5546 // }
5547 //
5548 // ]
5549 // ```
5550 //
5551 // You might then run your `get_stock_price` tool with `{"ticker": "^GSPC"}` as an
5552 // input, and return the following back to the model in a subsequent `user`
5553 // message:
5554 //
5555 // ```json
5556 // [
5557 //
5558 // {
5559 // "type": "tool_result",
5560 // "tool_use_id": "toolu_01D7FLrfh4GYq7yT1ULFeyMV",
5561 // "content": "259.75 USD"
5562 // }
5563 //
5564 // ]
5565 // ```
5566 //
5567 // Tools can be used for workflows that include running client-side tools and
5568 // functions, or more generally whenever you want the model to produce a particular
5569 // JSON structure of output.
5570 //
5571 // See our [guide](https://docs.anthropic.com/en/docs/tool-use) for more details.
5572 Tools []BetaMessageCountTokensParamsToolUnion `json:"tools,omitzero"`
5573 // Optional header to specify the beta version(s) you want to use.
5574 Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
5575 paramObj
5576}
5577
5578func (r BetaMessageCountTokensParams) MarshalJSON() (data []byte, err error) {
5579 type shadow BetaMessageCountTokensParams
5580 return param.MarshalObject(r, (*shadow)(&r))
5581}
5582func (r *BetaMessageCountTokensParams) UnmarshalJSON(data []byte) error {
5583 return apijson.UnmarshalRoot(data, r)
5584}
5585
5586// Only one field can be non-zero.
5587//
5588// Use [param.IsOmitted] to confirm if a field is set.
5589type BetaMessageCountTokensParamsSystemUnion struct {
5590 OfString param.Opt[string] `json:",omitzero,inline"`
5591 OfBetaTextBlockArray []BetaTextBlockParam `json:",omitzero,inline"`
5592 paramUnion
5593}
5594
5595func (u BetaMessageCountTokensParamsSystemUnion) MarshalJSON() ([]byte, error) {
5596 return param.MarshalUnion(u, u.OfString, u.OfBetaTextBlockArray)
5597}
5598func (u *BetaMessageCountTokensParamsSystemUnion) UnmarshalJSON(data []byte) error {
5599 return apijson.UnmarshalRoot(data, u)
5600}
5601
5602func (u *BetaMessageCountTokensParamsSystemUnion) asAny() any {
5603 if !param.IsOmitted(u.OfString) {
5604 return &u.OfString.Value
5605 } else if !param.IsOmitted(u.OfBetaTextBlockArray) {
5606 return &u.OfBetaTextBlockArray
5607 }
5608 return nil
5609}
5610
5611// Only one field can be non-zero.
5612//
5613// Use [param.IsOmitted] to confirm if a field is set.
5614type BetaMessageCountTokensParamsToolUnion struct {
5615 OfTool *BetaToolParam `json:",omitzero,inline"`
5616 OfComputerUseTool20241022 *BetaToolComputerUse20241022Param `json:",omitzero,inline"`
5617 OfBashTool20241022 *BetaToolBash20241022Param `json:",omitzero,inline"`
5618 OfTextEditor20241022 *BetaToolTextEditor20241022Param `json:",omitzero,inline"`
5619 OfComputerUseTool20250124 *BetaToolComputerUse20250124Param `json:",omitzero,inline"`
5620 OfBashTool20250124 *BetaToolBash20250124Param `json:",omitzero,inline"`
5621 OfTextEditor20250124 *BetaToolTextEditor20250124Param `json:",omitzero,inline"`
5622 OfTextEditor20250429 *BetaToolTextEditor20250429Param `json:",omitzero,inline"`
5623 OfWebSearchTool20250305 *BetaWebSearchTool20250305Param `json:",omitzero,inline"`
5624 OfCodeExecutionTool20250522 *BetaCodeExecutionTool20250522Param `json:",omitzero,inline"`
5625 paramUnion
5626}
5627
5628func (u BetaMessageCountTokensParamsToolUnion) MarshalJSON() ([]byte, error) {
5629 return param.MarshalUnion(u, u.OfTool,
5630 u.OfComputerUseTool20241022,
5631 u.OfBashTool20241022,
5632 u.OfTextEditor20241022,
5633 u.OfComputerUseTool20250124,
5634 u.OfBashTool20250124,
5635 u.OfTextEditor20250124,
5636 u.OfTextEditor20250429,
5637 u.OfWebSearchTool20250305,
5638 u.OfCodeExecutionTool20250522)
5639}
5640func (u *BetaMessageCountTokensParamsToolUnion) UnmarshalJSON(data []byte) error {
5641 return apijson.UnmarshalRoot(data, u)
5642}
5643
5644func (u *BetaMessageCountTokensParamsToolUnion) asAny() any {
5645 if !param.IsOmitted(u.OfTool) {
5646 return u.OfTool
5647 } else if !param.IsOmitted(u.OfComputerUseTool20241022) {
5648 return u.OfComputerUseTool20241022
5649 } else if !param.IsOmitted(u.OfBashTool20241022) {
5650 return u.OfBashTool20241022
5651 } else if !param.IsOmitted(u.OfTextEditor20241022) {
5652 return u.OfTextEditor20241022
5653 } else if !param.IsOmitted(u.OfComputerUseTool20250124) {
5654 return u.OfComputerUseTool20250124
5655 } else if !param.IsOmitted(u.OfBashTool20250124) {
5656 return u.OfBashTool20250124
5657 } else if !param.IsOmitted(u.OfTextEditor20250124) {
5658 return u.OfTextEditor20250124
5659 } else if !param.IsOmitted(u.OfTextEditor20250429) {
5660 return u.OfTextEditor20250429
5661 } else if !param.IsOmitted(u.OfWebSearchTool20250305) {
5662 return u.OfWebSearchTool20250305
5663 } else if !param.IsOmitted(u.OfCodeExecutionTool20250522) {
5664 return u.OfCodeExecutionTool20250522
5665 }
5666 return nil
5667}
5668
5669// Returns a pointer to the underlying variant's property, if present.
5670func (u BetaMessageCountTokensParamsToolUnion) GetInputSchema() *BetaToolInputSchemaParam {
5671 if vt := u.OfTool; vt != nil {
5672 return &vt.InputSchema
5673 }
5674 return nil
5675}
5676
5677// Returns a pointer to the underlying variant's property, if present.
5678func (u BetaMessageCountTokensParamsToolUnion) GetDescription() *string {
5679 if vt := u.OfTool; vt != nil && vt.Description.Valid() {
5680 return &vt.Description.Value
5681 }
5682 return nil
5683}
5684
5685// Returns a pointer to the underlying variant's property, if present.
5686func (u BetaMessageCountTokensParamsToolUnion) GetAllowedDomains() []string {
5687 if vt := u.OfWebSearchTool20250305; vt != nil {
5688 return vt.AllowedDomains
5689 }
5690 return nil
5691}
5692
5693// Returns a pointer to the underlying variant's property, if present.
5694func (u BetaMessageCountTokensParamsToolUnion) GetBlockedDomains() []string {
5695 if vt := u.OfWebSearchTool20250305; vt != nil {
5696 return vt.BlockedDomains
5697 }
5698 return nil
5699}
5700
5701// Returns a pointer to the underlying variant's property, if present.
5702func (u BetaMessageCountTokensParamsToolUnion) GetMaxUses() *int64 {
5703 if vt := u.OfWebSearchTool20250305; vt != nil && vt.MaxUses.Valid() {
5704 return &vt.MaxUses.Value
5705 }
5706 return nil
5707}
5708
5709// Returns a pointer to the underlying variant's property, if present.
5710func (u BetaMessageCountTokensParamsToolUnion) GetUserLocation() *BetaWebSearchTool20250305UserLocationParam {
5711 if vt := u.OfWebSearchTool20250305; vt != nil {
5712 return &vt.UserLocation
5713 }
5714 return nil
5715}
5716
5717// Returns a pointer to the underlying variant's property, if present.
5718func (u BetaMessageCountTokensParamsToolUnion) GetName() *string {
5719 if vt := u.OfTool; vt != nil {
5720 return (*string)(&vt.Name)
5721 } else if vt := u.OfComputerUseTool20241022; vt != nil {
5722 return (*string)(&vt.Name)
5723 } else if vt := u.OfBashTool20241022; vt != nil {
5724 return (*string)(&vt.Name)
5725 } else if vt := u.OfTextEditor20241022; vt != nil {
5726 return (*string)(&vt.Name)
5727 } else if vt := u.OfComputerUseTool20250124; vt != nil {
5728 return (*string)(&vt.Name)
5729 } else if vt := u.OfBashTool20250124; vt != nil {
5730 return (*string)(&vt.Name)
5731 } else if vt := u.OfTextEditor20250124; vt != nil {
5732 return (*string)(&vt.Name)
5733 } else if vt := u.OfTextEditor20250429; vt != nil {
5734 return (*string)(&vt.Name)
5735 } else if vt := u.OfWebSearchTool20250305; vt != nil {
5736 return (*string)(&vt.Name)
5737 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
5738 return (*string)(&vt.Name)
5739 }
5740 return nil
5741}
5742
5743// Returns a pointer to the underlying variant's property, if present.
5744func (u BetaMessageCountTokensParamsToolUnion) GetType() *string {
5745 if vt := u.OfTool; vt != nil {
5746 return (*string)(&vt.Type)
5747 } else if vt := u.OfComputerUseTool20241022; vt != nil {
5748 return (*string)(&vt.Type)
5749 } else if vt := u.OfBashTool20241022; vt != nil {
5750 return (*string)(&vt.Type)
5751 } else if vt := u.OfTextEditor20241022; vt != nil {
5752 return (*string)(&vt.Type)
5753 } else if vt := u.OfComputerUseTool20250124; vt != nil {
5754 return (*string)(&vt.Type)
5755 } else if vt := u.OfBashTool20250124; vt != nil {
5756 return (*string)(&vt.Type)
5757 } else if vt := u.OfTextEditor20250124; vt != nil {
5758 return (*string)(&vt.Type)
5759 } else if vt := u.OfTextEditor20250429; vt != nil {
5760 return (*string)(&vt.Type)
5761 } else if vt := u.OfWebSearchTool20250305; vt != nil {
5762 return (*string)(&vt.Type)
5763 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
5764 return (*string)(&vt.Type)
5765 }
5766 return nil
5767}
5768
5769// Returns a pointer to the underlying variant's property, if present.
5770func (u BetaMessageCountTokensParamsToolUnion) GetDisplayHeightPx() *int64 {
5771 if vt := u.OfComputerUseTool20241022; vt != nil {
5772 return (*int64)(&vt.DisplayHeightPx)
5773 } else if vt := u.OfComputerUseTool20250124; vt != nil {
5774 return (*int64)(&vt.DisplayHeightPx)
5775 }
5776 return nil
5777}
5778
5779// Returns a pointer to the underlying variant's property, if present.
5780func (u BetaMessageCountTokensParamsToolUnion) GetDisplayWidthPx() *int64 {
5781 if vt := u.OfComputerUseTool20241022; vt != nil {
5782 return (*int64)(&vt.DisplayWidthPx)
5783 } else if vt := u.OfComputerUseTool20250124; vt != nil {
5784 return (*int64)(&vt.DisplayWidthPx)
5785 }
5786 return nil
5787}
5788
5789// Returns a pointer to the underlying variant's property, if present.
5790func (u BetaMessageCountTokensParamsToolUnion) GetDisplayNumber() *int64 {
5791 if vt := u.OfComputerUseTool20241022; vt != nil && vt.DisplayNumber.Valid() {
5792 return &vt.DisplayNumber.Value
5793 } else if vt := u.OfComputerUseTool20250124; vt != nil && vt.DisplayNumber.Valid() {
5794 return &vt.DisplayNumber.Value
5795 }
5796 return nil
5797}
5798
5799// Returns a pointer to the underlying variant's CacheControl property, if present.
5800func (u BetaMessageCountTokensParamsToolUnion) GetCacheControl() *BetaCacheControlEphemeralParam {
5801 if vt := u.OfTool; vt != nil {
5802 return &vt.CacheControl
5803 } else if vt := u.OfComputerUseTool20241022; vt != nil {
5804 return &vt.CacheControl
5805 } else if vt := u.OfBashTool20241022; vt != nil {
5806 return &vt.CacheControl
5807 } else if vt := u.OfTextEditor20241022; vt != nil {
5808 return &vt.CacheControl
5809 } else if vt := u.OfComputerUseTool20250124; vt != nil {
5810 return &vt.CacheControl
5811 } else if vt := u.OfBashTool20250124; vt != nil {
5812 return &vt.CacheControl
5813 } else if vt := u.OfTextEditor20250124; vt != nil {
5814 return &vt.CacheControl
5815 } else if vt := u.OfTextEditor20250429; vt != nil {
5816 return &vt.CacheControl
5817 } else if vt := u.OfWebSearchTool20250305; vt != nil {
5818 return &vt.CacheControl
5819 } else if vt := u.OfCodeExecutionTool20250522; vt != nil {
5820 return &vt.CacheControl
5821 }
5822 return nil
5823}