Class AnthropicApi
java.lang.Object
org.springframework.ai.anthropic.api.AnthropicApi
The Anthropic API client.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Mariusz Bernacki, Thomas Vitale, Jihoon Kim, Alexandros Pappas, Jonghoon Park, Claudio Silva Junior, Filip Hrisafov, Soby Chacko, Austin Dase
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordInput messages.static enumPre-built Anthropic Skills for document generation.static final classstatic final recordChat completion request object.static final classstatic final recordChat completion response object.static enumCheck the Models overview and model comparison for additional details and options.static final recordCitation response structure from Anthropic API.static final recordCitations configuration for document ContentBlocks.static final recordThe content block of the message.static final recordContent block delta event.static final recordContent block start event.static final recordContent block stop event.static final recordError event.static enumThe event type of the streamed chunk.static final recordMetadata for a file generated by Claude Skills or uploaded via Files API.static final recordPaginated list of files response from the Files API.static final recordMessage delta event.static final recordMessage start event.static final recordMessage stop event.static final recordPing event.static enumThe role of the author of this message.static final recordRepresents a Claude Skill - either pre-built Anthropic skill or custom skill.static final recordContainer for Claude Skills in a chat completion request.static enumTypes of Claude Skills.static interfacestatic enumThe thinking type.static final recordTool description.static interfaceBase interface for tool choice options.static final recordAny tool choice - the model will use any available tools.static final recordAuto tool choice - the model will automatically decide whether to use tools.static final recordNone tool choice - the model will not be allowed to use tools.static final recordTool choice - the model will use the specified tool.static classSpecial event used to aggregate multiple tool use events into a single event with list of aggregated ContentBlockToolUse.static final recordUsage statistics. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAnthropicApi(String completionsPath, org.springframework.web.client.RestClient restClient, org.springframework.web.reactive.function.client.WebClient webClient, org.springframework.ai.model.ApiKey apiKey) Create a new client api. -
Method Summary
Modifier and TypeMethodDescriptionstatic AnthropicApi.Builderbuilder()org.springframework.http.ResponseEntity<AnthropicApi.ChatCompletionResponse> chatCompletionEntity(AnthropicApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.org.springframework.http.ResponseEntity<AnthropicApi.ChatCompletionResponse> chatCompletionEntity(AnthropicApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader) Creates a model response for the given chat conversation.reactor.core.publisher.Flux<AnthropicApi.ChatCompletionResponse> chatCompletionStream(AnthropicApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.reactor.core.publisher.Flux<AnthropicApi.ChatCompletionResponse> chatCompletionStream(AnthropicApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader) Creates a streaming chat response for the given chat conversation.voiddeleteFile(String fileId) Delete a file.byte[]downloadFile(String fileId) Download file content as byte array.getFileMetadata(String fileId) Get metadata for a specific file generated by Skills or uploaded via Files API.List all files with optional pagination.
-
Field Details
-
PROVIDER_NAME
-
DEFAULT_BASE_URL
- See Also:
-
DEFAULT_MESSAGE_COMPLETIONS_PATH
- See Also:
-
FILES_PATH
- See Also:
-
DEFAULT_ANTHROPIC_VERSION
- See Also:
-
DEFAULT_ANTHROPIC_BETA_VERSION
- See Also:
-
BETA_EXTENDED_CACHE_TTL
- See Also:
-
BETA_SKILLS
- See Also:
-
BETA_FILES_API
- See Also:
-
BETA_CODE_EXECUTION
- See Also:
-
CODE_EXECUTION_TOOL_TYPE
- See Also:
-
-
Constructor Details
-
AnthropicApi
public AnthropicApi(String completionsPath, org.springframework.web.client.RestClient restClient, org.springframework.web.reactive.function.client.WebClient webClient, org.springframework.ai.model.ApiKey apiKey) Create a new client api.- Parameters:
completionsPath- path to append to the base URL.restClient- RestClient instance.webClient- WebClient instance.apiKey- Anthropic api Key.
-
-
Method Details
-
builder
-
chatCompletionEntity
public org.springframework.http.ResponseEntity<AnthropicApi.ChatCompletionResponse> chatCompletionEntity(AnthropicApi.ChatCompletionRequest chatRequest) Creates a model response for the given chat conversation.- Parameters:
chatRequest- The chat completion request.- Returns:
- Entity response with
AnthropicApi.ChatCompletionResponseas a body and HTTP status code and headers.
-
chatCompletionEntity
public org.springframework.http.ResponseEntity<AnthropicApi.ChatCompletionResponse> chatCompletionEntity(AnthropicApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader) Creates a model response for the given chat conversation.- Parameters:
chatRequest- The chat completion request.additionalHttpHeader- Additional HTTP headers.- Returns:
- Entity response with
AnthropicApi.ChatCompletionResponseas a body and HTTP status code and headers.
-
chatCompletionStream
public reactor.core.publisher.Flux<AnthropicApi.ChatCompletionResponse> chatCompletionStream(AnthropicApi.ChatCompletionRequest chatRequest) Creates a streaming chat response for the given chat conversation.- Parameters:
chatRequest- The chat completion request. Must have the stream property set to true.- Returns:
- Returns a
Fluxstream from chat completion chunks.
-
chatCompletionStream
public reactor.core.publisher.Flux<AnthropicApi.ChatCompletionResponse> chatCompletionStream(AnthropicApi.ChatCompletionRequest chatRequest, org.springframework.http.HttpHeaders additionalHttpHeader) Creates a streaming chat response for the given chat conversation.- Parameters:
chatRequest- The chat completion request. Must have the stream property set to true.additionalHttpHeader- Additional HTTP headers.- Returns:
- Returns a
Fluxstream from chat completion chunks.
-
getFileMetadata
Get metadata for a specific file generated by Skills or uploaded via Files API.- Parameters:
fileId- The file ID to retrieve (format: file_*)- Returns:
- File metadata including filename, size, mime type, and expiration
-
downloadFile
Download file content as byte array. Suitable for small to medium files.- Parameters:
fileId- The file ID to download- Returns:
- File content as bytes
-
listFiles
List all files with optional pagination.- Parameters:
limit- Maximum number of results per page (default 20, max 100)page- Pagination token from previous response- Returns:
- Paginated list of files
-
deleteFile
Delete a file. Files expire automatically after 24 hours, but this allows immediate cleanup.- Parameters:
fileId- The file ID to delete
-