diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClient.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClient.kt index 634e8f0..3d478c3 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClient.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClient.kt @@ -18,4 +18,17 @@ interface AnthropicClient { fun models(): ModelService fun beta(): BetaService + + /** + * Closes this client, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client is long-lived and + * usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default HTTP client + * automatically releases threads and connections if they remain idle, but if you are writing an + * application that needs to aggressively release unused resources, then you may call this + * method. + */ + fun close() } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsync.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsync.kt index bc9af30..c5dc2dc 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsync.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsync.kt @@ -18,4 +18,17 @@ interface AnthropicClientAsync { fun models(): ModelServiceAsync fun beta(): BetaServiceAsync + + /** + * Closes this client, relinquishing any underlying resources. + * + * This is purposefully not inherited from [AutoCloseable] because the client is long-lived and + * usually should not be synchronously closed via try-with-resources. + * + * It's also usually not necessary to call this method at all. the default HTTP client + * automatically releases threads and connections if they remain idle, but if you are writing an + * application that needs to aggressively release unused resources, then you may call this + * method. + */ + fun close() } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsyncImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsyncImpl.kt index 99adf09..11645b5 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsyncImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientAsyncImpl.kt @@ -52,4 +52,6 @@ constructor( override fun models(): ModelServiceAsync = models override fun beta(): BetaServiceAsync = beta + + override fun close() = clientOptions.httpClient.close() } diff --git a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientImpl.kt b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientImpl.kt index 7c44418..bbd28db 100644 --- a/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientImpl.kt +++ b/anthropic-java-core/src/main/kotlin/com/anthropic/client/AnthropicClientImpl.kt @@ -48,4 +48,6 @@ constructor( override fun models(): ModelService = models override fun beta(): BetaService = beta + + override fun close() = clientOptions.httpClient.close() }