Class AnthropicSkillsResponseHelper

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

public final class AnthropicSkillsResponseHelper extends Object
Helper utilities for working with Anthropic Claude Skills responses and files. Provides methods to extract file IDs, container IDs, and download files generated by Skills.

Unlike the RestClient module's helper which requires recursive Map/List crawling to find file IDs in untyped response structures, this SDK-based helper uses the SDK's typed ContentBlock variants with direct accessor methods.

Since:
2.0.0
Author:
Soby Chacko
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<Path>
    downloadAllFiles(org.springframework.ai.chat.model.ChatResponse response, com.anthropic.client.AnthropicClient client, Path targetDir)
    Download all files from a Skills response to a target directory.
    static @Nullable String
    extractContainerId(@Nullable org.springframework.ai.chat.model.ChatResponse response)
    Extract container ID from a chat response for multi-turn conversation reuse.
    static List<String>
    extractFileIds(@Nullable org.springframework.ai.chat.model.ChatResponse response)
    Extract all file IDs from a chat response.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • extractFileIds

      public static List<String> extractFileIds(@Nullable org.springframework.ai.chat.model.ChatResponse response)
      Extract all file IDs from a chat response. Searches through all content blocks in the underlying SDK Message stored in 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 @Nullable String extractContainerId(@Nullable org.springframework.ai.chat.model.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(org.springframework.ai.chat.model.ChatResponse response, com.anthropic.client.AnthropicClient client, Path targetDir) throws IOException
      Download all files from a Skills response to a target directory.

      Filenames returned by the API are validated before use: null/blank names, absolute paths, multi-segment paths, and ./.. segments are rejected. An invalid name aborts the batch; any files already written remain on disk.

      Parameters:
      response - the chat response containing file IDs
      client - the Anthropic client to use for downloading (beta files API)
      targetDir - directory to save files (must exist)
      Returns:
      list of paths to saved files
      Throws:
      IOException - if file download, saving, or filename validation fails