-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathbetamessage.go
More file actions
12345 lines (11283 loc) · 481 KB
/
betamessage.go
File metadata and controls
12345 lines (11283 loc) · 481 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package anthropic
import (
"context"
"encoding/json"
"fmt"
"net/http"
"slices"
"time"
"github.com/anthropics/anthropic-sdk-go/internal/apijson"
"github.com/anthropics/anthropic-sdk-go/internal/paramutil"
"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/anthropics/anthropic-sdk-go/packages/param"
"github.com/anthropics/anthropic-sdk-go/packages/respjson"
"github.com/anthropics/anthropic-sdk-go/packages/ssestream"
"github.com/anthropics/anthropic-sdk-go/shared/constant"
)
// BetaMessageService contains methods and other services that help with
// interacting with the anthropic API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBetaMessageService] method instead.
type BetaMessageService struct {
Options []option.RequestOption
Batches BetaMessageBatchService
}
// NewBetaMessageService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewBetaMessageService(opts ...option.RequestOption) (r BetaMessageService) {
r = BetaMessageService{}
r.Options = opts
r.Batches = NewBetaMessageBatchService(opts...)
return
}
// Send a structured list of input messages with text and/or image content, and the
// model will generate the next message in the conversation.
//
// The Messages API can be used for either single queries or stateless multi-turn
// conversations.
//
// Learn more about the Messages API in our
// [user guide](https://docs.claude.com/en/docs/initial-setup)
//
// Note: If you choose to set a timeout for this request, we recommend 10 minutes.
func (r *BetaMessageService) New(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (res *BetaMessage, err error) {
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
// For non-streaming requests, calculate the appropriate timeout based on maxTokens
// and check against model-specific limits
timeout, timeoutErr := CalculateNonStreamingTimeout(int(params.MaxTokens), params.Model, opts)
if timeoutErr != nil {
return nil, timeoutErr
}
opts = append(opts, option.WithRequestTimeout(timeout))
path := "v1/messages?beta=true"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Send a structured list of input messages with text and/or image content, and the
// model will generate the next message in the conversation.
//
// The Messages API can be used for either single queries or stateless multi-turn
// conversations.
//
// Learn more about the Messages API in our
// [user guide](https://docs.claude.com/en/docs/initial-setup)
//
// Note: If you choose to set a timeout for this request, we recommend 10 minutes.
func (r *BetaMessageService) NewStreaming(ctx context.Context, params BetaMessageNewParams, opts ...option.RequestOption) (stream *ssestream.Stream[BetaRawMessageStreamEventUnion]) {
var (
raw *http.Response
err error
)
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
opts = append(opts, option.WithJSONSet("stream", true))
path := "v1/messages?beta=true"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &raw, opts...)
return ssestream.NewStream[BetaRawMessageStreamEventUnion](ssestream.NewDecoder(raw), err)
}
// Count the number of tokens in a Message.
//
// The Token Count API can be used to count the number of tokens in a Message,
// including tools, images, and documents, without creating it.
//
// Learn more about token counting in our
// [user guide](https://docs.claude.com/en/docs/build-with-claude/token-counting)
func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessageCountTokensParams, opts ...option.RequestOption) (res *BetaMessageTokensCount, err error) {
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
path := "v1/messages/count_tokens?beta=true"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Token usage for an advisor sub-inference iteration.
type BetaAdvisorMessageIterationUsage struct {
// Breakdown of cached tokens by TTL
CacheCreation BetaCacheCreation `json:"cache_creation" api:"required"`
// The number of input tokens used to create the cache entry.
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens" api:"required"`
// The number of input tokens read from the cache.
CacheReadInputTokens int64 `json:"cache_read_input_tokens" api:"required"`
// The number of input tokens which were used.
InputTokens int64 `json:"input_tokens" api:"required"`
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model Model `json:"model" api:"required"`
// The number of output tokens which were used.
OutputTokens int64 `json:"output_tokens" api:"required"`
// Usage for an advisor sub-inference iteration
Type constant.AdvisorMessage `json:"type" default:"advisor_message"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CacheCreation respjson.Field
CacheCreationInputTokens respjson.Field
CacheReadInputTokens respjson.Field
InputTokens respjson.Field
Model respjson.Field
OutputTokens respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAdvisorMessageIterationUsage) RawJSON() string { return r.JSON.raw }
func (r *BetaAdvisorMessageIterationUsage) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAdvisorRedactedResultBlock struct {
// Opaque blob containing the advisor's output. Round-trip verbatim; do not inspect
// or modify.
EncryptedContent string `json:"encrypted_content" api:"required"`
Type constant.AdvisorRedactedResult `json:"type" default:"advisor_redacted_result"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
EncryptedContent respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAdvisorRedactedResultBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaAdvisorRedactedResultBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties EncryptedContent, Type are required.
type BetaAdvisorRedactedResultBlockParam struct {
// Opaque blob produced by a prior response; must be round-tripped verbatim.
EncryptedContent string `json:"encrypted_content" api:"required"`
// This field can be elided, and will marshal its zero value as
// "advisor_redacted_result".
Type constant.AdvisorRedactedResult `json:"type" default:"advisor_redacted_result"`
paramObj
}
func (r BetaAdvisorRedactedResultBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaAdvisorRedactedResultBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAdvisorRedactedResultBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAdvisorResultBlock struct {
Text string `json:"text" api:"required"`
Type constant.AdvisorResult `json:"type" default:"advisor_result"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Text respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAdvisorResultBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaAdvisorResultBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Text, Type are required.
type BetaAdvisorResultBlockParam struct {
Text string `json:"text" api:"required"`
// This field can be elided, and will marshal its zero value as "advisor_result".
Type constant.AdvisorResult `json:"type" default:"advisor_result"`
paramObj
}
func (r BetaAdvisorResultBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaAdvisorResultBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAdvisorResultBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Model, Name, Type are required.
type BetaAdvisorTool20260301Param struct {
// The model that will complete your prompt.\n\nSee
// [models](https://docs.anthropic.com/en/docs/models-overview) for additional
// details and options.
Model Model `json:"model,omitzero" api:"required"`
// Maximum number of times the tool can be used in the API request.
MaxUses param.Opt[int64] `json:"max_uses,omitzero"`
// If true, tool will not be included in initial system prompt. Only loaded when
// returned via tool_reference from tool search.
DeferLoading param.Opt[bool] `json:"defer_loading,omitzero"`
// When true, guarantees schema validation on tool names and inputs
Strict param.Opt[bool] `json:"strict,omitzero"`
// Any of "direct", "code_execution_20250825", "code_execution_20260120".
AllowedCallers []string `json:"allowed_callers,omitzero"`
// Create a cache control breakpoint at this content block.
CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
// Caching for the advisor's own prompt. When set, each advisor call writes a cache
// entry at the given TTL so subsequent calls in the same conversation read the
// stable prefix. When omitted, the advisor prompt is not cached.
Caching BetaCacheControlEphemeralParam `json:"caching,omitzero"`
// Name of the tool.
//
// This is how the tool will be called by the model and in `tool_use` blocks.
//
// This field can be elided, and will marshal its zero value as "advisor".
Name constant.Advisor `json:"name" default:"advisor"`
// This field can be elided, and will marshal its zero value as "advisor_20260301".
Type constant.Advisor20260301 `json:"type" default:"advisor_20260301"`
paramObj
}
func (r BetaAdvisorTool20260301Param) MarshalJSON() (data []byte, err error) {
type shadow BetaAdvisorTool20260301Param
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAdvisorTool20260301Param) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAdvisorToolResultBlock struct {
Content BetaAdvisorToolResultBlockContentUnion `json:"content" api:"required"`
ToolUseID string `json:"tool_use_id" api:"required"`
Type constant.AdvisorToolResult `json:"type" default:"advisor_tool_result"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Content respjson.Field
ToolUseID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAdvisorToolResultBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaAdvisorToolResultBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaAdvisorToolResultBlockContentUnion contains all possible properties and
// values from [BetaAdvisorToolResultError], [BetaAdvisorResultBlock],
// [BetaAdvisorRedactedResultBlock].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaAdvisorToolResultBlockContentUnion struct {
// This field is from variant [BetaAdvisorToolResultError].
ErrorCode BetaAdvisorToolResultErrorErrorCode `json:"error_code"`
Type string `json:"type"`
// This field is from variant [BetaAdvisorResultBlock].
Text string `json:"text"`
// This field is from variant [BetaAdvisorRedactedResultBlock].
EncryptedContent string `json:"encrypted_content"`
JSON struct {
ErrorCode respjson.Field
Type respjson.Field
Text respjson.Field
EncryptedContent respjson.Field
raw string
} `json:"-"`
}
func (u BetaAdvisorToolResultBlockContentUnion) AsResponseAdvisorToolResultError() (v BetaAdvisorToolResultError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaAdvisorToolResultBlockContentUnion) AsResponseAdvisorResultBlock() (v BetaAdvisorResultBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaAdvisorToolResultBlockContentUnion) AsResponseAdvisorRedactedResultBlock() (v BetaAdvisorRedactedResultBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaAdvisorToolResultBlockContentUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaAdvisorToolResultBlockContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Content, ToolUseID, Type are required.
type BetaAdvisorToolResultBlockParam struct {
Content BetaAdvisorToolResultBlockParamContentUnion `json:"content,omitzero" api:"required"`
ToolUseID string `json:"tool_use_id" api:"required"`
// Create a cache control breakpoint at this content block.
CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
// This field can be elided, and will marshal its zero value as
// "advisor_tool_result".
Type constant.AdvisorToolResult `json:"type" default:"advisor_tool_result"`
paramObj
}
func (r BetaAdvisorToolResultBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaAdvisorToolResultBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAdvisorToolResultBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type BetaAdvisorToolResultBlockParamContentUnion struct {
OfRequestAdvisorToolResultError *BetaAdvisorToolResultErrorParam `json:",omitzero,inline"`
OfRequestAdvisorResultBlock *BetaAdvisorResultBlockParam `json:",omitzero,inline"`
OfRequestAdvisorRedactedResultBlock *BetaAdvisorRedactedResultBlockParam `json:",omitzero,inline"`
paramUnion
}
func (u BetaAdvisorToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfRequestAdvisorToolResultError, u.OfRequestAdvisorResultBlock, u.OfRequestAdvisorRedactedResultBlock)
}
func (u *BetaAdvisorToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *BetaAdvisorToolResultBlockParamContentUnion) asAny() any {
if !param.IsOmitted(u.OfRequestAdvisorToolResultError) {
return u.OfRequestAdvisorToolResultError
} else if !param.IsOmitted(u.OfRequestAdvisorResultBlock) {
return u.OfRequestAdvisorResultBlock
} else if !param.IsOmitted(u.OfRequestAdvisorRedactedResultBlock) {
return u.OfRequestAdvisorRedactedResultBlock
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaAdvisorToolResultBlockParamContentUnion) GetErrorCode() *string {
if vt := u.OfRequestAdvisorToolResultError; vt != nil {
return (*string)(&vt.ErrorCode)
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaAdvisorToolResultBlockParamContentUnion) GetText() *string {
if vt := u.OfRequestAdvisorResultBlock; vt != nil {
return &vt.Text
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaAdvisorToolResultBlockParamContentUnion) GetEncryptedContent() *string {
if vt := u.OfRequestAdvisorRedactedResultBlock; vt != nil {
return &vt.EncryptedContent
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaAdvisorToolResultBlockParamContentUnion) GetType() *string {
if vt := u.OfRequestAdvisorToolResultError; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfRequestAdvisorResultBlock; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfRequestAdvisorRedactedResultBlock; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
type BetaAdvisorToolResultError struct {
// Any of "max_uses_exceeded", "prompt_too_long", "too_many_requests",
// "overloaded", "unavailable", "execution_time_exceeded".
ErrorCode BetaAdvisorToolResultErrorErrorCode `json:"error_code" api:"required"`
Type constant.AdvisorToolResultError `json:"type" default:"advisor_tool_result_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ErrorCode respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaAdvisorToolResultError) RawJSON() string { return r.JSON.raw }
func (r *BetaAdvisorToolResultError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAdvisorToolResultErrorErrorCode string
const (
BetaAdvisorToolResultErrorErrorCodeMaxUsesExceeded BetaAdvisorToolResultErrorErrorCode = "max_uses_exceeded"
BetaAdvisorToolResultErrorErrorCodePromptTooLong BetaAdvisorToolResultErrorErrorCode = "prompt_too_long"
BetaAdvisorToolResultErrorErrorCodeTooManyRequests BetaAdvisorToolResultErrorErrorCode = "too_many_requests"
BetaAdvisorToolResultErrorErrorCodeOverloaded BetaAdvisorToolResultErrorErrorCode = "overloaded"
BetaAdvisorToolResultErrorErrorCodeUnavailable BetaAdvisorToolResultErrorErrorCode = "unavailable"
BetaAdvisorToolResultErrorErrorCodeExecutionTimeExceeded BetaAdvisorToolResultErrorErrorCode = "execution_time_exceeded"
)
// The properties ErrorCode, Type are required.
type BetaAdvisorToolResultErrorParam struct {
// Any of "max_uses_exceeded", "prompt_too_long", "too_many_requests",
// "overloaded", "unavailable", "execution_time_exceeded".
ErrorCode BetaAdvisorToolResultErrorParamErrorCode `json:"error_code,omitzero" api:"required"`
// This field can be elided, and will marshal its zero value as
// "advisor_tool_result_error".
Type constant.AdvisorToolResultError `json:"type" default:"advisor_tool_result_error"`
paramObj
}
func (r BetaAdvisorToolResultErrorParam) MarshalJSON() (data []byte, err error) {
type shadow BetaAdvisorToolResultErrorParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAdvisorToolResultErrorParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaAdvisorToolResultErrorParamErrorCode string
const (
BetaAdvisorToolResultErrorParamErrorCodeMaxUsesExceeded BetaAdvisorToolResultErrorParamErrorCode = "max_uses_exceeded"
BetaAdvisorToolResultErrorParamErrorCodePromptTooLong BetaAdvisorToolResultErrorParamErrorCode = "prompt_too_long"
BetaAdvisorToolResultErrorParamErrorCodeTooManyRequests BetaAdvisorToolResultErrorParamErrorCode = "too_many_requests"
BetaAdvisorToolResultErrorParamErrorCodeOverloaded BetaAdvisorToolResultErrorParamErrorCode = "overloaded"
BetaAdvisorToolResultErrorParamErrorCodeUnavailable BetaAdvisorToolResultErrorParamErrorCode = "unavailable"
BetaAdvisorToolResultErrorParamErrorCodeExecutionTimeExceeded BetaAdvisorToolResultErrorParamErrorCode = "execution_time_exceeded"
)
func NewBetaAllThinkingTurnsParam() BetaAllThinkingTurnsParam {
return BetaAllThinkingTurnsParam{
Type: "all",
}
}
// This struct has a constant value, construct it with
// [NewBetaAllThinkingTurnsParam].
type BetaAllThinkingTurnsParam struct {
Type constant.All `json:"type" default:"all"`
paramObj
}
func (r BetaAllThinkingTurnsParam) MarshalJSON() (data []byte, err error) {
type shadow BetaAllThinkingTurnsParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaAllThinkingTurnsParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Data, MediaType, Type are required.
type BetaBase64ImageSourceParam struct {
Data string `json:"data" api:"required" format:"byte"`
// Any of "image/jpeg", "image/png", "image/gif", "image/webp".
MediaType BetaBase64ImageSourceMediaType `json:"media_type,omitzero" api:"required"`
// This field can be elided, and will marshal its zero value as "base64".
Type constant.Base64 `json:"type" default:"base64"`
paramObj
}
func (r BetaBase64ImageSourceParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBase64ImageSourceParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBase64ImageSourceParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBase64ImageSourceMediaType string
const (
BetaBase64ImageSourceMediaTypeImageJPEG BetaBase64ImageSourceMediaType = "image/jpeg"
BetaBase64ImageSourceMediaTypeImagePNG BetaBase64ImageSourceMediaType = "image/png"
BetaBase64ImageSourceMediaTypeImageGIF BetaBase64ImageSourceMediaType = "image/gif"
BetaBase64ImageSourceMediaTypeImageWebP BetaBase64ImageSourceMediaType = "image/webp"
)
type BetaBase64PDFSource struct {
Data string `json:"data" api:"required" format:"byte"`
MediaType constant.ApplicationPDF `json:"media_type" default:"application/pdf"`
Type constant.Base64 `json:"type" default:"base64"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBase64PDFSource) RawJSON() string { return r.JSON.raw }
func (r *BetaBase64PDFSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this BetaBase64PDFSource to a BetaBase64PDFSourceParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// BetaBase64PDFSourceParam.Overrides()
func (r BetaBase64PDFSource) ToParam() BetaBase64PDFSourceParam {
return param.Override[BetaBase64PDFSourceParam](json.RawMessage(r.RawJSON()))
}
// The properties Data, MediaType, Type are required.
type BetaBase64PDFSourceParam struct {
Data string `json:"data" api:"required" format:"byte"`
// This field can be elided, and will marshal its zero value as "application/pdf".
MediaType constant.ApplicationPDF `json:"media_type" default:"application/pdf"`
// This field can be elided, and will marshal its zero value as "base64".
Type constant.Base64 `json:"type" default:"base64"`
paramObj
}
func (r BetaBase64PDFSourceParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBase64PDFSourceParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBase64PDFSourceParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBashCodeExecutionOutputBlock struct {
FileID string `json:"file_id" api:"required"`
Type constant.BashCodeExecutionOutput `json:"type" default:"bash_code_execution_output"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FileID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBashCodeExecutionOutputBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaBashCodeExecutionOutputBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties FileID, Type are required.
type BetaBashCodeExecutionOutputBlockParam struct {
FileID string `json:"file_id" api:"required"`
// This field can be elided, and will marshal its zero value as
// "bash_code_execution_output".
Type constant.BashCodeExecutionOutput `json:"type" default:"bash_code_execution_output"`
paramObj
}
func (r BetaBashCodeExecutionOutputBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBashCodeExecutionOutputBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBashCodeExecutionOutputBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBashCodeExecutionResultBlock struct {
Content []BetaBashCodeExecutionOutputBlock `json:"content" api:"required"`
ReturnCode int64 `json:"return_code" api:"required"`
Stderr string `json:"stderr" api:"required"`
Stdout string `json:"stdout" api:"required"`
Type constant.BashCodeExecutionResult `json:"type" default:"bash_code_execution_result"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Content respjson.Field
ReturnCode respjson.Field
Stderr respjson.Field
Stdout respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBashCodeExecutionResultBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaBashCodeExecutionResultBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Content, ReturnCode, Stderr, Stdout, Type are required.
type BetaBashCodeExecutionResultBlockParam struct {
Content []BetaBashCodeExecutionOutputBlockParam `json:"content,omitzero" api:"required"`
ReturnCode int64 `json:"return_code" api:"required"`
Stderr string `json:"stderr" api:"required"`
Stdout string `json:"stdout" api:"required"`
// This field can be elided, and will marshal its zero value as
// "bash_code_execution_result".
Type constant.BashCodeExecutionResult `json:"type" default:"bash_code_execution_result"`
paramObj
}
func (r BetaBashCodeExecutionResultBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBashCodeExecutionResultBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBashCodeExecutionResultBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBashCodeExecutionToolResultBlock struct {
Content BetaBashCodeExecutionToolResultBlockContentUnion `json:"content" api:"required"`
ToolUseID string `json:"tool_use_id" api:"required"`
Type constant.BashCodeExecutionToolResult `json:"type" default:"bash_code_execution_tool_result"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Content respjson.Field
ToolUseID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBashCodeExecutionToolResultBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaBashCodeExecutionToolResultBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaBashCodeExecutionToolResultBlockContentUnion contains all possible
// properties and values from [BetaBashCodeExecutionToolResultError],
// [BetaBashCodeExecutionResultBlock].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaBashCodeExecutionToolResultBlockContentUnion struct {
// This field is from variant [BetaBashCodeExecutionToolResultError].
ErrorCode BetaBashCodeExecutionToolResultErrorErrorCode `json:"error_code"`
Type string `json:"type"`
// This field is from variant [BetaBashCodeExecutionResultBlock].
Content []BetaBashCodeExecutionOutputBlock `json:"content"`
// This field is from variant [BetaBashCodeExecutionResultBlock].
ReturnCode int64 `json:"return_code"`
// This field is from variant [BetaBashCodeExecutionResultBlock].
Stderr string `json:"stderr"`
// This field is from variant [BetaBashCodeExecutionResultBlock].
Stdout string `json:"stdout"`
JSON struct {
ErrorCode respjson.Field
Type respjson.Field
Content respjson.Field
ReturnCode respjson.Field
Stderr respjson.Field
Stdout respjson.Field
raw string
} `json:"-"`
}
func (u BetaBashCodeExecutionToolResultBlockContentUnion) AsResponseBashCodeExecutionToolResultError() (v BetaBashCodeExecutionToolResultError) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaBashCodeExecutionToolResultBlockContentUnion) AsResponseBashCodeExecutionResultBlock() (v BetaBashCodeExecutionResultBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaBashCodeExecutionToolResultBlockContentUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaBashCodeExecutionToolResultBlockContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties Content, ToolUseID, Type are required.
type BetaBashCodeExecutionToolResultBlockParam struct {
Content BetaBashCodeExecutionToolResultBlockParamContentUnion `json:"content,omitzero" api:"required"`
ToolUseID string `json:"tool_use_id" api:"required"`
// Create a cache control breakpoint at this content block.
CacheControl BetaCacheControlEphemeralParam `json:"cache_control,omitzero"`
// This field can be elided, and will marshal its zero value as
// "bash_code_execution_tool_result".
Type constant.BashCodeExecutionToolResult `json:"type" default:"bash_code_execution_tool_result"`
paramObj
}
func (r BetaBashCodeExecutionToolResultBlockParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBashCodeExecutionToolResultBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBashCodeExecutionToolResultBlockParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type BetaBashCodeExecutionToolResultBlockParamContentUnion struct {
OfRequestBashCodeExecutionToolResultError *BetaBashCodeExecutionToolResultErrorParam `json:",omitzero,inline"`
OfRequestBashCodeExecutionResultBlock *BetaBashCodeExecutionResultBlockParam `json:",omitzero,inline"`
paramUnion
}
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfRequestBashCodeExecutionToolResultError, u.OfRequestBashCodeExecutionResultBlock)
}
func (u *BetaBashCodeExecutionToolResultBlockParamContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *BetaBashCodeExecutionToolResultBlockParamContentUnion) asAny() any {
if !param.IsOmitted(u.OfRequestBashCodeExecutionToolResultError) {
return u.OfRequestBashCodeExecutionToolResultError
} else if !param.IsOmitted(u.OfRequestBashCodeExecutionResultBlock) {
return u.OfRequestBashCodeExecutionResultBlock
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetErrorCode() *string {
if vt := u.OfRequestBashCodeExecutionToolResultError; vt != nil {
return (*string)(&vt.ErrorCode)
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetContent() []BetaBashCodeExecutionOutputBlockParam {
if vt := u.OfRequestBashCodeExecutionResultBlock; vt != nil {
return vt.Content
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetReturnCode() *int64 {
if vt := u.OfRequestBashCodeExecutionResultBlock; vt != nil {
return &vt.ReturnCode
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetStderr() *string {
if vt := u.OfRequestBashCodeExecutionResultBlock; vt != nil {
return &vt.Stderr
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetStdout() *string {
if vt := u.OfRequestBashCodeExecutionResultBlock; vt != nil {
return &vt.Stdout
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaBashCodeExecutionToolResultBlockParamContentUnion) GetType() *string {
if vt := u.OfRequestBashCodeExecutionToolResultError; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfRequestBashCodeExecutionResultBlock; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
type BetaBashCodeExecutionToolResultError struct {
// Any of "invalid_tool_input", "unavailable", "too_many_requests",
// "execution_time_exceeded", "output_file_too_large".
ErrorCode BetaBashCodeExecutionToolResultErrorErrorCode `json:"error_code" api:"required"`
Type constant.BashCodeExecutionToolResultError `json:"type" default:"bash_code_execution_tool_result_error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ErrorCode respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaBashCodeExecutionToolResultError) RawJSON() string { return r.JSON.raw }
func (r *BetaBashCodeExecutionToolResultError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBashCodeExecutionToolResultErrorErrorCode string
const (
BetaBashCodeExecutionToolResultErrorErrorCodeInvalidToolInput BetaBashCodeExecutionToolResultErrorErrorCode = "invalid_tool_input"
BetaBashCodeExecutionToolResultErrorErrorCodeUnavailable BetaBashCodeExecutionToolResultErrorErrorCode = "unavailable"
BetaBashCodeExecutionToolResultErrorErrorCodeTooManyRequests BetaBashCodeExecutionToolResultErrorErrorCode = "too_many_requests"
BetaBashCodeExecutionToolResultErrorErrorCodeExecutionTimeExceeded BetaBashCodeExecutionToolResultErrorErrorCode = "execution_time_exceeded"
BetaBashCodeExecutionToolResultErrorErrorCodeOutputFileTooLarge BetaBashCodeExecutionToolResultErrorErrorCode = "output_file_too_large"
)
// The properties ErrorCode, Type are required.
type BetaBashCodeExecutionToolResultErrorParam struct {
// Any of "invalid_tool_input", "unavailable", "too_many_requests",
// "execution_time_exceeded", "output_file_too_large".
ErrorCode BetaBashCodeExecutionToolResultErrorParamErrorCode `json:"error_code,omitzero" api:"required"`
// This field can be elided, and will marshal its zero value as
// "bash_code_execution_tool_result_error".
Type constant.BashCodeExecutionToolResultError `json:"type" default:"bash_code_execution_tool_result_error"`
paramObj
}
func (r BetaBashCodeExecutionToolResultErrorParam) MarshalJSON() (data []byte, err error) {
type shadow BetaBashCodeExecutionToolResultErrorParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaBashCodeExecutionToolResultErrorParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaBashCodeExecutionToolResultErrorParamErrorCode string
const (
BetaBashCodeExecutionToolResultErrorParamErrorCodeInvalidToolInput BetaBashCodeExecutionToolResultErrorParamErrorCode = "invalid_tool_input"
BetaBashCodeExecutionToolResultErrorParamErrorCodeUnavailable BetaBashCodeExecutionToolResultErrorParamErrorCode = "unavailable"
BetaBashCodeExecutionToolResultErrorParamErrorCodeTooManyRequests BetaBashCodeExecutionToolResultErrorParamErrorCode = "too_many_requests"
BetaBashCodeExecutionToolResultErrorParamErrorCodeExecutionTimeExceeded BetaBashCodeExecutionToolResultErrorParamErrorCode = "execution_time_exceeded"
BetaBashCodeExecutionToolResultErrorParamErrorCodeOutputFileTooLarge BetaBashCodeExecutionToolResultErrorParamErrorCode = "output_file_too_large"
)
func NewBetaCacheControlEphemeralParam() BetaCacheControlEphemeralParam {
return BetaCacheControlEphemeralParam{
Type: "ephemeral",
}
}
// This struct has a constant value, construct it with
// [NewBetaCacheControlEphemeralParam].
type BetaCacheControlEphemeralParam struct {
// The time-to-live for the cache control breakpoint.
//
// This may be one the following values:
//
// - `5m`: 5 minutes
// - `1h`: 1 hour
//
// Defaults to `5m`.
//
// Any of "5m", "1h".
TTL BetaCacheControlEphemeralTTL `json:"ttl,omitzero"`
Type constant.Ephemeral `json:"type" default:"ephemeral"`
paramObj
}
func (r BetaCacheControlEphemeralParam) MarshalJSON() (data []byte, err error) {
type shadow BetaCacheControlEphemeralParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaCacheControlEphemeralParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The time-to-live for the cache control breakpoint.
//
// This may be one the following values:
//
// - `5m`: 5 minutes
// - `1h`: 1 hour
//
// Defaults to `5m`.
type BetaCacheControlEphemeralTTL string
const (
BetaCacheControlEphemeralTTLTTL5m BetaCacheControlEphemeralTTL = "5m"
BetaCacheControlEphemeralTTLTTL1h BetaCacheControlEphemeralTTL = "1h"
)
type BetaCacheCreation struct {
// The number of input tokens used to create the 1 hour cache entry.
Ephemeral1hInputTokens int64 `json:"ephemeral_1h_input_tokens" api:"required"`
// The number of input tokens used to create the 5 minute cache entry.
Ephemeral5mInputTokens int64 `json:"ephemeral_5m_input_tokens" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Ephemeral1hInputTokens respjson.Field
Ephemeral5mInputTokens respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaCacheCreation) RawJSON() string { return r.JSON.raw }
func (r *BetaCacheCreation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaCitationCharLocation struct {
CitedText string `json:"cited_text" api:"required"`
DocumentIndex int64 `json:"document_index" api:"required"`
DocumentTitle string `json:"document_title" api:"required"`
EndCharIndex int64 `json:"end_char_index" api:"required"`
FileID string `json:"file_id" api:"required"`
StartCharIndex int64 `json:"start_char_index" api:"required"`
Type constant.CharLocation `json:"type" default:"char_location"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CitedText respjson.Field
DocumentIndex respjson.Field
DocumentTitle respjson.Field
EndCharIndex respjson.Field
FileID respjson.Field
StartCharIndex respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaCitationCharLocation) RawJSON() string { return r.JSON.raw }
func (r *BetaCitationCharLocation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The properties CitedText, DocumentIndex, DocumentTitle, EndCharIndex,
// StartCharIndex, Type are required.
type BetaCitationCharLocationParam struct {
DocumentTitle param.Opt[string] `json:"document_title,omitzero" api:"required"`
CitedText string `json:"cited_text" api:"required"`
DocumentIndex int64 `json:"document_index" api:"required"`
EndCharIndex int64 `json:"end_char_index" api:"required"`
StartCharIndex int64 `json:"start_char_index" api:"required"`
// This field can be elided, and will marshal its zero value as "char_location".
Type constant.CharLocation `json:"type" default:"char_location"`
paramObj
}
func (r BetaCitationCharLocationParam) MarshalJSON() (data []byte, err error) {
type shadow BetaCitationCharLocationParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaCitationCharLocationParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaCitationConfig struct {
Enabled bool `json:"enabled" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Enabled respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaCitationConfig) RawJSON() string { return r.JSON.raw }
func (r *BetaCitationConfig) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaCitationContentBlockLocation struct {
CitedText string `json:"cited_text" api:"required"`