How about something like
if (token(ApiContext.class).isAssignableFrom(ctx.getBackendType())) {
Closeable api = ((ApiContext) unwrap()).getApi();
}
That's pretty much what BaseView does for unwrapApi, it seems [2].
Admittedly, to check for a *particular* API you'd need to figure out
what the generic type argument of ctx.getBackendType() is, I guess...
ap
[1]
https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/rest/ApiContext.java
[2]
https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/internal/BaseView.java#L70