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 recordInput messages.static 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 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 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 interfacestatic final recordTool description.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 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.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.
-