diff --git a/.stats.yml b/.stats.yml
index c809f63..e7d0669 100644
--- a/.stats.yml
+++ b/.stats.yml
@@ -1,2 +1,2 @@
configured_endpoints: 21
-openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-75f0573c3d6d79650bcbd8b1b4fcf93ce146d567afeb1061cd4afccf8d1d6799.yml
+openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-7270ee0a79d885681ee507414608229f61c27f47c40f355dcd210b38aa7cddf1.yml
diff --git a/README.md b/README.md
index c370988..6358aea 100644
--- a/README.md
+++ b/README.md
@@ -54,7 +54,7 @@ func main() {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -212,7 +212,7 @@ _, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -246,7 +246,7 @@ client.Messages.New(
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
},
@@ -289,7 +289,7 @@ client.Messages.New(
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
},
diff --git a/api.md b/api.md
index 51ede65..7ddb9c3 100644
--- a/api.md
+++ b/api.md
@@ -18,13 +18,21 @@ Params Types:
- anthropic.Base64PDFSourceParam
- anthropic.CacheControlEphemeralParam
+- anthropic.CitationCharLocationParam
+- anthropic.CitationContentBlockLocationParam
+- anthropic.CitationPageLocationParam
+- anthropic.CitationsConfigParam
- anthropic.ContentBlockParamUnion
+- anthropic.ContentBlockSourceParam
+- anthropic.ContentBlockSourceContentUnionParam
- anthropic.DocumentBlockParam
- anthropic.ImageBlockParam
- anthropic.MessageParam
- anthropic.MetadataParam
- anthropic.Model
+- anthropic.PlainTextSourceParam
- anthropic.TextBlockParam
+- anthropic.TextCitationParamUnion
- anthropic.ToolParam
- anthropic.ToolChoiceUnionParam
- anthropic.ToolChoiceAnyParam
@@ -35,6 +43,10 @@ Params Types:
Response Types:
+- anthropic.CitationCharLocation
+- anthropic.CitationContentBlockLocation
+- anthropic.CitationPageLocation
+- anthropic.CitationsDelta
- anthropic.ContentBlock
- anthropic.InputJSONDelta
- anthropic.Message
@@ -49,6 +61,7 @@ Response Types:
- anthropic.MessageStopEvent
- anthropic.MessageStreamEvent
- anthropic.TextBlock
+- anthropic.TextCitation
- anthropic.TextDelta
- anthropic.ToolUseBlock
- anthropic.Usage
@@ -130,11 +143,19 @@ Params Types:
- anthropic.BetaBase64PDFBlockParam
- anthropic.BetaBase64PDFSourceParam
- anthropic.BetaCacheControlEphemeralParam
+- anthropic.BetaCitationCharLocationParam
+- anthropic.BetaCitationContentBlockLocationParam
+- anthropic.BetaCitationPageLocationParam
+- anthropic.BetaCitationsConfigParam
- anthropic.BetaContentBlockParamUnion
+- anthropic.BetaContentBlockSourceParam
+- anthropic.BetaContentBlockSourceContentUnionParam
- anthropic.BetaImageBlockParam
- anthropic.BetaMessageParam
- anthropic.BetaMetadataParam
+- anthropic.BetaPlainTextSourceParam
- anthropic.BetaTextBlockParam
+- anthropic.BetaTextCitationParamUnion
- anthropic.BetaToolParam
- anthropic.BetaToolBash20241022Param
- anthropic.BetaToolChoiceUnionParam
@@ -149,6 +170,10 @@ Params Types:
Response Types:
+- anthropic.BetaCitationCharLocation
+- anthropic.BetaCitationContentBlockLocation
+- anthropic.BetaCitationPageLocation
+- anthropic.BetaCitationsDelta
- anthropic.BetaContentBlock
- anthropic.BetaInputJSONDelta
- anthropic.BetaMessage
@@ -162,6 +187,7 @@ Response Types:
- anthropic.BetaRawMessageStopEvent
- anthropic.BetaRawMessageStreamEvent
- anthropic.BetaTextBlock
+- anthropic.BetaTextCitation
- anthropic.BetaTextDelta
- anthropic.BetaToolUseBlock
- anthropic.BetaUsage
diff --git a/betamessage.go b/betamessage.go
index 8e71df0..56dc5a9 100644
--- a/betamessage.go
+++ b/betamessage.go
@@ -91,9 +91,12 @@ func (r *BetaMessageService) CountTokens(ctx context.Context, params BetaMessage
}
type BetaBase64PDFBlockParam struct {
- Source param.Field[BetaBase64PDFSourceParam] `json:"source,required"`
- Type param.Field[BetaBase64PDFBlockType] `json:"type,required"`
- CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
+ Source param.Field[BetaBase64PDFBlockSourceUnionParam] `json:"source,required"`
+ Type param.Field[BetaBase64PDFBlockType] `json:"type,required"`
+ CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[BetaCitationsConfigParam] `json:"citations"`
+ Context param.Field[string] `json:"context"`
+ Title param.Field[string] `json:"title"`
}
func (r BetaBase64PDFBlockParam) MarshalJSON() (data []byte, err error) {
@@ -102,6 +105,56 @@ func (r BetaBase64PDFBlockParam) MarshalJSON() (data []byte, err error) {
func (r BetaBase64PDFBlockParam) implementsBetaContentBlockParamUnion() {}
+type BetaBase64PDFBlockSourceParam struct {
+ Type param.Field[BetaBase64PDFBlockSourceType] `json:"type,required"`
+ Content param.Field[interface{}] `json:"content"`
+ Data param.Field[string] `json:"data" format:"byte"`
+ MediaType param.Field[BetaBase64PDFBlockSourceMediaType] `json:"media_type"`
+}
+
+func (r BetaBase64PDFBlockSourceParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaBase64PDFBlockSourceParam) implementsBetaBase64PDFBlockSourceUnionParam() {}
+
+// Satisfied by [BetaBase64PDFSourceParam], [BetaPlainTextSourceParam],
+// [BetaContentBlockSourceParam], [BetaBase64PDFBlockSourceParam].
+type BetaBase64PDFBlockSourceUnionParam interface {
+ implementsBetaBase64PDFBlockSourceUnionParam()
+}
+
+type BetaBase64PDFBlockSourceType string
+
+const (
+ BetaBase64PDFBlockSourceTypeBase64 BetaBase64PDFBlockSourceType = "base64"
+ BetaBase64PDFBlockSourceTypeText BetaBase64PDFBlockSourceType = "text"
+ BetaBase64PDFBlockSourceTypeContent BetaBase64PDFBlockSourceType = "content"
+)
+
+func (r BetaBase64PDFBlockSourceType) IsKnown() bool {
+ switch r {
+ case BetaBase64PDFBlockSourceTypeBase64, BetaBase64PDFBlockSourceTypeText, BetaBase64PDFBlockSourceTypeContent:
+ return true
+ }
+ return false
+}
+
+type BetaBase64PDFBlockSourceMediaType string
+
+const (
+ BetaBase64PDFBlockSourceMediaTypeApplicationPDF BetaBase64PDFBlockSourceMediaType = "application/pdf"
+ BetaBase64PDFBlockSourceMediaTypeTextPlain BetaBase64PDFBlockSourceMediaType = "text/plain"
+)
+
+func (r BetaBase64PDFBlockSourceMediaType) IsKnown() bool {
+ switch r {
+ case BetaBase64PDFBlockSourceMediaTypeApplicationPDF, BetaBase64PDFBlockSourceMediaTypeTextPlain:
+ return true
+ }
+ return false
+}
+
type BetaBase64PDFBlockType string
const (
@@ -126,6 +179,8 @@ func (r BetaBase64PDFSourceParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
+func (r BetaBase64PDFSourceParam) implementsBetaBase64PDFBlockSourceUnionParam() {}
+
type BetaBase64PDFSourceMediaType string
const (
@@ -176,9 +231,390 @@ func (r BetaCacheControlEphemeralType) IsKnown() bool {
return false
}
+type BetaCitationCharLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndCharIndex int64 `json:"end_char_index,required"`
+ StartCharIndex int64 `json:"start_char_index,required"`
+ Type BetaCitationCharLocationType `json:"type,required"`
+ JSON betaCitationCharLocationJSON `json:"-"`
+}
+
+// betaCitationCharLocationJSON contains the JSON metadata for the struct
+// [BetaCitationCharLocation]
+type betaCitationCharLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndCharIndex apijson.Field
+ StartCharIndex apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *BetaCitationCharLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r betaCitationCharLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r BetaCitationCharLocation) implementsBetaCitationsDeltaCitation() {}
+
+func (r BetaCitationCharLocation) implementsBetaTextCitation() {}
+
+type BetaCitationCharLocationType string
+
+const (
+ BetaCitationCharLocationTypeCharLocation BetaCitationCharLocationType = "char_location"
+)
+
+func (r BetaCitationCharLocationType) IsKnown() bool {
+ switch r {
+ case BetaCitationCharLocationTypeCharLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationCharLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndCharIndex param.Field[int64] `json:"end_char_index,required"`
+ StartCharIndex param.Field[int64] `json:"start_char_index,required"`
+ Type param.Field[BetaCitationCharLocationParamType] `json:"type,required"`
+}
+
+func (r BetaCitationCharLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaCitationCharLocationParam) implementsBetaTextCitationParamUnion() {}
+
+type BetaCitationCharLocationParamType string
+
+const (
+ BetaCitationCharLocationParamTypeCharLocation BetaCitationCharLocationParamType = "char_location"
+)
+
+func (r BetaCitationCharLocationParamType) IsKnown() bool {
+ switch r {
+ case BetaCitationCharLocationParamTypeCharLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationContentBlockLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndBlockIndex int64 `json:"end_block_index,required"`
+ StartBlockIndex int64 `json:"start_block_index,required"`
+ Type BetaCitationContentBlockLocationType `json:"type,required"`
+ JSON betaCitationContentBlockLocationJSON `json:"-"`
+}
+
+// betaCitationContentBlockLocationJSON contains the JSON metadata for the struct
+// [BetaCitationContentBlockLocation]
+type betaCitationContentBlockLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndBlockIndex apijson.Field
+ StartBlockIndex apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *BetaCitationContentBlockLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r betaCitationContentBlockLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r BetaCitationContentBlockLocation) implementsBetaCitationsDeltaCitation() {}
+
+func (r BetaCitationContentBlockLocation) implementsBetaTextCitation() {}
+
+type BetaCitationContentBlockLocationType string
+
+const (
+ BetaCitationContentBlockLocationTypeContentBlockLocation BetaCitationContentBlockLocationType = "content_block_location"
+)
+
+func (r BetaCitationContentBlockLocationType) IsKnown() bool {
+ switch r {
+ case BetaCitationContentBlockLocationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationContentBlockLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndBlockIndex param.Field[int64] `json:"end_block_index,required"`
+ StartBlockIndex param.Field[int64] `json:"start_block_index,required"`
+ Type param.Field[BetaCitationContentBlockLocationParamType] `json:"type,required"`
+}
+
+func (r BetaCitationContentBlockLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaCitationContentBlockLocationParam) implementsBetaTextCitationParamUnion() {}
+
+type BetaCitationContentBlockLocationParamType string
+
+const (
+ BetaCitationContentBlockLocationParamTypeContentBlockLocation BetaCitationContentBlockLocationParamType = "content_block_location"
+)
+
+func (r BetaCitationContentBlockLocationParamType) IsKnown() bool {
+ switch r {
+ case BetaCitationContentBlockLocationParamTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationPageLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndPageNumber int64 `json:"end_page_number,required"`
+ StartPageNumber int64 `json:"start_page_number,required"`
+ Type BetaCitationPageLocationType `json:"type,required"`
+ JSON betaCitationPageLocationJSON `json:"-"`
+}
+
+// betaCitationPageLocationJSON contains the JSON metadata for the struct
+// [BetaCitationPageLocation]
+type betaCitationPageLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndPageNumber apijson.Field
+ StartPageNumber apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *BetaCitationPageLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r betaCitationPageLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r BetaCitationPageLocation) implementsBetaCitationsDeltaCitation() {}
+
+func (r BetaCitationPageLocation) implementsBetaTextCitation() {}
+
+type BetaCitationPageLocationType string
+
+const (
+ BetaCitationPageLocationTypePageLocation BetaCitationPageLocationType = "page_location"
+)
+
+func (r BetaCitationPageLocationType) IsKnown() bool {
+ switch r {
+ case BetaCitationPageLocationTypePageLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationPageLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndPageNumber param.Field[int64] `json:"end_page_number,required"`
+ StartPageNumber param.Field[int64] `json:"start_page_number,required"`
+ Type param.Field[BetaCitationPageLocationParamType] `json:"type,required"`
+}
+
+func (r BetaCitationPageLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaCitationPageLocationParam) implementsBetaTextCitationParamUnion() {}
+
+type BetaCitationPageLocationParamType string
+
+const (
+ BetaCitationPageLocationParamTypePageLocation BetaCitationPageLocationParamType = "page_location"
+)
+
+func (r BetaCitationPageLocationParamType) IsKnown() bool {
+ switch r {
+ case BetaCitationPageLocationParamTypePageLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationsConfigParam struct {
+ Enabled param.Field[bool] `json:"enabled"`
+}
+
+func (r BetaCitationsConfigParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+type BetaCitationsDelta struct {
+ Citation BetaCitationsDeltaCitation `json:"citation,required"`
+ Type BetaCitationsDeltaType `json:"type,required"`
+ JSON betaCitationsDeltaJSON `json:"-"`
+}
+
+// betaCitationsDeltaJSON contains the JSON metadata for the struct
+// [BetaCitationsDelta]
+type betaCitationsDeltaJSON struct {
+ Citation apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *BetaCitationsDelta) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r betaCitationsDeltaJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r BetaCitationsDelta) implementsBetaRawContentBlockDeltaEventDelta() {}
+
+type BetaCitationsDeltaCitation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ Type BetaCitationsDeltaCitationType `json:"type,required"`
+ EndBlockIndex int64 `json:"end_block_index"`
+ EndCharIndex int64 `json:"end_char_index"`
+ EndPageNumber int64 `json:"end_page_number"`
+ StartBlockIndex int64 `json:"start_block_index"`
+ StartCharIndex int64 `json:"start_char_index"`
+ StartPageNumber int64 `json:"start_page_number"`
+ JSON betaCitationsDeltaCitationJSON `json:"-"`
+ union BetaCitationsDeltaCitationUnion
+}
+
+// betaCitationsDeltaCitationJSON contains the JSON metadata for the struct
+// [BetaCitationsDeltaCitation]
+type betaCitationsDeltaCitationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ Type apijson.Field
+ EndBlockIndex apijson.Field
+ EndCharIndex apijson.Field
+ EndPageNumber apijson.Field
+ StartBlockIndex apijson.Field
+ StartCharIndex apijson.Field
+ StartPageNumber apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r betaCitationsDeltaCitationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *BetaCitationsDeltaCitation) UnmarshalJSON(data []byte) (err error) {
+ *r = BetaCitationsDeltaCitation{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [BetaCitationsDeltaCitationUnion] interface which you can cast
+// to the specific types for more type safety.
+//
+// Possible runtime types of the union are [BetaCitationCharLocation],
+// [BetaCitationPageLocation], [BetaCitationContentBlockLocation].
+func (r BetaCitationsDeltaCitation) AsUnion() BetaCitationsDeltaCitationUnion {
+ return r.union
+}
+
+// Union satisfied by [BetaCitationCharLocation], [BetaCitationPageLocation] or
+// [BetaCitationContentBlockLocation].
+type BetaCitationsDeltaCitationUnion interface {
+ implementsBetaCitationsDeltaCitation()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*BetaCitationsDeltaCitationUnion)(nil)).Elem(),
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationCharLocation{}),
+ DiscriminatorValue: "char_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationPageLocation{}),
+ DiscriminatorValue: "page_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationContentBlockLocation{}),
+ DiscriminatorValue: "content_block_location",
+ },
+ )
+}
+
+type BetaCitationsDeltaCitationType string
+
+const (
+ BetaCitationsDeltaCitationTypeCharLocation BetaCitationsDeltaCitationType = "char_location"
+ BetaCitationsDeltaCitationTypePageLocation BetaCitationsDeltaCitationType = "page_location"
+ BetaCitationsDeltaCitationTypeContentBlockLocation BetaCitationsDeltaCitationType = "content_block_location"
+)
+
+func (r BetaCitationsDeltaCitationType) IsKnown() bool {
+ switch r {
+ case BetaCitationsDeltaCitationTypeCharLocation, BetaCitationsDeltaCitationTypePageLocation, BetaCitationsDeltaCitationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type BetaCitationsDeltaType string
+
+const (
+ BetaCitationsDeltaTypeCitationsDelta BetaCitationsDeltaType = "citations_delta"
+)
+
+func (r BetaCitationsDeltaType) IsKnown() bool {
+ switch r {
+ case BetaCitationsDeltaTypeCitationsDelta:
+ return true
+ }
+ return false
+}
+
type BetaContentBlock struct {
Type BetaContentBlockType `json:"type,required"`
ID string `json:"id"`
+ // This field can have the runtime type of [[]BetaTextCitation].
+ Citations interface{} `json:"citations"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
@@ -192,6 +628,7 @@ type BetaContentBlock struct {
type betaContentBlockJSON struct {
Type apijson.Field
ID apijson.Field
+ Citations apijson.Field
Input apijson.Field
Name apijson.Field
Text apijson.Field
@@ -261,12 +698,15 @@ type BetaContentBlockParam struct {
Type param.Field[BetaContentBlockParamType] `json:"type,required"`
ID param.Field[string] `json:"id"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[interface{}] `json:"citations"`
Content param.Field[interface{}] `json:"content"`
+ Context param.Field[string] `json:"context"`
Input param.Field[interface{}] `json:"input"`
IsError param.Field[bool] `json:"is_error"`
Name param.Field[string] `json:"name"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
+ Title param.Field[string] `json:"title"`
ToolUseID param.Field[string] `json:"tool_use_id"`
}
@@ -301,6 +741,42 @@ func (r BetaContentBlockParamType) IsKnown() bool {
return false
}
+type BetaContentBlockSourceParam struct {
+ Content param.Field[BetaContentBlockSourceContentUnionParam] `json:"content,required"`
+ Type param.Field[BetaContentBlockSourceType] `json:"type,required"`
+}
+
+func (r BetaContentBlockSourceParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaContentBlockSourceParam) implementsBetaBase64PDFBlockSourceUnionParam() {}
+
+// Satisfied by [shared.UnionString],
+// [BetaContentBlockSourceContentBetaContentBlockSourceContentParam].
+type BetaContentBlockSourceContentUnionParam interface {
+ ImplementsBetaContentBlockSourceContentUnionParam()
+}
+
+type BetaContentBlockSourceContentBetaContentBlockSourceContentParam []BetaContentBlockSourceContentUnionParam
+
+func (r BetaContentBlockSourceContentBetaContentBlockSourceContentParam) ImplementsBetaContentBlockSourceContentUnionParam() {
+}
+
+type BetaContentBlockSourceType string
+
+const (
+ BetaContentBlockSourceTypeContent BetaContentBlockSourceType = "content"
+)
+
+func (r BetaContentBlockSourceType) IsKnown() bool {
+ switch r {
+ case BetaContentBlockSourceTypeContent:
+ return true
+ }
+ return false
+}
+
type BetaImageBlockParam struct {
Source param.Field[BetaImageBlockParamSource] `json:"source,required"`
Type param.Field[BetaImageBlockParamType] `json:"type,required"`
@@ -313,6 +789,8 @@ func (r BetaImageBlockParam) MarshalJSON() (data []byte, err error) {
func (r BetaImageBlockParam) implementsBetaContentBlockParamUnion() {}
+func (r BetaImageBlockParam) implementsBetaContentBlockSourceContentUnionParam() {}
+
func (r BetaImageBlockParam) implementsBetaToolResultBlockParamContentUnion() {}
type BetaImageBlockParamSource struct {
@@ -660,6 +1138,46 @@ func (r BetaMetadataParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
+type BetaPlainTextSourceParam struct {
+ Data param.Field[string] `json:"data,required"`
+ MediaType param.Field[BetaPlainTextSourceMediaType] `json:"media_type,required"`
+ Type param.Field[BetaPlainTextSourceType] `json:"type,required"`
+}
+
+func (r BetaPlainTextSourceParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaPlainTextSourceParam) implementsBetaBase64PDFBlockSourceUnionParam() {}
+
+type BetaPlainTextSourceMediaType string
+
+const (
+ BetaPlainTextSourceMediaTypeTextPlain BetaPlainTextSourceMediaType = "text/plain"
+)
+
+func (r BetaPlainTextSourceMediaType) IsKnown() bool {
+ switch r {
+ case BetaPlainTextSourceMediaTypeTextPlain:
+ return true
+ }
+ return false
+}
+
+type BetaPlainTextSourceType string
+
+const (
+ BetaPlainTextSourceTypeText BetaPlainTextSourceType = "text"
+)
+
+func (r BetaPlainTextSourceType) IsKnown() bool {
+ switch r {
+ case BetaPlainTextSourceTypeText:
+ return true
+ }
+ return false
+}
+
type BetaRawContentBlockDeltaEvent struct {
Delta BetaRawContentBlockDeltaEventDelta `json:"delta,required"`
Index int64 `json:"index,required"`
@@ -688,7 +1206,9 @@ func (r betaRawContentBlockDeltaEventJSON) RawJSON() string {
func (r BetaRawContentBlockDeltaEvent) implementsBetaRawMessageStreamEvent() {}
type BetaRawContentBlockDeltaEventDelta struct {
- Type BetaRawContentBlockDeltaEventDeltaType `json:"type,required"`
+ Type BetaRawContentBlockDeltaEventDeltaType `json:"type,required"`
+ // This field can have the runtime type of [BetaCitationsDeltaCitation].
+ Citation interface{} `json:"citation"`
PartialJSON string `json:"partial_json"`
Text string `json:"text"`
JSON betaRawContentBlockDeltaEventDeltaJSON `json:"-"`
@@ -699,6 +1219,7 @@ type BetaRawContentBlockDeltaEventDelta struct {
// [BetaRawContentBlockDeltaEventDelta]
type betaRawContentBlockDeltaEventDeltaJSON struct {
Type apijson.Field
+ Citation apijson.Field
PartialJSON apijson.Field
Text apijson.Field
raw string
@@ -721,12 +1242,14 @@ func (r *BetaRawContentBlockDeltaEventDelta) UnmarshalJSON(data []byte) (err err
// AsUnion returns a [BetaRawContentBlockDeltaEventDeltaUnion] interface which you
// can cast to the specific types for more type safety.
//
-// Possible runtime types of the union are [BetaTextDelta], [BetaInputJSONDelta].
+// Possible runtime types of the union are [BetaTextDelta], [BetaInputJSONDelta],
+// [BetaCitationsDelta].
func (r BetaRawContentBlockDeltaEventDelta) AsUnion() BetaRawContentBlockDeltaEventDeltaUnion {
return r.union
}
-// Union satisfied by [BetaTextDelta] or [BetaInputJSONDelta].
+// Union satisfied by [BetaTextDelta], [BetaInputJSONDelta] or
+// [BetaCitationsDelta].
type BetaRawContentBlockDeltaEventDeltaUnion interface {
implementsBetaRawContentBlockDeltaEventDelta()
}
@@ -734,14 +1257,21 @@ type BetaRawContentBlockDeltaEventDeltaUnion interface {
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*BetaRawContentBlockDeltaEventDeltaUnion)(nil)).Elem(),
- "",
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaTextDelta{}),
+ DiscriminatorValue: "text_delta",
+ },
apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(BetaTextDelta{}),
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaInputJSONDelta{}),
+ DiscriminatorValue: "input_json_delta",
},
apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(BetaInputJSONDelta{}),
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationsDelta{}),
+ DiscriminatorValue: "citations_delta",
},
)
}
@@ -751,11 +1281,12 @@ type BetaRawContentBlockDeltaEventDeltaType string
const (
BetaRawContentBlockDeltaEventDeltaTypeTextDelta BetaRawContentBlockDeltaEventDeltaType = "text_delta"
BetaRawContentBlockDeltaEventDeltaTypeInputJSONDelta BetaRawContentBlockDeltaEventDeltaType = "input_json_delta"
+ BetaRawContentBlockDeltaEventDeltaTypeCitationsDelta BetaRawContentBlockDeltaEventDeltaType = "citations_delta"
)
func (r BetaRawContentBlockDeltaEventDeltaType) IsKnown() bool {
switch r {
- case BetaRawContentBlockDeltaEventDeltaTypeTextDelta, BetaRawContentBlockDeltaEventDeltaTypeInputJSONDelta:
+ case BetaRawContentBlockDeltaEventDeltaTypeTextDelta, BetaRawContentBlockDeltaEventDeltaTypeInputJSONDelta, BetaRawContentBlockDeltaEventDeltaTypeCitationsDelta:
return true
}
return false
@@ -805,6 +1336,8 @@ func (r BetaRawContentBlockStartEvent) implementsBetaRawMessageStreamEvent() {}
type BetaRawContentBlockStartEventContentBlock struct {
Type BetaRawContentBlockStartEventContentBlockType `json:"type,required"`
ID string `json:"id"`
+ // This field can have the runtime type of [[]BetaTextCitation].
+ Citations interface{} `json:"citations"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
@@ -818,6 +1351,7 @@ type BetaRawContentBlockStartEventContentBlock struct {
type betaRawContentBlockStartEventContentBlockJSON struct {
Type apijson.Field
ID apijson.Field
+ Citations apijson.Field
Input apijson.Field
Name apijson.Field
Text apijson.Field
@@ -1233,13 +1767,20 @@ func (r BetaRawMessageStreamEventType) IsKnown() bool {
}
type BetaTextBlock struct {
- Text string `json:"text,required"`
- Type BetaTextBlockType `json:"type,required"`
- JSON betaTextBlockJSON `json:"-"`
+ // Citations supporting the text block.
+ //
+ // The type of citation returned will depend on the type of document being cited.
+ // Citing a PDF results in `page_location`, plain text results in `char_location`,
+ // and content document results in `content_block_location`.
+ Citations []BetaTextCitation `json:"citations,required,nullable"`
+ Text string `json:"text,required"`
+ Type BetaTextBlockType `json:"type,required"`
+ JSON betaTextBlockJSON `json:"-"`
}
// betaTextBlockJSON contains the JSON metadata for the struct [BetaTextBlock]
type betaTextBlockJSON struct {
+ Citations apijson.Field
Text apijson.Field
Type apijson.Field
raw string
@@ -1276,6 +1817,7 @@ type BetaTextBlockParam struct {
Text param.Field[string] `json:"text,required"`
Type param.Field[BetaTextBlockParamType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[[]BetaTextCitationParamUnion] `json:"citations"`
}
func (r BetaTextBlockParam) MarshalJSON() (data []byte, err error) {
@@ -1284,6 +1826,8 @@ func (r BetaTextBlockParam) MarshalJSON() (data []byte, err error) {
func (r BetaTextBlockParam) implementsBetaContentBlockParamUnion() {}
+func (r BetaTextBlockParam) implementsBetaContentBlockSourceContentUnionParam() {}
+
func (r BetaTextBlockParam) implementsBetaToolResultBlockParamContentUnion() {}
type BetaTextBlockParamType string
@@ -1300,6 +1844,145 @@ func (r BetaTextBlockParamType) IsKnown() bool {
return false
}
+type BetaTextCitation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ Type BetaTextCitationType `json:"type,required"`
+ EndBlockIndex int64 `json:"end_block_index"`
+ EndCharIndex int64 `json:"end_char_index"`
+ EndPageNumber int64 `json:"end_page_number"`
+ StartBlockIndex int64 `json:"start_block_index"`
+ StartCharIndex int64 `json:"start_char_index"`
+ StartPageNumber int64 `json:"start_page_number"`
+ JSON betaTextCitationJSON `json:"-"`
+ union BetaTextCitationUnion
+}
+
+// betaTextCitationJSON contains the JSON metadata for the struct
+// [BetaTextCitation]
+type betaTextCitationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ Type apijson.Field
+ EndBlockIndex apijson.Field
+ EndCharIndex apijson.Field
+ EndPageNumber apijson.Field
+ StartBlockIndex apijson.Field
+ StartCharIndex apijson.Field
+ StartPageNumber apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r betaTextCitationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *BetaTextCitation) UnmarshalJSON(data []byte) (err error) {
+ *r = BetaTextCitation{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [BetaTextCitationUnion] interface which you can cast to the
+// specific types for more type safety.
+//
+// Possible runtime types of the union are [BetaCitationCharLocation],
+// [BetaCitationPageLocation], [BetaCitationContentBlockLocation].
+func (r BetaTextCitation) AsUnion() BetaTextCitationUnion {
+ return r.union
+}
+
+// Union satisfied by [BetaCitationCharLocation], [BetaCitationPageLocation] or
+// [BetaCitationContentBlockLocation].
+type BetaTextCitationUnion interface {
+ implementsBetaTextCitation()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*BetaTextCitationUnion)(nil)).Elem(),
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationCharLocation{}),
+ DiscriminatorValue: "char_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationPageLocation{}),
+ DiscriminatorValue: "page_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(BetaCitationContentBlockLocation{}),
+ DiscriminatorValue: "content_block_location",
+ },
+ )
+}
+
+type BetaTextCitationType string
+
+const (
+ BetaTextCitationTypeCharLocation BetaTextCitationType = "char_location"
+ BetaTextCitationTypePageLocation BetaTextCitationType = "page_location"
+ BetaTextCitationTypeContentBlockLocation BetaTextCitationType = "content_block_location"
+)
+
+func (r BetaTextCitationType) IsKnown() bool {
+ switch r {
+ case BetaTextCitationTypeCharLocation, BetaTextCitationTypePageLocation, BetaTextCitationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type BetaTextCitationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ Type param.Field[BetaTextCitationParamType] `json:"type,required"`
+ EndBlockIndex param.Field[int64] `json:"end_block_index"`
+ EndCharIndex param.Field[int64] `json:"end_char_index"`
+ EndPageNumber param.Field[int64] `json:"end_page_number"`
+ StartBlockIndex param.Field[int64] `json:"start_block_index"`
+ StartCharIndex param.Field[int64] `json:"start_char_index"`
+ StartPageNumber param.Field[int64] `json:"start_page_number"`
+}
+
+func (r BetaTextCitationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r BetaTextCitationParam) implementsBetaTextCitationParamUnion() {}
+
+// Satisfied by [BetaCitationCharLocationParam], [BetaCitationPageLocationParam],
+// [BetaCitationContentBlockLocationParam], [BetaTextCitationParam].
+type BetaTextCitationParamUnion interface {
+ implementsBetaTextCitationParamUnion()
+}
+
+type BetaTextCitationParamType string
+
+const (
+ BetaTextCitationParamTypeCharLocation BetaTextCitationParamType = "char_location"
+ BetaTextCitationParamTypePageLocation BetaTextCitationParamType = "page_location"
+ BetaTextCitationParamTypeContentBlockLocation BetaTextCitationParamType = "content_block_location"
+)
+
+func (r BetaTextCitationParamType) IsKnown() bool {
+ switch r {
+ case BetaTextCitationParamTypeCharLocation, BetaTextCitationParamTypePageLocation, BetaTextCitationParamTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
type BetaTextDelta struct {
Text string `json:"text,required"`
Type BetaTextDeltaType `json:"type,required"`
@@ -1678,6 +2361,7 @@ func (r BetaToolResultBlockParamType) IsKnown() bool {
type BetaToolResultBlockParamContent struct {
Type param.Field[BetaToolResultBlockParamContentType] `json:"type,required"`
CacheControl param.Field[BetaCacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[interface{}] `json:"citations"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
}
diff --git a/betamessage_test.go b/betamessage_test.go
index f0b4f9e..04e3a87 100644
--- a/betamessage_test.go
+++ b/betamessage_test.go
@@ -28,7 +28,7 @@ func TestBetaMessageNewWithOptionalParams(t *testing.T) {
_, err := client.Beta.Messages.New(context.TODO(), anthropic.BetaMessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.BetaMessageParam{{
- Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.BetaMessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -36,7 +36,7 @@ func TestBetaMessageNewWithOptionalParams(t *testing.T) {
UserID: anthropic.F("13803d75-b4b5-4c3e-b2a2-6f21399b021b"),
}),
StopSequences: anthropic.F([]string{"string"}),
- System: anthropic.F([]anthropic.BetaTextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)})}}),
+ System: anthropic.F([]anthropic.BetaTextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation)}})}}),
Temperature: anthropic.F(1.000000),
ToolChoice: anthropic.F[anthropic.BetaToolChoiceUnionParam](anthropic.BetaToolChoiceAutoParam{
Type: anthropic.F(anthropic.BetaToolChoiceAutoTypeAuto),
@@ -90,7 +90,7 @@ func TestBetaMessageCountTokensWithOptionalParams(t *testing.T) {
)
_, err := client.Beta.Messages.CountTokens(context.TODO(), anthropic.BetaMessageCountTokensParams{
Messages: anthropic.F([]anthropic.BetaMessageParam{{
- Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.BetaMessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -100,6 +100,14 @@ func TestBetaMessageCountTokensWithOptionalParams(t *testing.T) {
CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{
Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral),
}),
+ Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{
+ CitedText: anthropic.F("cited_text"),
+ DocumentIndex: anthropic.F(int64(0)),
+ DocumentTitle: anthropic.F("x"),
+ EndCharIndex: anthropic.F(int64(0)),
+ StartCharIndex: anthropic.F(int64(0)),
+ Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation),
+ }}),
}})),
ToolChoice: anthropic.F[anthropic.BetaToolChoiceUnionParam](anthropic.BetaToolChoiceAutoParam{
Type: anthropic.F(anthropic.BetaToolChoiceAutoTypeAuto),
diff --git a/betamessagebatch.go b/betamessagebatch.go
index 440a668..2cf81c3 100644
--- a/betamessagebatch.go
+++ b/betamessagebatch.go
@@ -102,9 +102,10 @@ func (r *BetaMessageBatchService) ListAutoPaging(ctx context.Context, params Bet
return pagination.NewPageAutoPager(r.List(ctx, params, opts...))
}
-// This endpoint is idempotent and can be used to poll for Message Batch
-// completion. To access the results of a Message Batch, make a request to the
-// `results_url` field in the response.
+// Delete a Message Batch.
+//
+// Message Batches can only be deleted once they've finished processing. If you'd
+// like to delete an in-progress batch, you must first cancel it.
func (r *BetaMessageBatchService) Delete(ctx context.Context, messageBatchID string, body BetaMessageBatchDeleteParams, opts ...option.RequestOption) (res *BetaDeletedMessageBatch, err error) {
for _, v := range body.Betas.Value {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%s", v)))
diff --git a/betamessagebatch_test.go b/betamessagebatch_test.go
index 4ad14f3..0971fed 100644
--- a/betamessagebatch_test.go
+++ b/betamessagebatch_test.go
@@ -31,7 +31,7 @@ func TestBetaMessageBatchNewWithOptionalParams(t *testing.T) {
Params: anthropic.F(anthropic.BetaMessageBatchNewParamsRequestsParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.BetaMessageParam{{
- Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.BetaContentBlockParamUnion{anthropic.BetaTextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.BetaMessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -40,7 +40,7 @@ func TestBetaMessageBatchNewWithOptionalParams(t *testing.T) {
}),
StopSequences: anthropic.F([]string{"string"}),
Stream: anthropic.F(true),
- System: anthropic.F([]anthropic.BetaTextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)})}}),
+ System: anthropic.F([]anthropic.BetaTextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.BetaTextBlockParamTypeText), CacheControl: anthropic.F(anthropic.BetaCacheControlEphemeralParam{Type: anthropic.F(anthropic.BetaCacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.BetaTextCitationParamUnion{anthropic.BetaCitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.BetaCitationCharLocationParamTypeCharLocation)}})}}),
Temperature: anthropic.F(1.000000),
ToolChoice: anthropic.F[anthropic.BetaToolChoiceUnionParam](anthropic.BetaToolChoiceAutoParam{
Type: anthropic.F(anthropic.BetaToolChoiceAutoTypeAuto),
diff --git a/client_test.go b/client_test.go
index 801c64f..74d11a1 100644
--- a/client_test.go
+++ b/client_test.go
@@ -41,7 +41,7 @@ func TestUserAgentHeader(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -71,7 +71,7 @@ func TestRetryAfter(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -112,7 +112,7 @@ func TestDeleteRetryCountHeader(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -148,7 +148,7 @@ func TestOverwriteRetryCountHeader(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -183,7 +183,7 @@ func TestRetryAfterMs(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -212,7 +212,7 @@ func TestContextCancel(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -238,7 +238,7 @@ func TestContextCancelDelay(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
@@ -270,7 +270,7 @@ func TestContextDeadline(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})
diff --git a/message.go b/message.go
index 7b65f88..1fcf8dd 100644
--- a/message.go
+++ b/message.go
@@ -90,6 +90,8 @@ func (r Base64PDFSourceParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
+func (r Base64PDFSourceParam) implementsDocumentBlockParamSourceUnion() {}
+
type Base64PDFSourceMediaType string
const (
@@ -140,9 +142,389 @@ func (r CacheControlEphemeralType) IsKnown() bool {
return false
}
+type CitationCharLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndCharIndex int64 `json:"end_char_index,required"`
+ StartCharIndex int64 `json:"start_char_index,required"`
+ Type CitationCharLocationType `json:"type,required"`
+ JSON citationCharLocationJSON `json:"-"`
+}
+
+// citationCharLocationJSON contains the JSON metadata for the struct
+// [CitationCharLocation]
+type citationCharLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndCharIndex apijson.Field
+ StartCharIndex apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *CitationCharLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r citationCharLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r CitationCharLocation) implementsCitationsDeltaCitation() {}
+
+func (r CitationCharLocation) implementsTextCitation() {}
+
+type CitationCharLocationType string
+
+const (
+ CitationCharLocationTypeCharLocation CitationCharLocationType = "char_location"
+)
+
+func (r CitationCharLocationType) IsKnown() bool {
+ switch r {
+ case CitationCharLocationTypeCharLocation:
+ return true
+ }
+ return false
+}
+
+type CitationCharLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndCharIndex param.Field[int64] `json:"end_char_index,required"`
+ StartCharIndex param.Field[int64] `json:"start_char_index,required"`
+ Type param.Field[CitationCharLocationParamType] `json:"type,required"`
+}
+
+func (r CitationCharLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r CitationCharLocationParam) implementsTextCitationParamUnion() {}
+
+type CitationCharLocationParamType string
+
+const (
+ CitationCharLocationParamTypeCharLocation CitationCharLocationParamType = "char_location"
+)
+
+func (r CitationCharLocationParamType) IsKnown() bool {
+ switch r {
+ case CitationCharLocationParamTypeCharLocation:
+ return true
+ }
+ return false
+}
+
+type CitationContentBlockLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndBlockIndex int64 `json:"end_block_index,required"`
+ StartBlockIndex int64 `json:"start_block_index,required"`
+ Type CitationContentBlockLocationType `json:"type,required"`
+ JSON citationContentBlockLocationJSON `json:"-"`
+}
+
+// citationContentBlockLocationJSON contains the JSON metadata for the struct
+// [CitationContentBlockLocation]
+type citationContentBlockLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndBlockIndex apijson.Field
+ StartBlockIndex apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *CitationContentBlockLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r citationContentBlockLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r CitationContentBlockLocation) implementsCitationsDeltaCitation() {}
+
+func (r CitationContentBlockLocation) implementsTextCitation() {}
+
+type CitationContentBlockLocationType string
+
+const (
+ CitationContentBlockLocationTypeContentBlockLocation CitationContentBlockLocationType = "content_block_location"
+)
+
+func (r CitationContentBlockLocationType) IsKnown() bool {
+ switch r {
+ case CitationContentBlockLocationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type CitationContentBlockLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndBlockIndex param.Field[int64] `json:"end_block_index,required"`
+ StartBlockIndex param.Field[int64] `json:"start_block_index,required"`
+ Type param.Field[CitationContentBlockLocationParamType] `json:"type,required"`
+}
+
+func (r CitationContentBlockLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r CitationContentBlockLocationParam) implementsTextCitationParamUnion() {}
+
+type CitationContentBlockLocationParamType string
+
+const (
+ CitationContentBlockLocationParamTypeContentBlockLocation CitationContentBlockLocationParamType = "content_block_location"
+)
+
+func (r CitationContentBlockLocationParamType) IsKnown() bool {
+ switch r {
+ case CitationContentBlockLocationParamTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type CitationPageLocation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ EndPageNumber int64 `json:"end_page_number,required"`
+ StartPageNumber int64 `json:"start_page_number,required"`
+ Type CitationPageLocationType `json:"type,required"`
+ JSON citationPageLocationJSON `json:"-"`
+}
+
+// citationPageLocationJSON contains the JSON metadata for the struct
+// [CitationPageLocation]
+type citationPageLocationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ EndPageNumber apijson.Field
+ StartPageNumber apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *CitationPageLocation) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r citationPageLocationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r CitationPageLocation) implementsCitationsDeltaCitation() {}
+
+func (r CitationPageLocation) implementsTextCitation() {}
+
+type CitationPageLocationType string
+
+const (
+ CitationPageLocationTypePageLocation CitationPageLocationType = "page_location"
+)
+
+func (r CitationPageLocationType) IsKnown() bool {
+ switch r {
+ case CitationPageLocationTypePageLocation:
+ return true
+ }
+ return false
+}
+
+type CitationPageLocationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ EndPageNumber param.Field[int64] `json:"end_page_number,required"`
+ StartPageNumber param.Field[int64] `json:"start_page_number,required"`
+ Type param.Field[CitationPageLocationParamType] `json:"type,required"`
+}
+
+func (r CitationPageLocationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r CitationPageLocationParam) implementsTextCitationParamUnion() {}
+
+type CitationPageLocationParamType string
+
+const (
+ CitationPageLocationParamTypePageLocation CitationPageLocationParamType = "page_location"
+)
+
+func (r CitationPageLocationParamType) IsKnown() bool {
+ switch r {
+ case CitationPageLocationParamTypePageLocation:
+ return true
+ }
+ return false
+}
+
+type CitationsConfigParam struct {
+ Enabled param.Field[bool] `json:"enabled"`
+}
+
+func (r CitationsConfigParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+type CitationsDelta struct {
+ Citation CitationsDeltaCitation `json:"citation,required"`
+ Type CitationsDeltaType `json:"type,required"`
+ JSON citationsDeltaJSON `json:"-"`
+}
+
+// citationsDeltaJSON contains the JSON metadata for the struct [CitationsDelta]
+type citationsDeltaJSON struct {
+ Citation apijson.Field
+ Type apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r *CitationsDelta) UnmarshalJSON(data []byte) (err error) {
+ return apijson.UnmarshalRoot(data, r)
+}
+
+func (r citationsDeltaJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r CitationsDelta) implementsContentBlockDeltaEventDelta() {}
+
+type CitationsDeltaCitation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ Type CitationsDeltaCitationType `json:"type,required"`
+ EndBlockIndex int64 `json:"end_block_index"`
+ EndCharIndex int64 `json:"end_char_index"`
+ EndPageNumber int64 `json:"end_page_number"`
+ StartBlockIndex int64 `json:"start_block_index"`
+ StartCharIndex int64 `json:"start_char_index"`
+ StartPageNumber int64 `json:"start_page_number"`
+ JSON citationsDeltaCitationJSON `json:"-"`
+ union CitationsDeltaCitationUnion
+}
+
+// citationsDeltaCitationJSON contains the JSON metadata for the struct
+// [CitationsDeltaCitation]
+type citationsDeltaCitationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ Type apijson.Field
+ EndBlockIndex apijson.Field
+ EndCharIndex apijson.Field
+ EndPageNumber apijson.Field
+ StartBlockIndex apijson.Field
+ StartCharIndex apijson.Field
+ StartPageNumber apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r citationsDeltaCitationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *CitationsDeltaCitation) UnmarshalJSON(data []byte) (err error) {
+ *r = CitationsDeltaCitation{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [CitationsDeltaCitationUnion] interface which you can cast to
+// the specific types for more type safety.
+//
+// Possible runtime types of the union are [CitationCharLocation],
+// [CitationPageLocation], [CitationContentBlockLocation].
+func (r CitationsDeltaCitation) AsUnion() CitationsDeltaCitationUnion {
+ return r.union
+}
+
+// Union satisfied by [CitationCharLocation], [CitationPageLocation] or
+// [CitationContentBlockLocation].
+type CitationsDeltaCitationUnion interface {
+ implementsCitationsDeltaCitation()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*CitationsDeltaCitationUnion)(nil)).Elem(),
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationCharLocation{}),
+ DiscriminatorValue: "char_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationPageLocation{}),
+ DiscriminatorValue: "page_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationContentBlockLocation{}),
+ DiscriminatorValue: "content_block_location",
+ },
+ )
+}
+
+type CitationsDeltaCitationType string
+
+const (
+ CitationsDeltaCitationTypeCharLocation CitationsDeltaCitationType = "char_location"
+ CitationsDeltaCitationTypePageLocation CitationsDeltaCitationType = "page_location"
+ CitationsDeltaCitationTypeContentBlockLocation CitationsDeltaCitationType = "content_block_location"
+)
+
+func (r CitationsDeltaCitationType) IsKnown() bool {
+ switch r {
+ case CitationsDeltaCitationTypeCharLocation, CitationsDeltaCitationTypePageLocation, CitationsDeltaCitationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type CitationsDeltaType string
+
+const (
+ CitationsDeltaTypeCitationsDelta CitationsDeltaType = "citations_delta"
+)
+
+func (r CitationsDeltaType) IsKnown() bool {
+ switch r {
+ case CitationsDeltaTypeCitationsDelta:
+ return true
+ }
+ return false
+}
+
type ContentBlock struct {
Type ContentBlockType `json:"type,required"`
ID string `json:"id"`
+ // This field can have the runtime type of [[]TextCitation].
+ Citations interface{} `json:"citations"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
@@ -155,6 +537,7 @@ type ContentBlock struct {
type contentBlockJSON struct {
Type apijson.Field
ID apijson.Field
+ Citations apijson.Field
Input apijson.Field
Name apijson.Field
Text apijson.Field
@@ -224,12 +607,15 @@ type ContentBlockParam struct {
Type param.Field[ContentBlockParamType] `json:"type,required"`
ID param.Field[string] `json:"id"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[interface{}] `json:"citations"`
Content param.Field[interface{}] `json:"content"`
+ Context param.Field[string] `json:"context"`
Input param.Field[interface{}] `json:"input"`
IsError param.Field[bool] `json:"is_error"`
Name param.Field[string] `json:"name"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
+ Title param.Field[string] `json:"title"`
ToolUseID param.Field[string] `json:"tool_use_id"`
}
@@ -263,10 +649,49 @@ func (r ContentBlockParamType) IsKnown() bool {
return false
}
+type ContentBlockSourceParam struct {
+ Content param.Field[ContentBlockSourceContentUnionParam] `json:"content,required"`
+ Type param.Field[ContentBlockSourceType] `json:"type,required"`
+}
+
+func (r ContentBlockSourceParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r ContentBlockSourceParam) implementsDocumentBlockParamSourceUnion() {}
+
+// Satisfied by [shared.UnionString],
+// [ContentBlockSourceContentContentBlockSourceContentParam].
+type ContentBlockSourceContentUnionParam interface {
+ ImplementsContentBlockSourceContentUnionParam()
+}
+
+type ContentBlockSourceContentContentBlockSourceContentParam []ContentBlockSourceContentUnionParam
+
+func (r ContentBlockSourceContentContentBlockSourceContentParam) ImplementsContentBlockSourceContentUnionParam() {
+}
+
+type ContentBlockSourceType string
+
+const (
+ ContentBlockSourceTypeContent ContentBlockSourceType = "content"
+)
+
+func (r ContentBlockSourceType) IsKnown() bool {
+ switch r {
+ case ContentBlockSourceTypeContent:
+ return true
+ }
+ return false
+}
+
type DocumentBlockParam struct {
- Source param.Field[Base64PDFSourceParam] `json:"source,required"`
- Type param.Field[DocumentBlockParamType] `json:"type,required"`
- CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
+ Source param.Field[DocumentBlockParamSourceUnion] `json:"source,required"`
+ Type param.Field[DocumentBlockParamType] `json:"type,required"`
+ CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[CitationsConfigParam] `json:"citations"`
+ Context param.Field[string] `json:"context"`
+ Title param.Field[string] `json:"title"`
}
func (r DocumentBlockParam) MarshalJSON() (data []byte, err error) {
@@ -275,6 +700,56 @@ func (r DocumentBlockParam) MarshalJSON() (data []byte, err error) {
func (r DocumentBlockParam) implementsContentBlockParamUnion() {}
+type DocumentBlockParamSource struct {
+ Type param.Field[DocumentBlockParamSourceType] `json:"type,required"`
+ Content param.Field[interface{}] `json:"content"`
+ Data param.Field[string] `json:"data" format:"byte"`
+ MediaType param.Field[DocumentBlockParamSourceMediaType] `json:"media_type"`
+}
+
+func (r DocumentBlockParamSource) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r DocumentBlockParamSource) implementsDocumentBlockParamSourceUnion() {}
+
+// Satisfied by [Base64PDFSourceParam], [PlainTextSourceParam],
+// [ContentBlockSourceParam], [DocumentBlockParamSource].
+type DocumentBlockParamSourceUnion interface {
+ implementsDocumentBlockParamSourceUnion()
+}
+
+type DocumentBlockParamSourceType string
+
+const (
+ DocumentBlockParamSourceTypeBase64 DocumentBlockParamSourceType = "base64"
+ DocumentBlockParamSourceTypeText DocumentBlockParamSourceType = "text"
+ DocumentBlockParamSourceTypeContent DocumentBlockParamSourceType = "content"
+)
+
+func (r DocumentBlockParamSourceType) IsKnown() bool {
+ switch r {
+ case DocumentBlockParamSourceTypeBase64, DocumentBlockParamSourceTypeText, DocumentBlockParamSourceTypeContent:
+ return true
+ }
+ return false
+}
+
+type DocumentBlockParamSourceMediaType string
+
+const (
+ DocumentBlockParamSourceMediaTypeApplicationPDF DocumentBlockParamSourceMediaType = "application/pdf"
+ DocumentBlockParamSourceMediaTypeTextPlain DocumentBlockParamSourceMediaType = "text/plain"
+)
+
+func (r DocumentBlockParamSourceMediaType) IsKnown() bool {
+ switch r {
+ case DocumentBlockParamSourceMediaTypeApplicationPDF, DocumentBlockParamSourceMediaTypeTextPlain:
+ return true
+ }
+ return false
+}
+
type DocumentBlockParamType string
const (
@@ -301,6 +776,8 @@ func (r ImageBlockParam) MarshalJSON() (data []byte, err error) {
func (r ImageBlockParam) implementsContentBlockParamUnion() {}
+func (r ImageBlockParam) implementsContentBlockSourceContentUnionParam() {}
+
func (r ImageBlockParam) implementsToolResultBlockParamContentUnion() {}
type ImageBlockParamSource struct {
@@ -666,6 +1143,46 @@ const (
ModelClaude_2_0 Model = "claude-2.0"
)
+type PlainTextSourceParam struct {
+ Data param.Field[string] `json:"data,required"`
+ MediaType param.Field[PlainTextSourceMediaType] `json:"media_type,required"`
+ Type param.Field[PlainTextSourceType] `json:"type,required"`
+}
+
+func (r PlainTextSourceParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r PlainTextSourceParam) implementsDocumentBlockParamSourceUnion() {}
+
+type PlainTextSourceMediaType string
+
+const (
+ PlainTextSourceMediaTypeTextPlain PlainTextSourceMediaType = "text/plain"
+)
+
+func (r PlainTextSourceMediaType) IsKnown() bool {
+ switch r {
+ case PlainTextSourceMediaTypeTextPlain:
+ return true
+ }
+ return false
+}
+
+type PlainTextSourceType string
+
+const (
+ PlainTextSourceTypeText PlainTextSourceType = "text"
+)
+
+func (r PlainTextSourceType) IsKnown() bool {
+ switch r {
+ case PlainTextSourceTypeText:
+ return true
+ }
+ return false
+}
+
type ContentBlockDeltaEvent struct {
Delta ContentBlockDeltaEventDelta `json:"delta,required"`
Index int64 `json:"index,required"`
@@ -694,7 +1211,9 @@ func (r contentBlockDeltaEventJSON) RawJSON() string {
func (r ContentBlockDeltaEvent) implementsMessageStreamEvent() {}
type ContentBlockDeltaEventDelta struct {
- Type ContentBlockDeltaEventDeltaType `json:"type,required"`
+ Type ContentBlockDeltaEventDeltaType `json:"type,required"`
+ // This field can have the runtime type of [CitationsDeltaCitation].
+ Citation interface{} `json:"citation"`
PartialJSON string `json:"partial_json"`
Text string `json:"text"`
JSON contentBlockDeltaEventDeltaJSON `json:"-"`
@@ -705,6 +1224,7 @@ type ContentBlockDeltaEventDelta struct {
// [ContentBlockDeltaEventDelta]
type contentBlockDeltaEventDeltaJSON struct {
Type apijson.Field
+ Citation apijson.Field
PartialJSON apijson.Field
Text apijson.Field
raw string
@@ -727,12 +1247,13 @@ func (r *ContentBlockDeltaEventDelta) UnmarshalJSON(data []byte) (err error) {
// AsUnion returns a [ContentBlockDeltaEventDeltaUnion] interface which you can
// cast to the specific types for more type safety.
//
-// Possible runtime types of the union are [TextDelta], [InputJSONDelta].
+// Possible runtime types of the union are [TextDelta], [InputJSONDelta],
+// [CitationsDelta].
func (r ContentBlockDeltaEventDelta) AsUnion() ContentBlockDeltaEventDeltaUnion {
return r.union
}
-// Union satisfied by [TextDelta] or [InputJSONDelta].
+// Union satisfied by [TextDelta], [InputJSONDelta] or [CitationsDelta].
type ContentBlockDeltaEventDeltaUnion interface {
implementsContentBlockDeltaEventDelta()
}
@@ -740,14 +1261,21 @@ type ContentBlockDeltaEventDeltaUnion interface {
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*ContentBlockDeltaEventDeltaUnion)(nil)).Elem(),
- "",
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(TextDelta{}),
+ DiscriminatorValue: "text_delta",
+ },
apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(TextDelta{}),
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(InputJSONDelta{}),
+ DiscriminatorValue: "input_json_delta",
},
apijson.UnionVariant{
- TypeFilter: gjson.JSON,
- Type: reflect.TypeOf(InputJSONDelta{}),
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationsDelta{}),
+ DiscriminatorValue: "citations_delta",
},
)
}
@@ -757,11 +1285,12 @@ type ContentBlockDeltaEventDeltaType string
const (
ContentBlockDeltaEventDeltaTypeTextDelta ContentBlockDeltaEventDeltaType = "text_delta"
ContentBlockDeltaEventDeltaTypeInputJSONDelta ContentBlockDeltaEventDeltaType = "input_json_delta"
+ ContentBlockDeltaEventDeltaTypeCitationsDelta ContentBlockDeltaEventDeltaType = "citations_delta"
)
func (r ContentBlockDeltaEventDeltaType) IsKnown() bool {
switch r {
- case ContentBlockDeltaEventDeltaTypeTextDelta, ContentBlockDeltaEventDeltaTypeInputJSONDelta:
+ case ContentBlockDeltaEventDeltaTypeTextDelta, ContentBlockDeltaEventDeltaTypeInputJSONDelta, ContentBlockDeltaEventDeltaTypeCitationsDelta:
return true
}
return false
@@ -811,6 +1340,8 @@ func (r ContentBlockStartEvent) implementsMessageStreamEvent() {}
type ContentBlockStartEventContentBlock struct {
Type ContentBlockStartEventContentBlockType `json:"type,required"`
ID string `json:"id"`
+ // This field can have the runtime type of [[]TextCitation].
+ Citations interface{} `json:"citations"`
// This field can have the runtime type of [interface{}].
Input interface{} `json:"input"`
Name string `json:"name"`
@@ -824,6 +1355,7 @@ type ContentBlockStartEventContentBlock struct {
type contentBlockStartEventContentBlockJSON struct {
Type apijson.Field
ID apijson.Field
+ Citations apijson.Field
Input apijson.Field
Name apijson.Field
Text apijson.Field
@@ -1236,13 +1768,20 @@ func (r MessageStreamEventType) IsKnown() bool {
}
type TextBlock struct {
- Text string `json:"text,required"`
- Type TextBlockType `json:"type,required"`
- JSON textBlockJSON `json:"-"`
+ // Citations supporting the text block.
+ //
+ // The type of citation returned will depend on the type of document being cited.
+ // Citing a PDF results in `page_location`, plain text results in `char_location`,
+ // and content document results in `content_block_location`.
+ Citations []TextCitation `json:"citations,required,nullable"`
+ Text string `json:"text,required"`
+ Type TextBlockType `json:"type,required"`
+ JSON textBlockJSON `json:"-"`
}
// textBlockJSON contains the JSON metadata for the struct [TextBlock]
type textBlockJSON struct {
+ Citations apijson.Field
Text apijson.Field
Type apijson.Field
raw string
@@ -1279,6 +1818,7 @@ type TextBlockParam struct {
Text param.Field[string] `json:"text,required"`
Type param.Field[TextBlockParamType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[[]TextCitationParamUnion] `json:"citations"`
}
func (r TextBlockParam) MarshalJSON() (data []byte, err error) {
@@ -1287,6 +1827,8 @@ func (r TextBlockParam) MarshalJSON() (data []byte, err error) {
func (r TextBlockParam) implementsContentBlockParamUnion() {}
+func (r TextBlockParam) implementsContentBlockSourceContentUnionParam() {}
+
func (r TextBlockParam) implementsToolResultBlockParamContentUnion() {}
type TextBlockParamType string
@@ -1303,6 +1845,144 @@ func (r TextBlockParamType) IsKnown() bool {
return false
}
+type TextCitation struct {
+ CitedText string `json:"cited_text,required"`
+ DocumentIndex int64 `json:"document_index,required"`
+ DocumentTitle string `json:"document_title,required,nullable"`
+ Type TextCitationType `json:"type,required"`
+ EndBlockIndex int64 `json:"end_block_index"`
+ EndCharIndex int64 `json:"end_char_index"`
+ EndPageNumber int64 `json:"end_page_number"`
+ StartBlockIndex int64 `json:"start_block_index"`
+ StartCharIndex int64 `json:"start_char_index"`
+ StartPageNumber int64 `json:"start_page_number"`
+ JSON textCitationJSON `json:"-"`
+ union TextCitationUnion
+}
+
+// textCitationJSON contains the JSON metadata for the struct [TextCitation]
+type textCitationJSON struct {
+ CitedText apijson.Field
+ DocumentIndex apijson.Field
+ DocumentTitle apijson.Field
+ Type apijson.Field
+ EndBlockIndex apijson.Field
+ EndCharIndex apijson.Field
+ EndPageNumber apijson.Field
+ StartBlockIndex apijson.Field
+ StartCharIndex apijson.Field
+ StartPageNumber apijson.Field
+ raw string
+ ExtraFields map[string]apijson.Field
+}
+
+func (r textCitationJSON) RawJSON() string {
+ return r.raw
+}
+
+func (r *TextCitation) UnmarshalJSON(data []byte) (err error) {
+ *r = TextCitation{}
+ err = apijson.UnmarshalRoot(data, &r.union)
+ if err != nil {
+ return err
+ }
+ return apijson.Port(r.union, &r)
+}
+
+// AsUnion returns a [TextCitationUnion] interface which you can cast to the
+// specific types for more type safety.
+//
+// Possible runtime types of the union are [CitationCharLocation],
+// [CitationPageLocation], [CitationContentBlockLocation].
+func (r TextCitation) AsUnion() TextCitationUnion {
+ return r.union
+}
+
+// Union satisfied by [CitationCharLocation], [CitationPageLocation] or
+// [CitationContentBlockLocation].
+type TextCitationUnion interface {
+ implementsTextCitation()
+}
+
+func init() {
+ apijson.RegisterUnion(
+ reflect.TypeOf((*TextCitationUnion)(nil)).Elem(),
+ "type",
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationCharLocation{}),
+ DiscriminatorValue: "char_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationPageLocation{}),
+ DiscriminatorValue: "page_location",
+ },
+ apijson.UnionVariant{
+ TypeFilter: gjson.JSON,
+ Type: reflect.TypeOf(CitationContentBlockLocation{}),
+ DiscriminatorValue: "content_block_location",
+ },
+ )
+}
+
+type TextCitationType string
+
+const (
+ TextCitationTypeCharLocation TextCitationType = "char_location"
+ TextCitationTypePageLocation TextCitationType = "page_location"
+ TextCitationTypeContentBlockLocation TextCitationType = "content_block_location"
+)
+
+func (r TextCitationType) IsKnown() bool {
+ switch r {
+ case TextCitationTypeCharLocation, TextCitationTypePageLocation, TextCitationTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
+type TextCitationParam struct {
+ CitedText param.Field[string] `json:"cited_text,required"`
+ DocumentIndex param.Field[int64] `json:"document_index,required"`
+ DocumentTitle param.Field[string] `json:"document_title,required"`
+ Type param.Field[TextCitationParamType] `json:"type,required"`
+ EndBlockIndex param.Field[int64] `json:"end_block_index"`
+ EndCharIndex param.Field[int64] `json:"end_char_index"`
+ EndPageNumber param.Field[int64] `json:"end_page_number"`
+ StartBlockIndex param.Field[int64] `json:"start_block_index"`
+ StartCharIndex param.Field[int64] `json:"start_char_index"`
+ StartPageNumber param.Field[int64] `json:"start_page_number"`
+}
+
+func (r TextCitationParam) MarshalJSON() (data []byte, err error) {
+ return apijson.MarshalRoot(r)
+}
+
+func (r TextCitationParam) implementsTextCitationParamUnion() {}
+
+// Satisfied by [CitationCharLocationParam], [CitationPageLocationParam],
+// [CitationContentBlockLocationParam], [TextCitationParam].
+type TextCitationParamUnion interface {
+ implementsTextCitationParamUnion()
+}
+
+type TextCitationParamType string
+
+const (
+ TextCitationParamTypeCharLocation TextCitationParamType = "char_location"
+ TextCitationParamTypePageLocation TextCitationParamType = "page_location"
+ TextCitationParamTypeContentBlockLocation TextCitationParamType = "content_block_location"
+)
+
+func (r TextCitationParamType) IsKnown() bool {
+ switch r {
+ case TextCitationParamTypeCharLocation, TextCitationParamTypePageLocation, TextCitationParamTypeContentBlockLocation:
+ return true
+ }
+ return false
+}
+
type TextDelta struct {
Text string `json:"text,required"`
Type TextDeltaType `json:"type,required"`
@@ -1560,6 +2240,7 @@ func (r ToolResultBlockParamType) IsKnown() bool {
type ToolResultBlockParamContent struct {
Type param.Field[ToolResultBlockParamContentType] `json:"type,required"`
CacheControl param.Field[CacheControlEphemeralParam] `json:"cache_control"`
+ Citations param.Field[interface{}] `json:"citations"`
Source param.Field[interface{}] `json:"source"`
Text param.Field[string] `json:"text"`
}
diff --git a/message_test.go b/message_test.go
index 21656a1..da1a10c 100644
--- a/message_test.go
+++ b/message_test.go
@@ -28,7 +28,7 @@ func TestMessageNewWithOptionalParams(t *testing.T) {
_, err := client.Messages.New(context.TODO(), anthropic.MessageNewParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.MessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -36,7 +36,7 @@ func TestMessageNewWithOptionalParams(t *testing.T) {
UserID: anthropic.F("13803d75-b4b5-4c3e-b2a2-6f21399b021b"),
}),
StopSequences: anthropic.F([]string{"string"}),
- System: anthropic.F([]anthropic.TextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ System: anthropic.F([]anthropic.TextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
Temperature: anthropic.F(1.000000),
ToolChoice: anthropic.F[anthropic.ToolChoiceUnionParam](anthropic.ToolChoiceAutoParam{
Type: anthropic.F(anthropic.ToolChoiceAutoTypeAuto),
@@ -88,7 +88,7 @@ func TestMessageCountTokensWithOptionalParams(t *testing.T) {
)
_, err := client.Messages.CountTokens(context.TODO(), anthropic.MessageCountTokensParams{
Messages: anthropic.F([]anthropic.MessageParam{{
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.MessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -98,6 +98,14 @@ func TestMessageCountTokensWithOptionalParams(t *testing.T) {
CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{
Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral),
}),
+ Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{
+ CitedText: anthropic.F("cited_text"),
+ DocumentIndex: anthropic.F(int64(0)),
+ DocumentTitle: anthropic.F("x"),
+ EndCharIndex: anthropic.F(int64(0)),
+ StartCharIndex: anthropic.F(int64(0)),
+ Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation),
+ }}),
}})),
ToolChoice: anthropic.F[anthropic.ToolChoiceUnionParam](anthropic.ToolChoiceAutoParam{
Type: anthropic.F(anthropic.ToolChoiceAutoTypeAuto),
diff --git a/messagebatch.go b/messagebatch.go
index 071f3a4..7c0fd05 100644
--- a/messagebatch.go
+++ b/messagebatch.go
@@ -92,9 +92,10 @@ func (r *MessageBatchService) ListAutoPaging(ctx context.Context, query MessageB
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
-// This endpoint is idempotent and can be used to poll for Message Batch
-// completion. To access the results of a Message Batch, make a request to the
-// `results_url` field in the response.
+// Delete a Message Batch.
+//
+// Message Batches can only be deleted once they've finished processing. If you'd
+// like to delete an in-progress batch, you must first cancel it.
func (r *MessageBatchService) Delete(ctx context.Context, messageBatchID string, opts ...option.RequestOption) (res *DeletedMessageBatch, err error) {
opts = append(r.Options[:], opts...)
if messageBatchID == "" {
diff --git a/messagebatch_test.go b/messagebatch_test.go
index 40d21bf..213d657 100644
--- a/messagebatch_test.go
+++ b/messagebatch_test.go
@@ -31,7 +31,7 @@ func TestMessageBatchNew(t *testing.T) {
Params: anthropic.F(anthropic.MessageBatchNewParamsRequestsParams{
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
Role: anthropic.F(anthropic.MessageParamRoleUser),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
@@ -40,7 +40,7 @@ func TestMessageBatchNew(t *testing.T) {
}),
StopSequences: anthropic.F([]string{"string"}),
Stream: anthropic.F(true),
- System: anthropic.F([]anthropic.TextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ System: anthropic.F([]anthropic.TextBlockParam{{Text: anthropic.F("x"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
Temperature: anthropic.F(1.000000),
ToolChoice: anthropic.F[anthropic.ToolChoiceUnionParam](anthropic.ToolChoiceAutoParam{
Type: anthropic.F(anthropic.ToolChoiceAutoTypeAuto),
diff --git a/shared/union.go b/shared/union.go
index 57f90f0..fc40f8a 100644
--- a/shared/union.go
+++ b/shared/union.go
@@ -5,6 +5,8 @@ package shared
type UnionString string
func (UnionString) ImplementsModel() {}
+func (UnionString) ImplementsContentBlockSourceContentUnionParam() {}
func (UnionString) ImplementsMessageCountTokensParamsSystemUnion() {}
func (UnionString) ImplementsAnthropicBeta() {}
+func (UnionString) ImplementsBetaContentBlockSourceContentUnionParam() {}
func (UnionString) ImplementsBetaMessageCountTokensParamsSystemUnion() {}
diff --git a/usage_test.go b/usage_test.go
index ada7c9a..e3d25ee 100644
--- a/usage_test.go
+++ b/usage_test.go
@@ -28,7 +28,7 @@ func TestUsage(t *testing.T) {
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{{
Role: anthropic.F(anthropic.MessageParamRoleUser),
- Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)})}}),
+ Content: anthropic.F([]anthropic.ContentBlockParamUnion{anthropic.TextBlockParam{Text: anthropic.F("What is a quaternion?"), Type: anthropic.F(anthropic.TextBlockParamTypeText), CacheControl: anthropic.F(anthropic.CacheControlEphemeralParam{Type: anthropic.F(anthropic.CacheControlEphemeralTypeEphemeral)}), Citations: anthropic.F([]anthropic.TextCitationParamUnion{anthropic.CitationCharLocationParam{CitedText: anthropic.F("cited_text"), DocumentIndex: anthropic.F(int64(0)), DocumentTitle: anthropic.F("x"), EndCharIndex: anthropic.F(int64(0)), StartCharIndex: anthropic.F(int64(0)), Type: anthropic.F(anthropic.CitationCharLocationParamTypeCharLocation)}})}}),
}}),
Model: anthropic.F(anthropic.ModelClaude3_5HaikuLatest),
})