diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/image/openai-image.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/image/openai-image.adoc index 0846515f3..d4f378ba9 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/image/openai-image.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/image/openai-image.adoc @@ -41,7 +41,9 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man === Image Generation Properties -The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Chat client. +==== Retry Properties + +The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Image client. [cols="3,5,1"] |==== @@ -51,10 +53,11 @@ The prefix `spring.ai.retry` is used as the property prefix that lets you config | spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec. | spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5 | spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min. -| spring.ai.retry.on-client-errors | If true, do not throw a NonTransientAiException, and do not attempt retry for 4xx client error codes | false -| spring.ai.retry.on-http-codes | List of HTTP Error Code to include for retry | empty +| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false +| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty |==== +==== Connection Properties The prefix `spring.ai.openai` is used as the property prefix that lets you connect to OpenAI. @@ -65,6 +68,8 @@ The prefix `spring.ai.openai` is used as the property prefix that lets you conne | spring.ai.openai.api-key | The API Key | - |==== +==== Configuration Properties + The prefix `spring.ai.openai.image` is the property prefix that lets you configure the `ImageClient` implementation for OpenAI. [cols="3,5,1"] diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/mistralai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/mistralai-chat.adoc index 816685530..0df388c91 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/mistralai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/mistralai-chat.adoc @@ -49,7 +49,9 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man === Chat Properties -The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Chat client. +==== Retry Properties + +The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the Mistral AI Chat client. [cols="3,5,1"] |==== @@ -59,10 +61,12 @@ The prefix `spring.ai.retry` is used as the property prefix that lets you config | spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec. | spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5 | spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min. -| spring.ai.retry.on-client-errors | If true, do not throw a NonTransientAiException, and do not attempt retry for 4xx client error codes | false -| spring.ai.retry.on-http-codes | List of HTTP Error Code to include for retry | empty +| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false +| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty |==== +==== Connection Properties + The prefix `spring.ai.mistralai` is used as the property prefix that lets you connect to OpenAI. [cols="3,5,1"] @@ -73,6 +77,8 @@ The prefix `spring.ai.mistralai` is used as the property prefix that lets you co | spring.ai.mistralai.api-key | The API Key | - |==== +==== Configuration Properties + The prefix `spring.ai.mistralai.chat` is the property prefix that lets you configure the chat client implementation for MistralAI. [cols="3,5,1"] diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/openai-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/openai-chat.adoc index 63828c6d5..a9303495e 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/openai-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/openai-chat.adoc @@ -49,6 +49,8 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man === Chat Properties +==== Retry Properties + The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Chat client. [cols="3,5,1"] @@ -59,10 +61,12 @@ The prefix `spring.ai.retry` is used as the property prefix that lets you config | spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec. | spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5 | spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min. -| spring.ai.retry.on-client-errors | If true, do not throw a NonTransientAiException, and do not attempt retry for 4xx client error codes | false -| spring.ai.retry.on-http-codes | List of HTTP Error Code to include for retry | empty +| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false +| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty |==== +==== Connection Properties + The prefix `spring.ai.openai` is used as the property prefix that lets you connect to OpenAI. [cols="3,5,1"] @@ -73,6 +77,9 @@ The prefix `spring.ai.openai` is used as the property prefix that lets you conne | spring.ai.openai.api-key | The API Key | - |==== + +==== Configuration Properties + The prefix `spring.ai.openai.chat` is the property prefix that lets you configure the chat client implementation for OpenAI. [cols="3,5,1"] diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc index 3c0379eec..8cc14e642 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/mistralai-embeddings.adoc @@ -49,6 +49,24 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man === Embedding Properties +==== Retry Properties + +The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the Mistral AI Embedding client. + +[cols="3,5,1"] +|==== +| Property | Description | Default + +| spring.ai.retry.max-attempts | Maximum number of retry attempts. | 10 +| spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec. +| spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5 +| spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min. +| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false +| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty +|==== + +==== Connection Properties + The prefix `spring.ai.mistralai` is used as the property prefix that lets you connect to MistralAI. [cols="3,5,1"] @@ -59,6 +77,8 @@ The prefix `spring.ai.mistralai` is used as the property prefix that lets you co | spring.ai.mistralai.api-key | The API Key | - |==== +==== Configuration Properties + The prefix `spring.ai.mistralai.embedding` is property prefix that configures the `EmbeddingClient` implementation for MistralAI. [cols="3,5,1"] diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc index 57f19e66b..f61b1bf92 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/embeddings/openai-embeddings.adoc @@ -50,7 +50,9 @@ TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Man === Embedding Properties -The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Chat client. +==== Retry Properties + +The prefix `spring.ai.retry` is used as the property prefix that lets you configure the retry mechanism for the OpenAI Embedding client. [cols="3,5,1"] |==== @@ -60,8 +62,12 @@ The prefix `spring.ai.retry` is used as the property prefix that lets you config | spring.ai.retry.backoff.initial-interval | Initial sleep duration for the exponential backoff policy. | 2 sec. | spring.ai.retry.backoff.multiplier | Backoff interval multiplier. | 5 | spring.ai.retry.backoff.max-interval | Maximum backoff duration. | 3 min. +| spring.ai.retry.on-client-errors | If false, throw a NonTransientAiException, and do not attempt retry for `4xx` client error codes | false +| spring.ai.retry.exclude-on-http-codes | List of HTTP status codes that should not trigger a retry (e.g. to throw NonTransientAiException). | empty |==== +==== Connection Properties + The prefix `spring.ai.openai` is used as the property prefix that lets you connect to OpenAI. [cols="3,5,1"] @@ -72,6 +78,8 @@ The prefix `spring.ai.openai` is used as the property prefix that lets you conne | spring.ai.openai.api-key | The API Key | - |==== +==== Configuration Properties + The prefix `spring.ai.openai.embedding` is property prefix that configures the `EmbeddingClient` implementation for OpenAI. [cols="3,5,1"] diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryAutoConfiguration.java index c3659d65e..df0b43d23 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryAutoConfiguration.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryAutoConfiguration.java @@ -95,8 +95,8 @@ public class SpringAiRetryAutoConfiguration { throw new NonTransientAiException(message); } // Explicitly configured non-transient codes - if (!CollectionUtils.isEmpty(properties.getOnHttpCodes()) - && properties.getOnHttpCodes().contains(response.getStatusCode().value())) { + if (!CollectionUtils.isEmpty(properties.getExcludeOnHttpCodes()) + && properties.getExcludeOnHttpCodes().contains(response.getStatusCode().value())) { throw new NonTransientAiException(message); } throw new TransientAiException(message); diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryProperties.java index bbbd0f4e1..1f70659d4 100644 --- a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryProperties.java +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryProperties.java @@ -42,13 +42,17 @@ public class SpringAiRetryProperties { private Backoff backoff = new Backoff(); /** - * If true, do not throw a NonTransientAiException, and do not attempt retry for 4xx - * client error codes false by default. - * + * If false, throw a NonTransientAiException, and do not attempt retry for 4xx client + * error codes. False by default. If true, throw a TransientAiException, and attempt + * retry for 4xx client. */ private boolean onClientErrors = false; - private List onHttpCodes = new ArrayList<>(); + /** + * List of HTTP status codes that should not trigger a retry (e.g. throw + * NonTransientAiException). + */ + private List excludeOnHttpCodes = new ArrayList<>(); /** * Exponential Backoff properties. @@ -108,12 +112,12 @@ public class SpringAiRetryProperties { return this.backoff; } - public List getOnHttpCodes() { - return this.onHttpCodes; + public List getExcludeOnHttpCodes() { + return this.excludeOnHttpCodes; } - public void setOnHttpCodes(List onHttpCodes) { - this.onHttpCodes = onHttpCodes; + public void setExcludeOnHttpCodes(List onHttpCodes) { + this.excludeOnHttpCodes = onHttpCodes; } public boolean isOnClientErrors() { diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryPropertiesTests.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryPropertiesTests.java index 812edbbf2..eba635f59 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryPropertiesTests.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/retry/SpringAiRetryPropertiesTests.java @@ -40,7 +40,7 @@ public class SpringAiRetryPropertiesTests { assertThat(retryProperties.isOnClientErrors()).isFalse(); // do not retry // on 4xx // errors - assertThat(retryProperties.getOnHttpCodes()).isEmpty(); + assertThat(retryProperties.getExcludeOnHttpCodes()).isEmpty(); assertThat(retryProperties.getBackoff().getInitialInterval().toMillis()).isEqualTo(2000); assertThat(retryProperties.getBackoff().getMultiplier()).isEqualTo(5); assertThat(retryProperties.getBackoff().getMaxInterval().toMillis()).isEqualTo(3 * 60000); @@ -54,7 +54,7 @@ public class SpringAiRetryPropertiesTests { // @formatter:off "spring.ai.retry.max-attempts=100", "spring.ai.retry.on-client-errors=false", - "spring.ai.retry.on-http-codes=404,500", + "spring.ai.retry.exclude-on-http-codes=404,500", "spring.ai.retry.backoff.initial-interval=1000", "spring.ai.retry.backoff.multiplier=2", "spring.ai.retry.backoff.max-interval=60000" ) @@ -65,7 +65,7 @@ public class SpringAiRetryPropertiesTests { assertThat(retryProperties.getMaxAttempts()).isEqualTo(100); assertThat(retryProperties.isOnClientErrors()).isFalse(); - assertThat(retryProperties.getOnHttpCodes()).containsExactly(404, 500); + assertThat(retryProperties.getExcludeOnHttpCodes()).containsExactly(404, 500); assertThat(retryProperties.getBackoff().getInitialInterval().toMillis()).isEqualTo(1000); assertThat(retryProperties.getBackoff().getMultiplier()).isEqualTo(2); assertThat(retryProperties.getBackoff().getMaxInterval().toMillis()).isEqualTo(60000);