如需最新的快照版本,请使用 Spring AI 1.1.3spring-doc.cadn.net.cn

Anthropic Chat

Anthropic Claude 是一系列基础人工智能模型,可以在多种应用中使用。 对于开发者和企业来说,您可以利用 API 访问并直接在 Anthropic 的 AI 基础设施 上构建。spring-doc.cadn.net.cn

Spring AI 支持 Anthropic 消息 API,用于同步和流式文本生成。spring-doc.cadn.net.cn

Anthropic 的 Claude 模型也可通过 Amazon Bedrock Converse 获取。 Spring AI 提供了专门的 Amazon Bedrock Converse Anthropic 客户端实现。

前置条件

您需要在Anthropic门户上创建一个API密钥。spring-doc.cadn.net.cn

Anthropic API 控制台注册账号,并在获取 API 密钥页面生成 API密钥。spring-doc.cadn.net.cn

The Spring AI项目定义了一个配置属性名为spring.ai.anthropic.api-key,你应该将其设置为从anthropic.com获取的API Key的值。spring-doc.cadn.net.cn

您可以在您的application.properties文件中设置此配置属性:spring-doc.cadn.net.cn

spring.ai.anthropic.api-key=<your-anthropic-api-key>

处理敏感信息(如API密钥)时,为了增强安全性,您可以使用Spring表达式语言(SpEL)引用自定义环境变量:spring-doc.cadn.net.cn

# In application.yml
spring:
  ai:
    anthropic:
      api-key: ${ANTHROPIC_API_KEY}
# In your environment or .env file
export ANTHROPIC_API_KEY=<your-anthropic-api-key>

您也可以在应用程序代码中程序化地获取此配置:spring-doc.cadn.net.cn

// Retrieve API key from a secure source or environment variable
String apiKey = System.getenv("ANTHROPIC_API_KEY");

添加仓库和BOM

Spring AI 构件发布在 Maven 中央仓库和 Spring Snapshot 仓库中。 请参阅 构件仓库 部分,将这些仓库添加到您的构建系统中。spring-doc.cadn.net.cn

为了帮助进行依赖管理,Spring AI 提供了一个 BOM(物料清单),以确保整个项目中使用的是相同的 Spring AI 版本。请参阅 依赖管理 部分,将 Spring AI BOM 添加到您的构建系统中。spring-doc.cadn.net.cn

Auto-configuration

Spring AI自动配置和starter模块的artifact名称有了重大变化。 请参阅升级说明获取更多信息。spring-doc.cadn.net.cn

Spring AI 为 Anthropic 聊天客户端提供了 Spring Boot 自动配置。 要启用它,请将以下依赖项添加到项目中的 Maven pom.xml 或 Gradle build.gradle 文件中:spring-doc.cadn.net.cn

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-starter-model-anthropic</artifactId>
</dependency>
dependencies {
    implementation 'org.springframework.ai:spring-ai-starter-model-anthropic'
}
请参阅依赖管理部分,将Spring AI BOM添加到您的构建文件中。

聊天属性

重试属性

spring.ai.retry 前缀用作属性前缀,允许您配置 Anthropic 对话模型的重试机制。spring-doc.cadn.net.cn

<property> </property> <description> </description> 默认

spring.ai.retry.max-attemptsspring-doc.cadn.net.cn

最大重试尝试次数。spring-doc.cadn.net.cn

10spring-doc.cadn.net.cn

spring.ai.retry.backoff.initial-intervalspring-doc.cadn.net.cn

指数退避策略的初始睡眠时长。spring-doc.cadn.net.cn

2 秒。spring-doc.cadn.net.cn

spring.ai.retry.backoff.multiplierspring-doc.cadn.net.cn

重试间隔倍数。spring-doc.cadn.net.cn

5spring-doc.cadn.net.cn

spring.ai.retry.backoff.max-intervalspring-doc.cadn.net.cn

最大退避持续时间。spring-doc.cadn.net.cn

3 min.spring-doc.cadn.net.cn

spring.ai.retry.on-client-errorsspring-doc.cadn.net.cn

如果为假,则抛出一个NonTransientAiException,并且不尝试重试4xx客户端错误代码spring-doc.cadn.net.cn

