Record Class AnthropicApi.ContentBlock
java.lang.Object
java.lang.Record
org.springframework.ai.anthropic.api.AnthropicApi.ContentBlock
- Record Components:
type- the content type can be "text", "image", "tool_use", "tool_result" or "text_delta".source- The source of the media content. Applicable for "image" types only.text- The text of the message. Applicable for "text" types only.index- The index of the content block. Applicable only for streaming responses.id- The id of the tool use. Applicable only for tool_use response.name- The name of the tool use. Applicable only for tool_use response.input- The input of the tool use. Applicable only for tool_use response.toolUseId- The id of the tool use. Applicable only for tool_result response.content- The content of the tool result. Applicable only for tool_result response.
- Enclosing class:
- AnthropicApi
public static record AnthropicApi.ContentBlock(AnthropicApi.ContentBlock.Type type, AnthropicApi.ContentBlock.Source source, String text, Integer index, String id, String name, Map<String,Object> input, String toolUseId, Object content, String signature, String thinking, String data, AnthropicApi.ChatCompletionRequest.CacheControl cacheControl, String title, String context, Object citations, String fileId, String filename)
extends Record
The content block of the message.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final recordThe source of the media content.static enumThe ContentBlock type. -
Constructor Summary
ConstructorsConstructorDescriptionContentBlock(String text) Create content blockContentBlock(String mediaType, String data) Create content blockCreate content blockContentBlock(AnthropicApi.ContentBlock.Source source, String title, String context, boolean citationsEnabled, AnthropicApi.ChatCompletionRequest.CacheControl cacheControl) Create a document ContentBlock with citations and optional caching.ContentBlock(AnthropicApi.ContentBlock.Type type, String toolUseId, String content) Create content blockContentBlock(AnthropicApi.ContentBlock.Type type, String id, String name, Map<String, Object> input) Create content blockCreate content blockContentBlock(AnthropicApi.ContentBlock.Type type, AnthropicApi.ContentBlock.Source source, String text, Integer index) Create content blockContentBlock(AnthropicApi.ContentBlock.Type type, AnthropicApi.ContentBlock.Source source, String text, Integer index, String id, String name, Map<String, Object> input, String toolUseId, Object content, String signature, String thinking, String data, AnthropicApi.ChatCompletionRequest.CacheControl cacheControl, String title, String context, Object citations, String fileId, String filename) Creates an instance of aContentBlockrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thecacheControlrecord component.Returns the value of thecitationsrecord component.content()Returns the value of thecontentrecord component.Returns the content as a String if it is a String, null otherwise.context()Returns the value of thecontextrecord component.data()Returns the value of thedatarecord component.final booleanIndicates whether some other object is "equal to" this one.fileId()Returns the value of thefileIdrecord component.filename()Returns the value of thefilenamerecord component.from(AnthropicApi.ContentBlock contentBlock) final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.index()Returns the value of theindexrecord component.input()Returns the value of theinputrecord component.name()Returns the value of thenamerecord component.Returns the value of thesignaturerecord component.source()Returns the value of thesourcerecord component.text()Returns the value of thetextrecord component.thinking()Returns the value of thethinkingrecord component.title()Returns the value of thetitlerecord component.Returns the value of thetoolUseIdrecord component.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
ContentBlock
Create content block- Parameters:
mediaType- The media type of the content.data- The content data.
-
ContentBlock
Create content block- Parameters:
type- The type of the content.source- The source of the content.
-
ContentBlock
Create content block- Parameters:
source- The source of the content.
-
ContentBlock
Create content block- Parameters:
text- The text of the content.
-
ContentBlock
-
ContentBlock
Create content block- Parameters:
type- The type of the content.toolUseId- The id of the tool use.content- The content of the tool result.
-
ContentBlock
public ContentBlock(AnthropicApi.ContentBlock.Type type, AnthropicApi.ContentBlock.Source source, String text, Integer index) Create content block- Parameters:
type- The type of the content.source- The source of the content.text- The text of the content.index- The index of the content block.
-
ContentBlock
public ContentBlock(AnthropicApi.ContentBlock.Type type, String id, String name, Map<String, Object> input) Create content block- Parameters:
type- The type of the content.id- The id of the tool use.name- The name of the tool use.input- The input of the tool use.
-
ContentBlock
public ContentBlock(AnthropicApi.ContentBlock.Source source, String title, String context, boolean citationsEnabled, AnthropicApi.ChatCompletionRequest.CacheControl cacheControl) Create a document ContentBlock with citations and optional caching.- Parameters:
source- The document sourcetitle- Optional document titlecontext- Optional document contextcitationsEnabled- Whether citations are enabledcacheControl- Optional cache control (can be null)
-
ContentBlock
public ContentBlock(AnthropicApi.ContentBlock.Type type, AnthropicApi.ContentBlock.Source source, String text, Integer index, String id, String name, Map<String, Object> input, String toolUseId, Object content, String signature, String thinking, String data, AnthropicApi.ChatCompletionRequest.CacheControl cacheControl, String title, String context, Object citations, String fileId, String filename) Creates an instance of aContentBlockrecord class.- Parameters:
type- the value for thetyperecord componentsource- the value for thesourcerecord componenttext- the value for thetextrecord componentindex- the value for theindexrecord componentid- the value for theidrecord componentname- the value for thenamerecord componentinput- the value for theinputrecord componenttoolUseId- the value for thetoolUseIdrecord componentcontent- the value for thecontentrecord componentsignature- the value for thesignaturerecord componentthinking- the value for thethinkingrecord componentdata- the value for thedatarecord componentcacheControl- the value for thecacheControlrecord componenttitle- the value for thetitlerecord componentcontext- the value for thecontextrecord componentcitations- the value for thecitationsrecord componentfileId- the value for thefileIdrecord componentfilename- the value for thefilenamerecord component
-
-
Method Details
-
from
public static AnthropicApi.ContentBlock.ContentBlockBuilder from(AnthropicApi.ContentBlock contentBlock) -
contentAsString
Returns the content as a String if it is a String, null otherwise.Note: The
content()field was changed fromStringtoObjectto support Skills responses which may return complex nested structures. If you are using the low-level API and previously relied oncontent()returning a String, use this method instead.- Returns:
- the content as String, or null if content is not a String
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
source
Returns the value of thesourcerecord component.- Returns:
- the value of the
sourcerecord component
-
text
Returns the value of thetextrecord component.- Returns:
- the value of the
textrecord component
-
index
Returns the value of theindexrecord component.- Returns:
- the value of the
indexrecord component
-
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
input
Returns the value of theinputrecord component.- Returns:
- the value of the
inputrecord component
-
toolUseId
Returns the value of thetoolUseIdrecord component.- Returns:
- the value of the
toolUseIdrecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
signature
Returns the value of thesignaturerecord component.- Returns:
- the value of the
signaturerecord component
-
thinking
Returns the value of thethinkingrecord component.- Returns:
- the value of the
thinkingrecord component
-
data
Returns the value of thedatarecord component.- Returns:
- the value of the
datarecord component
-
cacheControl
Returns the value of thecacheControlrecord component.- Returns:
- the value of the
cacheControlrecord component
-
title
Returns the value of thetitlerecord component.- Returns:
- the value of the
titlerecord component
-
context
Returns the value of thecontextrecord component.- Returns:
- the value of the
contextrecord component
-
citations
Returns the value of thecitationsrecord component.- Returns:
- the value of the
citationsrecord component
-
fileId
Returns the value of thefileIdrecord component.- Returns:
- the value of the
fileIdrecord component
-
filename
Returns the value of thefilenamerecord component.- Returns:
- the value of the
filenamerecord component
-