← Credentials | Endpoint(中文) | Transport →
Default
If
Endpointis not specified, the SDK uses Automatic Endpoint Resolution.
import com.volcengine.ApiClient;
import com.volcengine.sign.Credentials;
public class SampleCode {
public static void main(String[] args) {
String region = "cn-beijing";
ApiClient apiClient = new ApiClient()
.setCredentials(Credentials.getEnvCredentials())
.setRegion(region)
.setEndpoint("<example>.<regionId>.volcengineapi.com");
}
}import com.volcengine.ApiClient;
import com.volcengine.sign.Credentials;
public class SampleCode {
public static void main(String[] args) {
String regionId = "cn-beijing";
ApiClient apiClient = new ApiClient()
.setCredentials(Credentials.getEnvCredentials())
.setRegion(regionId);
}
}Volcengine provides a flexible endpoint resolution mechanism. The SDK automatically builds the endpoint based on service name and region, and supports DualStack.
-
Whether the region is in the bootstrap list
Built-in list:
./volcengine-java-sdk-core/src/main/java/com/volcengine/endpoint/DefaultEndpointProvider.java#BOOTSTRAP_REGION.Only predefined regions (e.g.,
cn-beijing-autodriving,ap-southeast-2) or user-configured regions are auto-resolved; others fall back toopen.volcengineapi.com.You can extend the list via env var
VOLC_BOOTSTRAP_REGION_LIST_CONForcustomBootstrapRegion. -
DualStack support (IPv6)
Enable via
setUseDualStack(true)or env varVOLC_ENABLE_DUALSTACK=true. Priority:useDualStack>VOLC_ENABLE_DUALSTACK.When enabled, the suffix changes from
volcengineapi.comtovolcengine-api.com. -
Construct endpoint based on service name and region
- Global services (e.g.,
CDN,IAM):<service>.volcengineapi.com(orvolcengine-api.comwhen DualStack is enabled). Example:cdn.volcengineapi.com. - Regional services (e.g.,
ECS,RDS):<service>.<region>.volcengineapi.comis used as the default endpoint. Example:ecs.cn-beijing.volcengineapi.com.
- Global services (e.g.,
import com.volcengine.ApiClient;
import com.volcengine.sign.Credentials;
import java.util.HashSet;
public class SampleCode {
public static void main(String[] args) {
String regionId = "cn-beijing";
ApiClient apiClient = new ApiClient()
.setCredentials(Credentials.getEnvCredentials())
.setRegion(regionId)
.setUseDualStack(true)
.setCustomBootstrapRegion(new HashSet<String>() {{
add("custom_example_region1");
add("custom_example_region2");
}});
}
}Automatic endpoint resolution places the service and region in the endpoint host (for example {service}.{region}.volcengineapi.com). To prevent a region or service from redirecting the request to a different host (SSRF), the SDK validates both values before any host is built. This applies to the default resolver, the standard resolver and any custom EndpointResolver.
Rules: a non-empty region or service must be a single valid host name label:
- only ASCII letters, digits,
-and_; - starts with a letter;
- does not end with
-or_.
null and the empty string are not covered by this check and keep the existing handling of each entry point; a whitespace-only string (such as " ") is not empty and is rejected. Values such as cn-beijing@127.0.0.1, cn/beijing, evil.com# or x:443 are rejected (. is not allowed either).
When and where it applies:
- Client requests: when no endpoint is set,
ResolveEndpointInterceptorvalidates before callingEndpointResolver#endpointFor(including a custom resolver set withsetEndpointResolver(...)). This interceptor runs before the request is built and signed, so a request that fails validation is neither signed nor sent. UniversalApi(doCall/doCallWithHttpInfo): when no endpoint is set, the service name of theUniversalRequestand the region of theApiClientare validated before the service name is written into the request path.- Calling
DefaultEndpointProvider#endpointFororStandardEndpointProvider#endpointFordirectly also validates, and throwsEndpointValidationExceptiondirectly.StandardEndpointProviderruns its existing non-blank check first (blank values still fail withregion must not be null./service must not be null.), then this validation. - RDS IAM auth token (
ConnectUtils.buildAuthToken): when no endpoint is set, the endpoint is resolved withStandardEndpointProvider, and an invalid region throwsEndpointValidationException. - SSO credentials: the region is validated before
cloudidentity-oauth.{region}.volces.com/cloudidentity-portal.{region}.volces.comis called. Anull, empty or whitespace-only configured region falls back tocn-beijing; any other value is trimmed first and the trimmed value is validated. On failure, retrieving the credentials fails with anApiExceptionwhose message containsInvalidRegion.
When it is skipped: when a non-blank endpoint is set on the ApiClient with setEndpoint(...), neither ResolveEndpointInterceptor nor UniversalApi runs this validation and the endpoint is used as is; the explicitly configured endpoint itself is not restricted by these rules.
Errors:
- A validation failure throws
com.volcengine.endpoint.EndpointValidationException, which extendsIllegalArgumentException.getCode()returns the error codeInvalidRegionorInvalidService(constantsEndpointValidation.ERR_CODE_INVALID_REGION/EndpointValidation.ERR_CODE_INVALID_SERVICE),getErrorMessage()returns the message without the code, andgetMessage()looks likeInvalidRegion: invalid region "...".... When both values are invalid, the service is reported first. - When triggered by an API call (including
UniversalApi), it is wrapped incom.volcengine.ApiException:getCode()is400,getCause()is the originalEndpointValidationException, andgetResponseMetadata().getError().getCode()isInvalidRegion/InvalidService. No request was sent, so there is no RequestId. - Synchronous calls throw this
ApiException; asynchronous calls (such asdescribeRegionsAsync) deliver it toApiCallback#onFailurewith astatusCodeargument of0, so usee.getCode()for the status code.
import com.volcengine.ApiClient;
import com.volcengine.ApiException;
import com.volcengine.ecs.EcsApi;
import com.volcengine.ecs.model.DescribeRegionsRequest;
import com.volcengine.endpoint.EndpointValidation;
import com.volcengine.model.Error;
import com.volcengine.sign.Credentials;
public class SampleCode {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient()
.setCredentials(Credentials.getEnvCredentials())
.setRegion("cn-beijing@127.0.0.1"); // invalid region
EcsApi api = new EcsApi(apiClient);
try {
api.describeRegions(new DescribeRegionsRequest());
} catch (ApiException e) {
Error error = e.getResponseMetadata() == null ? null : e.getResponseMetadata().getError();
if (e.getCode() == 400 && error != null
&& EndpointValidation.ERR_CODE_INVALID_REGION.equals(error.getCode())) {
// The request was neither signed nor sent.
System.out.println("invalid region: " + error.getMessage());
}
}
}
}Behavior change:
- On the client request path, a region with leading or trailing whitespace (such as
"cn-beijing ") is no longer accepted and fails withInvalidRegion. Previously the SDK did not reject it, but the request was always signed with the untrimmed value, so the server rejected such requests anyway. Remove the surrounding whitespace from the region. - The region configured for SSO credentials is still trimmed first, then validated.
- The
ApiExceptionwrapping above applies only to failures of this validation. Once a value passes it, exceptions thrown by the resolver itself (for exampleInvalidRegion: invalid region [...]for a well-formed but unsupported region, orServiceNotFound: ...for an unregistered service, fromStandardEndpointProvider) reach the caller unchanged, as before, and are not wrapped. - New public validation helpers:
EndpointValidation.validateRegion(String),EndpointValidation.validateService(String),EndpointValidation.validateServiceAndRegion(String, String), the constantsEndpointValidation.ERR_CODE_INVALID_REGIONandEndpointValidation.ERR_CODE_INVALID_SERVICE, andEndpointValidationException(getCode(),getErrorMessage(),toApiException()). CustomEndpointResolverimplementations can reuse them.
| Global service | DualStack | Format |
|---|---|---|
| Yes | Yes | {Service}.volcengine-api.com |
| Yes | No | {Service}.volcengineapi.com |
| No | Yes | {Service}.{region}.volcengine-api.com |
| No | No | {Service}.{region}.volcengineapi.com |
Whether a service is global depends on the service itself and cannot be changed. See: ./volcengine-java-sdk-core/src/main/java/com/volcengine/endpoint/StandardEndpointProvider.java#SERVICE_INFOS.
import com.volcengine.ApiClient;
import com.volcengine.sign.Credentials;
import com.volcengine.endpoint.StandardEndpointProvider;
public class SampleCode {
public static void main(String[] args) {
String regionId = "cn-beijing";
ApiClient apiClient = new ApiClient()
.setCredentials(Credentials.getEnvCredentials())
.setEndpointResolver(new StandardEndpointProvider())
.setRegion(regionId)
.setUseDualStack(true);
}
}← Credentials | Endpoint(中文) | Transport →