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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Input messages.static final record
Chat completion request object.static final class
static final record
Chat completion response object.static enum
Check the Models overview and model comparison for additional details and options.static final record
The content block of the message.static final record
Content block delta event.static final record
Content block start event.static final record
Content block stop event.static final record
Error event.static enum
The event type of the streamed chunk.static final record
Message delta event.static final record
Message start event.static final record
Message stop event.static final record
Ping event.static enum
The role of the author of this message.static interface
static final record
Tool description.static class
Special event used to aggregate multiple tool use events into a single event with list of aggregated ContentBlockToolUse.static final record
Usage statistics. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAnthropicApi
(String anthropicApiKey) Create a new client api with DEFAULT_BASE_URLAnthropicApi
(String baseUrl, String anthropicApiKey) Create a new client api.AnthropicApi
(String baseUrl, String anthropicApiKey, String anthropicVersion, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new client api.AnthropicApi
(String baseUrl, String anthropicApiKey, String anthropicVersion, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler, String anthropicBetaFeatures) Create a new client api. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<AnthropicApi.ChatCompletionResponse>
chatCompletionEntity
(AnthropicApi.ChatCompletionRequest chatRequest) 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.
-
Field Details
-
PROVIDER_NAME
-
DEFAULT_BASE_URL
- See Also:
-
DEFAULT_ANTHROPIC_VERSION
- See Also:
-
DEFAULT_ANTHROPIC_BETA_VERSION
- See Also:
-
BETA_MAX_TOKENS
- See Also:
-
-
Constructor Details
-
AnthropicApi
Create a new client api with DEFAULT_BASE_URL- Parameters:
anthropicApiKey
- Anthropic api Key.
-
AnthropicApi
Create a new client api.- Parameters:
baseUrl
- api base URL.anthropicApiKey
- Anthropic api Key.
-
AnthropicApi
public AnthropicApi(String baseUrl, String anthropicApiKey, String anthropicVersion, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler) Create a new client api.- Parameters:
baseUrl
- api base URL.anthropicApiKey
- Anthropic api Key.restClientBuilder
- RestClient builder.webClientBuilder
- WebClient builder.responseErrorHandler
- Response error handler.
-
AnthropicApi
public AnthropicApi(String baseUrl, String anthropicApiKey, String anthropicVersion, org.springframework.web.client.RestClient.Builder restClientBuilder, org.springframework.web.reactive.function.client.WebClient.Builder webClientBuilder, org.springframework.web.client.ResponseErrorHandler responseErrorHandler, String anthropicBetaFeatures) Create a new client api.- Parameters:
baseUrl
- api base URL.anthropicApiKey
- Anthropic api Key.anthropicVersion
- Anthropic version.restClientBuilder
- RestClient builder.webClientBuilder
- WebClient builder.responseErrorHandler
- Response error handler.anthropicBetaFeatures
- Anthropic beta features.
-
-
Method Details
-
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.ChatCompletionResponse
as 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
Flux
stream from chat completion chunks.
-