类 DashScopeHttpClient
java.lang.Object
io.agentscope.core.model.DashScopeHttpClient
HTTP client for DashScope API.
This client handles communication with DashScope's text-generation and multimodal-generation APIs using the native DashScope protocol.
Features:
- Automatic API endpoint routing based on model name
- Synchronous and streaming request support
- SSE stream parsing
- JSON serialization/deserialization
API endpoints:
- Text generation: /api/v1/services/aigc/text-generation/generation
- Multimodal generation: /api/v1/services/aigc/multimodal-generation/generation
-
嵌套类概要
嵌套类修饰符和类型类说明static classBuilder for DashScopeHttpClient.static classException thrown when DashScope HTTP operations fail.static final recordResult of fetching a public key from DashScope API. -
字段概要
字段 -
构造器概要
构造器构造器说明DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey) Create a new DashScopeHttpClient.DashScopeHttpClient(String apiKey) Create a new DashScopeHttpClient with default transport and base URL.DashScopeHttpClient(String apiKey, String baseUrl) Create a new DashScopeHttpClient.DashScopeHttpClient(String apiKey, String baseUrl, String publicKeyId, String publicKey) Create a new DashScopeHttpClient with default transport from factory. -
方法概要
修饰符和类型方法说明static DashScopeHttpClient.Builderbuilder()Create a new builder for DashScopeHttpClient.call(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams) Make a synchronous API call with additional HTTP parameters.fetchPublicKey(String apiKey, String baseUrl, HttpTransport transport) Fetch the latest RSA public key from DashScope API.Get the base URL.booleanCheck if encryption is enabled.static booleanisMultimodalModel(String modelName) Check if a model is a multimodal model that requires the multimodal-generation API.booleanrequiresMultimodalApi(String modelName) Check if a model requires the multimodal API.booleanrequiresMultimodalApi(String modelName, EndpointType endpointType) Check if a model requires the multimodal API based on the specified endpoint type.selectEndpoint(String modelName) Select the appropriate API endpoint based on model name.selectEndpoint(String modelName, EndpointType endpointType) Select the appropriate API endpoint based on model name and endpoint type.reactor.core.publisher.Flux<DashScopeResponse> stream(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams) Make a streaming API call with additional HTTP parameters.
-
字段详细资料
-
DEFAULT_BASE_URL
Default base URL for DashScope API.- 另请参阅:
-
TEXT_GENERATION_ENDPOINT
Text generation API endpoint.- 另请参阅:
-
MULTIMODAL_GENERATION_ENDPOINT
Multimodal generation API endpoint.- 另请参阅:
-
PUBLIC_KEYS_ENDPOINT
Public keys API endpoint.- 另请参阅:
-
-
构造器详细资料
-
DashScopeHttpClient
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey) Create a new DashScopeHttpClient.- 参数:
transport- the HTTP transport to useapiKey- the DashScope API keybaseUrl- the base URL (null for default)publicKeyId- the RSA public key ID for encryption (null to disable encryption)publicKey- the RSA public key for encryption (Base64-encoded, null to disable encryption)
-
DashScopeHttpClient
Create a new DashScopeHttpClient.- 参数:
apiKey- the DashScope API keybaseUrl- the base URL (null for default)
-
DashScopeHttpClient
Create a new DashScopeHttpClient with default transport from factory.Uses
HttpTransportFactory.getDefault()for the transport, which provides automatic lifecycle management and cleanup on JVM shutdown.- 参数:
apiKey- the DashScope API keybaseUrl- the base URL (null for default)publicKeyId- the RSA public key ID for encryption (null to disable encryption)publicKey- the RSA public key for encryption (Base64-encoded, null to disable encryption)
-
DashScopeHttpClient
Create a new DashScopeHttpClient with default transport and base URL.- 参数:
apiKey- the DashScope API key
-
-
方法详细资料
-
isEncryptionEnabled
public boolean isEncryptionEnabled()Check if encryption is enabled.- 返回:
- true if both publicKeyId and publicKey are set
-
call
public DashScopeResponse call(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams) Make a synchronous API call with additional HTTP parameters.- 参数:
request- the DashScope requestadditionalHeaders- additional HTTP headers to merge (may be null)additionalBodyParams- additional body parameters to merge (may be null)additionalQueryParams- additional query parameters to append (may be null)- 返回:
- the DashScope response
- 抛出:
DashScopeHttpClient.DashScopeHttpException- if the request fails
-
stream
public reactor.core.publisher.Flux<DashScopeResponse> stream(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams) Make a streaming API call with additional HTTP parameters.- 参数:
request- the DashScope requestadditionalHeaders- additional HTTP headers to merge (may be null)additionalBodyParams- additional body parameters to merge (may be null)additionalQueryParams- additional query parameters to append (may be null)- 返回:
- a Flux of DashScope responses (one per SSE event)
-
selectEndpoint
Select the appropriate API endpoint based on model name.This is a convenience method that uses
EndpointType.AUTOfor automatic detection.- 参数:
modelName- the model name- 返回:
- the API endpoint path
-
selectEndpoint
Select the appropriate API endpoint based on model name and endpoint type.Routing logic:
- If endpointType is
EndpointType.TEXT→ text generation API - If endpointType is
EndpointType.MULTIMODAL→ multimodal API - If endpointType is
EndpointType.AUTO:- Models starting with "qvq" → multimodal API
- Models containing "-vl" → multimodal API
- Models containing "-asr" → multimodal API
- Models starting with "qwen3.5" → multimodal API
- Models starting with "qwen3.6" → multimodal API
- All other models → text generation API
- 参数:
modelName- the model nameendpointType- the endpoint type to use (AUTO for automatic detection)- 返回:
- the API endpoint path
- If endpointType is
-
isMultimodalModel
Check if a model is a multimodal model that requires the multimodal-generation API.Supported multimodal model patterns (used when endpointType is AUTO):
- Models starting with "qvq" (e.g., qvq-72b, qvq-max)
- Models containing "-vl" (e.g., qwen-vl-plus, qwen3-vl-max)
- Models containing "-asr" (e.g., qwen3-asr-flash)
- Models starting with "qwen3.5"/"qwen3.6" (e.g., qwen3.5-plus, qwen3.5-flash, qwen3.6-plus)
- Models containing "kimi-k2.5"/"kimi-k2.6" (e.g., kimi-k2.6, kimi/kimi-k2.5)
- 参数:
modelName- the model name- 返回:
- true if the model is a multimodal model
-
requiresMultimodalApi
Check if a model requires the multimodal API.This is a convenience method that uses
EndpointType.AUTOfor automatic detection.- 参数:
modelName- the model name- 返回:
- true if the model requires multimodal API
-
requiresMultimodalApi
Check if a model requires the multimodal API based on the specified endpoint type.- 参数:
modelName- the model nameendpointType- the endpoint type to use- 返回:
- true if the model requires multimodal API
-
fetchPublicKey
public static DashScopeHttpClient.PublicKeyResult fetchPublicKey(String apiKey, String baseUrl, HttpTransport transport) Fetch the latest RSA public key from DashScope API.This method calls the DashScope public keys API to retrieve the latest public key and key ID for encryption purposes.
- 参数:
apiKey- the DashScope API keybaseUrl- the base URL (null for default)transport- the HTTP transport to use- 返回:
- PublicKeyResult containing the public key ID and public key
- 抛出:
DashScopeHttpClient.DashScopeHttpException- if the request fails
-
getBaseUrl
Get the base URL.- 返回:
- the base URL
-
builder
Create a new builder for DashScopeHttpClient.- 返回:
- a new Builder instance
-