falsespring-doc.cadn.net.cn

spring.ai.retry.exclude-on-http-codesspring-doc.cadn.net.cn

不应当触发重试的HTTP状态码列表(例如,抛出NonTransientAiException)。spring-doc.cadn.net.cn

<p>空内容</p>spring-doc.cadn.net.cn

spring.ai.retry.on-http-codesspring-doc.cadn.net.cn

应触发重试的HTTP状态码列表(例如,抛出TransientAiException)。spring-doc.cadn.net.cn

<p>空内容</p>spring-doc.cadn.net.cn

目前,重试策略不适用于流式API。

连接属性

使用前缀spring.ai.anthropic作为属性前缀,以便连接到Anthropic。spring-doc.cadn.net.cn

<property> </property> <description> </description> 默认

spring.ai.anthropic.base-urlspring-doc.cadn.net.cn

连接的URLspring-doc.cadn.net.cn

api.anthropic.comspring-doc.cadn.net.cn

spring.ai.anthropic.completions-pathspring-doc.cadn.net.cn

在基础URL后面附加的路径。spring-doc.cadn.net.cn

/v1/chat/completionsspring-doc.cadn.net.cn

spring.ai.anthropic.versionspring-doc.cadn.net.cn

Anthropic API 版本spring-doc.cadn.net.cn

2023-06-01spring-doc.cadn.net.cn

spring.ai.anthropic.api-keyspring-doc.cadn.net.cn

API密钥spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.beta-versionspring-doc.cadn.net.cn

启用新的/实验性的功能。如果设置为max-tokens-3-5-sonnet-2024-07-15,输出的Tokens限制将从4096增加到8192个Tokens(仅限claude-3-5-sonnet)。spring-doc.cadn.net.cn

tools-2024-04-04spring-doc.cadn.net.cn

配置属性

现在通过带有前缀spring.ai.model.chat的顶级属性来配置聊天自动配置的启用和禁用。spring-doc.cadn.net.cn

要启用,请设置:spring.ai.model.chat=anthropic (默认已启用)spring-doc.cadn.net.cn

要禁用,请设置 spring.ai.model.chat=none(或任何不匹配 Anthropic 的值)spring-doc.cadn.net.cn

此更改是为了允许配置多个模型。spring-doc.cadn.net.cn

spring.ai.anthropic.chat 前缀是属性前缀,让你可以配置与 Anthropic 对话模型相关的实现。spring-doc.cadn.net.cn

<property> </property> <description> </description> 默认

spring.ai.anthropic.chat.enabled (已移除且不再有效)spring-doc.cadn.net.cn

启用Anthropic聊天模型。spring-doc.cadn.net.cn

truespring-doc.cadn.net.cn

spring.ai.model.chatspring-doc.cadn.net.cn

启用Anthropic聊天模型。spring-doc.cadn.net.cn

Anthropicspring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.modelspring-doc.cadn.net.cn

这是要使用的 Anthropic Chat 模型。支持:claude-opus-4-0claude-sonnet-4-0claude-3-7-sonnet-latestclaude-3-5-sonnet-latestclaude-3-opus-20240229claude-3-sonnet-20240229claude-3-haiku-20240307claude-3-7-sonnet-latestclaude-sonnet-4-20250514claude-opus-4-1-20250805spring-doc.cadn.net.cn

claude-opus-4-20250514spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.temperaturespring-doc.cadn.net.cn

使用以控制生成完成内容的看似创造力的采样温度。较高值会使输出更具随机性,而较低值会使结果更集中和确定。不建议在同一完成请求中同时修改温度和top_p,因为这两个设置之间的交互难以预测。spring-doc.cadn.net.cn

0.8spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.max-tokensspring-doc.cadn.net.cn

生成聊天补全时的最大token数。输入token和生成token的总长度受限于模型的上下文长度。spring-doc.cadn.net.cn

500spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.stop-sequencespring-doc.cadn.net.cn

<p>自定义文本序列,这些序列会让模型停止生成。我们的模型通常会在自然完成其回合后停止生成,这会导致响应的 stop_reason 值为spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.top-pspring-doc.cadn.net.cn

