Class AnthropicApi

java.lang.Object
org.springframework.ai.anthropic.api.AnthropicApi

public final class AnthropicApi extends Object
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
  • Field Details

  • 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

      public static AnthropicApi.Builder 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.ChatCompletionResponse as 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.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.
    • 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 Flux stream from chat completion chunks.
    • getFileMetadata

      public AnthropicApi.FileMetadata getFileMetadata(String fileId)
      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

      public byte[] downloadFile(String fileId)
      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

      public AnthropicApi.FilesListResponse listFiles(Integer limit, String page)
      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

      public void deleteFile(String fileId)
      Delete a file. Files expire automatically after 24 hours, but this allows immediate cleanup.
      Parameters:
      fileId - The file ID to delete