Class SkillsResponseHelper

java.lang.Object
org.springframework.ai.anthropic.SkillsResponseHelper

public final class SkillsResponseHelper extends Object
Helper utilities for working with Claude Skills responses and files. Provides methods to extract file IDs, container IDs, and download files generated by Skills.
Since:
2.0.0
Author:
Soby Chacko
  • Method Details

    • extractFileIds

      public static List<String> extractFileIds(ChatResponse response)
      Extract all file IDs from a chat response. Searches through all content blocks in the response, including those in the underlying AnthropicApi response metadata.
      Parameters:
      response - The chat response to search
      Returns:
      List of file IDs found in the response (empty list if none found)
    • extractContainerId

      public static String extractContainerId(ChatResponse response)
      Extract container ID from a chat response for multi-turn conversation reuse.
      Parameters:
      response - The chat response
      Returns:
      Container ID if present, null otherwise
    • downloadAllFiles

      public static List<Path> downloadAllFiles(ChatResponse response, AnthropicApi api, Path targetDir) throws IOException
      Download all files from a Skills response to a target directory.

      Note: Existing files with the same name will be overwritten. Check for file existence before calling if overwrite protection is needed.

      Parameters:
      response - The chat response containing file IDs
      api - The Anthropic API client to use for downloading
      targetDir - Directory to save files (must exist)
      Returns:
      List of paths to saved files
      Throws:
      IOException - if file download or saving fails