使用核采样。在核采样中,我们按照递减概率顺序计算每个后续标记的所有选项的累积分布,并在达到由 top_p 指定的特定概率时停止。你应该仅更改温度或 top_p 中的一个,但不能同时更改两者。仅对高级用例推荐使用。通常情况下,你只需要使用温度。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.top-kspring-doc.cadn.net.cn

仅从每个后续标记的前K个选项中取样。用于去除低概率响应中的“长尾”情况。详细了解技术细节请参阅此处。仅推荐在高级用例中使用。通常您只需要使用温度参数。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.toolNamesspring-doc.cadn.net.cn

使用名称标识的工具列表,以启用在单个提示请求中调用工具。这些名称中的工具必须存在于toolCallbacks注册表中。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.toolCallbacksspring-doc.cadn.net.cn

使用回调注册与ChatModel相关的工具。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.internal-tool-execution-enabledspring-doc.cadn.net.cn

如果为假,Spring AI 将不会内部处理工具调用,而是将它们代理给客户端。然后需要由客户端负责处理这些工具调用、将其分派到适当的函数,并返回结果。如果为真(默认值),Spring AI 将会内部处理这些函数调用。仅适用于支持功能调用的聊天模型。spring-doc.cadn.net.cn

truespring-doc.cadn.net.cn

(已弃用 - 被 toolNames 替换) spring.ai.anthropic.chat.options.functionsspring-doc.cadn.net.cn

函数列表,通过其名称标识,以便在单个提示请求中启用函数调用。具有这些名称的函数必须存在于 functionCallbacks 注册表中。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

(已弃用 - 被 toolCallbacks 替换) spring.ai.anthropic.chat.options.functionCallbacksspring-doc.cadn.net.cn

向 ChatModel 注册的工具函数回调。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

(已弃用 - 被否定的 internal-tool-execution-enabled 替代) spring.ai.anthropic.chat.options.proxy-tool-callsspring-doc.cadn.net.cn

如果为 true,Spring AI 将不会在内部处理函数调用,而是将其代理给客户端。然后由客户端负责处理函数调用,将其分派到相应的函数,并返回结果。如果为 false(默认值),Spring AI 将在内部处理函数调用。仅适用于支持函数调用的聊天模型spring-doc.cadn.net.cn

falsespring-doc.cadn.net.cn

spring.ai.anthropic.chat.options.http-headersspring-doc.cadn.net.cn

添加到聊天补全请求中的可选HTTP标头。spring-doc.cadn.net.cn

-spring-doc.cadn.net.cn

对于最新的模型别名及其描述列表,请参见官方Anthropic模型别名文档
所有以spring.ai.anthropic.chat.options开头的属性可以在运行时通过向Prompt调用添加请求特定的运行时选项来覆盖。

运行时选项

The AnthropicChatOptions.java 提供了模型配置,例如要使用的模型、温度、最大token计数等。spring-doc.cadn.net.cn

启动时,可以使用AnthropicChatModel(api, options)构造函数或spring.ai.anthropic.chat.options.*属性来配置默认选项。spring-doc.cadn.net.cn

在运行时,您可以覆盖默认选项并通过向Prompt调用添加新的、针对请求的选项来实现。例如,要为特定请求覆盖默认模型和温度:spring-doc.cadn.net.cn

ChatResponse response = chatModel.call(
    new Prompt(
        "Generate the names of 5 famous pirates.",
        AnthropicChatOptions.builder()
            .model("claude-3-7-sonnet-latest")
            .temperature(0.4)
        .build()
    ));
此外,除了特定于模型的AnthropicChatOptions外,您还可以使用一个通用的ChatOptions 实例,该实例通过调用ChatOptions#builder() 创建。

思考

Anthropic Claude 模型支持一种“思考”功能,允许模型在提供最终答案之前展示其推理过程。该功能使问题解决更加透明和详细,特别适用于需要逐步推理的复杂问题。spring-doc.cadn.net.cn

支持的模型spring-doc.cadn.net.cn

该思考功能由以下Claude模型支持:spring-doc.cadn.net.cn

