Interface Backend
-
- All Implemented Interfaces:
public interface BackendAn interface that represents adaptations required to support different backend AI services. Different backends may require different credentials, request headers, request authorization, request signatures, response handlers and endpoint URLs. Implementations of this interface may define the information and handling appropriate for each backend service.
When a backend is no longer needed, such as when the client it is associated with is closed and discarded, close must be called on the backend to ensure any resources it is using are released.
-
-
Method Summary
Modifier and Type Method Description abstract StringbaseUrl()Gets the backend service's base URL identifying the network address of the service that will be accessed by this backend. HttpRequestprepareRequest(HttpRequest request)Prepares the request for use by the backend service. HttpRequestauthorizeRequest(HttpRequest request)Authorizes the given request and returns the new authorized request. HttpResponseprepareResponse(HttpResponse response)Prepares the response returned by the backend service. BooleansupportsMessageThreads()Returns whether the backend service takes the threadfield of the Messages API.StringopenTelemetryProviderName()The gen_ai.provider.nameattribute of the OpenTelemetry spans of a client that uses this backend: the platform that serves the requests.Optional<String>openTelemetryPlatform()The platform of this backend in the instrumentation scope of the OpenTelemetry spans of a client that uses it: bedrockgives the spans the scopecom.anthropic.sdk.java.bedrock.abstract Unitclose()Closes any streams and releases any resources used by this backend. -
-
Method Detail
-
baseUrl
abstract String baseUrl()
Gets the backend service's base URL identifying the network address of the service that will be accessed by this backend.
The client builder adopts this as the client's base URL when the client is built; each request then carries its own base URL, which is what the transport uses.
-
prepareRequest
HttpRequest prepareRequest(HttpRequest request)
Prepares the request for use by the backend service. Changes may be made to the request to adapt it for backends other than the default Anthropic backend.
Changes may be made to the headers, path segments, query parameters, and body content to suit the requirements of the backend where they differ from the default Anthropic backend. All changes that may affect the resolution of the full URL for the request must be made by this method.
Changes specifically related to request authorization or signing should be performed by the implementation of authorizeRequest.
If no changes are required, the given request can be returned unchanged. This is the behavior of the default implementation.
-
authorizeRequest
HttpRequest authorizeRequest(HttpRequest request)
Authorizes the given request and returns the new authorized request. The URL of the request will be resolved fully before this method is called.
Changes will typically include the addition of authorization headers or signature headers. Other changes not directly related to authorization should be performed by prepareRequest.
If the request already carries authorization headers (e.g., added by an interceptor or set at the request level), implementations must return the request unchanged rather than fail, so that interceptors and per-request options can manage credentials themselves.
Where a backend does not require request authorization or other related changes to the request, the given HttpRequest may be returned unchanged. This is the behavior of the default implementation.
-
prepareResponse
HttpResponse prepareResponse(HttpResponse response)
Prepares the response returned by the backend service. This allows changes to be made to the response to adapt it for backend services other than the default Anthropic backend service. The adaptations make the response appear to come from that default Anthropic backend.
If no changes are required, the given response can be returned unchanged. This is the behavior of the default implementation.
-
supportsMessageThreads
Boolean supportsMessageThreads()
Returns whether the backend service takes the
threadfield of the Messages API.The default implementation returns
true, so the service answers for itself. Override it to returnfalsefor a service that is known to take no message threads.
-
openTelemetryProviderName
String openTelemetryProviderName()
The
gen_ai.provider.nameattribute of the OpenTelemetry spans of a client that uses this backend: the platform that serves the requests.aws.bedrockon Amazon Bedrock, including its Mantle endpoint,gcp.vertex_aion Vertex AI, andanthropicfor every other backend, because Anthropic runs the service each of them calls.
-
openTelemetryPlatform
Optional<String> openTelemetryPlatform()
The platform of this backend in the instrumentation scope of the OpenTelemetry spans of a client that uses it:
bedrockgives the spans the scopecom.anthropic.sdk.java.bedrock. Empty for a backend with no platform of its own, whose spans have the scopecom.anthropic.sdk.java.
-
-
-
-