模型能力:spring-doc.cadn.net.cn

  • Claude 3.7 Sonnet: 返回完整的思考输出。行为一致但不支持摘要式或交错式思考。spring-doc.cadn.net.cn

  • Claude 4 模型:支持摘要式思考、交替思考和增强工具集成。spring-doc.cadn.net.cn

API请求结构在所有支持的模型中是相同的,但输出行为会有所不同。spring-doc.cadn.net.cn

思考配置

要启用任何支持的Claude模型进行思考,请在请求中包含以下配置:spring-doc.cadn.net.cn

所需配置

  1. 强健的对象thinking:spring-doc.cadn.net.cn

  2. Token预算规则:spring-doc.cadn.net.cn

关键考虑事项

  • Claude 3.7 在响应中返回完整的思考内容spring-doc.cadn.net.cn

  • Claude 4 返回模型内部推理的摘要版本,以降低延迟并保护敏感内容spring-doc.cadn.net.cn

  • 思考Tokens是可计费的,作为输出Tokens的一部分(即使在响应中并非全部可见)spring-doc.cadn.net.cn

  • 交错思考仅在 Claude 4 模型上可用,并且需要使用测试版头 interleaved-thinking-2025-05-14spring-doc.cadn.net.cn

工具集成与交错思考

Claude 4 模型支持工具使用过程中的交错思考,允许模型在调用工具时进行推理。spring-doc.cadn.net.cn

当前的Spring AI 实现支持单独的基本思维和工具使用,但尚未支持在多次工具调用间进行交错思维(即思维跨越多个工具调用持续进行)。spring-doc.cadn.net.cn

在了解工具使用过程中的交错思考方法时,请参阅Anthropic 文档spring-doc.cadn.net.cn

非流式示例

如何使用ChatClient API 在非流式请求中启用思考:<br />spring-doc.cadn.net.cn

ChatClient chatClient = ChatClient.create(chatModel);

// For Claude 3.7 Sonnet - explicit thinking configuration required
ChatResponse response = chatClient.prompt()
    .options(AnthropicChatOptions.builder()
        .model("claude-3-7-sonnet-latest")
        .temperature(1.0)  // Temperature should be set to 1 when thinking is enabled
        .maxTokens(8192)
        .thinking(AnthropicApi.ThinkingType.ENABLED, 2048)  // Must be ≥1024 && < max_tokens
        .build())
    .user("Are there an infinite number of prime numbers such that n mod 4 == 3?")
    .call()
    .chatResponse();

// For Claude 4 models - thinking is enabled by default
ChatResponse response4 = chatClient.prompt()
    .options(AnthropicChatOptions.builder()
        .model("claude-opus-4-0")
        .maxTokens(8192)
        // No explicit thinking configuration needed
        .build())
    .user("Are there an infinite number of prime numbers such that n mod 4 == 3?")
    .call()
    .chatResponse();

// Process the response which may contain thinking content
for (Generation generation : response.getResults()) {
    AssistantMessage message = generation.getOutput();
    if (message.getText() != null) {
        // Regular text response
        System.out.println("Text response: " + message.getText());
    }
    else if (message.getMetadata().containsKey("signature")) {
        // Thinking content
        System.out.println("Thinking: " + message.getMetadata().get("thinking"));
        System.out.println("Signature: " + message.getMetadata().get("signature"));
    }
}

流式示例

您也可以使用带有流式响应的思考:<br>spring-doc.cadn.net.cn

ChatClient chatClient = ChatClient.create(chatModel);

// For Claude 3.7 Sonnet - explicit thinking configuration
Flux<ChatResponse> responseFlux = chatClient.prompt()
    .options(AnthropicChatOptions.builder()
        .model("claude-3-7-sonnet-latest")
        .temperature(1.0)
        .maxTokens(8192)
        .thinking(AnthropicApi.ThinkingType.ENABLED, 2048)
        .build())
    .user("Are there an infinite number of prime numbers such that n mod 4 == 3?")
    .stream();

// For Claude 4 models - thinking is enabled by default
Flux<ChatResponse> responseFlux4 = chatClient.prompt()
    .options(AnthropicChatOptions.builder()
        .model("claude-opus-4-0")
        .maxTokens(8192)
        // No explicit thinking configuration needed
        .build())
    .user("Are there an infinite number of prime numbers such that n mod 4 == 3?")
    .stream();

// For streaming, you might want to collect just the text responses
String textContent = responseFlux.collectList()
    .block()
    .stream()
    .map(ChatResponse::getResults)
    .flatMap(List::stream)
    .map(Generation::getOutput)
    .map(AssistantMessage::getText)
    .filter(text -> text != null && !text.isBlank())
    .collect(Collectors.joining());

工具使用集成

Claude 4 模型集成了思考和工具使用能力:spring-doc.cadn.net.cn

  • Claude 3.7 子君: 支持思考和工具使用,但它们独立运作,并且需要更多的显式配置spring-doc.cadn.net.cn

  • Claude 4 模型: 在工具交互过程中自然地结合思考和工具使用,提供更深的推理spring-doc.cadn.net.cn

使用Thinking的优势

思考功能提供了几种优势:spring-doc.cadn.net.cn

  1. 透明性:查看模型的推理过程及其结论是如何得出的spring-doc.cadn.net.cn

  2. 调试: 识别模型可能存在的逻辑错误spring-doc.cadn.net.cn

  3. 教育: 使用逐步推理作为教学工具spring-doc.cadn.net.cn

  4. 复杂问题解决能力:在数学、逻辑和推理任务上获得更好的结果spring-doc.cadn.net.cn

注意启用思考功能需要更高的Tokens预算,因为思考过程本身会消耗您分配的Tokens。spring-doc.cadn.net.cn

工具/函数调用

您可以通过AnthropicChatModel注册自定义Java工具,并让Anthropic Claude模型智能地选择输出一个包含调用已注册函数参数的JSON对象。 这是一种强大的技术,可以将LLM能力与外部工具和API连接起来。 更多关于工具调用的内容,请参阅相关文档。spring-doc.cadn.net.cn

多模态

多模态指的是模型同时理解并处理来自多种源的信息的能力,包括文本、PDF、图像和数据格式。spring-doc.cadn.net.cn

图片

目前,Anthropic Claude 3 支持 base64 源类型用于 images,以及 image/jpegimage/pngimage/gifimage/webp 媒体类型。 请查阅 视觉指南 以获取更多信息。 Anthropic Claude 3.5 Sonnet 还支持 pdf 源类型用于 application/pdf 文件。spring-doc.cadn.net.cn

Spring AI的Message接口通过引入Media类型支持多模态AI模型。 这种类型包含消息中媒体附件的数据和信息,使用Spring的org.springframework.util.MimeType和一个java.lang.Object来承载原始媒体数据。spring-doc.cadn.net.cn

以下是一个从AnthropicChatModelIT.java提取的简单代码示例,展示了用户文本与图片的结合。spring-doc.cadn.net.cn

var imageData = new ClassPathResource("/multimodal.test.png");

var userMessage = new UserMessage("Explain what do you see on this picture?",
        List.of(new Media(MimeTypeUtils.IMAGE_PNG, this.imageData)));

ChatResponse response = chatModel.call(new Prompt(List.of(this.userMessage)));

logger.info(response.getResult().getOutput().getContent());

它将输入multimodal.test.png图像:spring-doc.cadn.net.cn

Multimodal Test Image

<p>along with the text message &quot;Explain what do you see on this picture?&quot;, 和生成类似下面的响应:</p>spring-doc.cadn.net.cn

The image shows a close-up view of a wire fruit basket containing several pieces of fruit.
...

PDF

使用Sonnet 3.5,PDF支持(beta)已提供。 使用application/pdf媒体类型将PDF文件附加到消息中:spring-doc.cadn.net.cn

var pdfData = new ClassPathResource("/spring-ai-reference-overview.pdf");

var userMessage = new UserMessage(
        "You are a very professional document summarization specialist. Please summarize the given document.",
        List.of(new Media(new MimeType("application", "pdf"), pdfData)));

var response = this.chatModel.call(new Prompt(List.of(userMessage)));

样本控制器

创建一个新的Spring Boot项目,并在pom(或gradle)依赖中添加spring-ai-starter-model-anthropicspring-doc.cadn.net.cn

src/main/resources目录下添加一个application.properties文件,以启用并配置Anthropic聊天模型:spring-doc.cadn.net.cn

spring.ai.anthropic.api-key=YOUR_API_KEY
spring.ai.anthropic.chat.options.model=claude-3-5-sonnet-latest
spring.ai.anthropic.chat.options.temperature=0.7
spring.ai.anthropic.chat.options.max-tokens=450
请用你的Anthropic凭据替换api-key

这将创建一个AnthropicChatModel实现,你可以在你的类中注入。 以下是一个使用聊天模型进行文本生成的简单@Controller类示例。spring-doc.cadn.net.cn

@RestController
public class ChatController {

    private final AnthropicChatModel chatModel;

    @Autowired
    public ChatController(AnthropicChatModel chatModel) {
        this.chatModel = chatModel;
    }

    @GetMapping("/ai/generate")
    public Map generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return Map.of("generation", this.chatModel.call(message));
    }

    @GetMapping("/ai/generateStream")
	public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        return this.chatModel.stream(prompt);
    }
}

手动配置

The AnthropicChatModel 实现了ChatModelStreamingChatModel,并使用低级 AnthropicApi 客户端 连接到 Anthropic 服务。spring-doc.cadn.net.cn

将如下的spring-ai-anthropic依赖添加到项目中Maven的pom.xml文件中:spring-doc.cadn.net.cn

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-anthropic</artifactId>
</dependency>

请将以下内容添加到您的Gradle build.gradle 构建文件中。spring-doc.cadn.net.cn

dependencies {
    implementation 'org.springframework.ai:spring-ai-anthropic'
}
请参阅依赖管理部分,将Spring AI BOM添加到您的构建文件中。

接下来,创建一个AnthropicChatModel 并用于文本生成:spring-doc.cadn.net.cn

var anthropicApi = new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));
var anthropicChatOptions = AnthropicChatOptions.builder()
            .model("claude-3-7-sonnet-20250219")
            .temperature(0.4)
            .maxTokens(200)
        .build()
var chatModel = AnthropicChatModel.builder().anthropicApi(anthropicApi)
                .defaultOptions(anthropicChatOptions).build();

ChatResponse response = this.chatModel.call(
    new Prompt("Generate the names of 5 famous pirates."));

// Or with streaming responses
Flux<ChatResponse> response = this.chatModel.stream(
    new Prompt("Generate the names of 5 famous pirates."));

The AnthropicChatOptions 提供了聊天请求的配置信息。 The AnthropicChatOptions.Builder 是流畅选项构建器。spring-doc.cadn.net.cn

低级 AnthropicApi 客户端

The AnthropicApi 提供了一个轻量级的 Java 客户端用于 Anthropic Message API spring-doc.cadn.net.cn

以下类图说明了AnthropicApi聊天接口和构建块:spring-doc.cadn.net.cn

AnthropicApi Chat API Diagram
AnthropicApi Event Model

这里是如何通过程序方式使用API的一个简单示例:spring-doc.cadn.net.cn

AnthropicApi anthropicApi =
    new AnthropicApi(System.getenv("ANTHROPIC_API_KEY"));

AnthropicMessage chatCompletionMessage = new AnthropicMessage(
        List.of(new ContentBlock("Tell me a Joke?")), Role.USER);

// Sync request
ResponseEntity<ChatCompletionResponse> response = this.anthropicApi
    .chatCompletionEntity(new ChatCompletionRequest(AnthropicApi.ChatModel.CLAUDE_OPUS_4_5.getValue(),
            List.of(this.chatCompletionMessage), null, 100, 0.8, false));

// Streaming request
Flux<StreamResponse> response = this.anthropicApi
    .chatCompletionStream(new ChatCompletionRequest(AnthropicApi.ChatModel.CLAUDE_OPUS_4_5.getValue(),
            List.of(this.chatCompletionMessage), null, 100, 0.8, true));

跟随AnthropicApi.java的JavaDoc以获得更多信息。spring-doc.cadn.net.cn

低级API示例