AS AgentScopeAPI 手册 / API Reference

DashScopeHttpClient

public class DashScopeHttpClient
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:65–985

用于DashScope API的HTTP 客户端。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 isEncryptionEnabled、call、stream、selectEndpoint、isMultimodalModel、requiresMultimodalApi。

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

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
PublicKeyResult记录record
承载 Public 键结果数据的记录类型。
Result of fetching a public key from DashScope API.
Builder类class
DashScopeHttpClient的构建器。
Builder for DashScopeHttpClient.
DashScopeHttpException类class
DashScope HTTP 异常,表示执行过程中的错误。
Exception thrown when DashScope HTTP operations fail.

字段摘要Field Summary

字段Field类型Type说明Description
DEFAULT_BASE_URL
staticfinal
String
用于DashScope API的默认基类 URL。
Default base URL for DashScope API.
TEXT_GENERATION_ENDPOINT
staticfinal
String
文本 GENERATION 端点字段。
Text generation API endpoint.
MULTIMODAL_GENERATION_ENDPOINT
staticfinal
String
多模态 GENERATION 端点字段。
Multimodal generation API endpoint.
PUBLIC_KEYS_ENDPOINT
staticfinal
String
PUBLIC 密钥端点字段。
Public keys API endpoint.

构造器摘要Constructor Summary

构造器Constructor说明Description
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey)
创建新的DashScopeHttpClient。
Create a new DashScopeHttpClient.
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey, Collection<String> userMultimodalPatterns)
初始化 `DashScopeHttpClient` 实例。
Create a new DashScopeHttpClient with user-supplied multimodal model patterns.
public DashScopeHttpClient(String apiKey, String baseUrl)
创建新的DashScopeHttpClient。
Create a new DashScopeHttpClient.
public DashScopeHttpClient(String apiKey, String baseUrl, String publicKeyId, String publicKey)
创建新的DashScopeHttpClient 使用默认传输层来自工厂。
Create a new DashScopeHttpClient with default transport from factory.
public DashScopeHttpClient(String apiKey)
创建新的DashScopeHttpClient 使用默认传输层和基类 URL。
Create a new DashScopeHttpClient with default transport and base URL.

方法摘要Method Summary

方法Method说明Description
public boolean isEncryptionEnabled()
判断是否 `isEncryptionEnabled`。
Check if encryption is enabled.
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.
public 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.
public String selectEndpoint(String modelName)
设置选择端点。
Select the appropriate API endpoint based on model name.
public String selectEndpoint(String modelName, EndpointType endpointType)
执行选择端点相关操作。
Select the appropriate API endpoint based on model name and endpoint type.
public static boolean isMultimodalModel(String modelName)
static
判断是否多模态模型。
Check if a model is a multimodal model that requires the multimodal-generation API.
public boolean requiresMultimodalApi(String modelName)
设置该参数。
Check if a model requires the multimodal API.
public boolean requiresMultimodalApi(String modelName, EndpointType endpointType)
执行 `requiresMultimodalApi` 方法。
Check if a model requires the multimodal API based on the specified endpoint type.
public static PublicKeyResult fetchPublicKey(String apiKey, String baseUrl, HttpTransport transport)
static
执行 `fetchPublicKey` 方法。
Fetch the latest RSA public key from DashScope API.
public String getBaseUrl()
获取基类 URL。
Get the base URL.
public static Builder builder()
static
创建用于DashScopeHttpClient的构建器。
Create a new builder for DashScopeHttpClient.

字段详情Field Detail

DEFAULT_BASE_URL

public static final String DEFAULT_BASE_URL
staticfinal

用于DashScope API的默认基类 URL。

Default base URL for DashScope API.

源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:70

TEXT_GENERATION_ENDPOINT

public static final String TEXT_GENERATION_ENDPOINT
staticfinal

文本 GENERATION 端点字段。声明为 public static final String TEXT_GENERATION_ENDPOINT。

Text generation API endpoint.

源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:73–74

MULTIMODAL_GENERATION_ENDPOINT

public static final String MULTIMODAL_GENERATION_ENDPOINT
staticfinal

多模态 GENERATION 端点字段。声明为 public static final String MULTIMODAL_GENERATION_ENDPOINT。

Multimodal generation API endpoint.

源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:77–78

PUBLIC_KEYS_ENDPOINT

public static final String PUBLIC_KEYS_ENDPOINT
staticfinal

PUBLIC 密钥端点字段。声明为 public static final String PUBLIC_KEYS_ENDPOINT。

Public keys API endpoint.

源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:81

构造器详情Constructor Detail

DashScopeHttpClient

public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey)

创建新的DashScopeHttpClient。

Create a new DashScopeHttpClient.

参数Parameters
名称Name类型Type说明Description
transportHttpTransportHTTP 传输层到使用。the HTTP transport to use
apiKeyStringDashScope API 密钥。the DashScope API key
baseUrlString基类 URL(类型 `String`)。the base URL (null for default)
publicKeyIdStringpublic 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption)
publicKeyStringpublic 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption)
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:99–106

DashScopeHttpClient

public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey, Collection<String> userMultimodalPatterns)

初始化 DashScopeHttpClient 实例。

Create a new DashScopeHttpClient with user-supplied multimodal model patterns.

参数Parameters
名称Name类型Type说明Description
transportHttpTransportHTTP 传输层到使用。the HTTP transport to use
apiKeyStringDashScope API 密钥。the DashScope API key
baseUrlString基类 URL(类型 `String`)。the base URL (null for default)
publicKeyIdStringpublic 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption)
publicKeyStringpublic 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption)
userMultimodalPatternsCollection<String>用户多模态 Patterns(类型 `Collection`)。case-insensitive substring patterns that extend the built-in multimodal model detection (null or empty to disable)
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:119–135

DashScopeHttpClient

public DashScopeHttpClient(String apiKey, String baseUrl)

创建新的DashScopeHttpClient。

Create a new DashScopeHttpClient.

参数Parameters
名称Name类型Type说明Description
apiKeyStringDashScope API 密钥。the DashScope API key
baseUrlString基类 URL(类型 `String`)。the base URL (null for default)
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:153–155

DashScopeHttpClient

public DashScopeHttpClient(String apiKey, String baseUrl, String publicKeyId, String publicKey)

创建新的DashScopeHttpClient 使用默认传输层来自工厂。

Create a new DashScopeHttpClient with default transport from factory.

参数Parameters
名称Name类型Type说明Description
apiKeyStringDashScope API 密钥。the DashScope API key
baseUrlString基类 URL(类型 `String`)。the base URL (null for default)
publicKeyIdStringpublic 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption)
publicKeyStringpublic 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption)
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:168–171

DashScopeHttpClient

public DashScopeHttpClient(String apiKey)

创建新的DashScopeHttpClient 使用默认传输层和基类 URL。

Create a new DashScopeHttpClient with default transport and base URL.

参数Parameters
名称Name类型Type说明Description
apiKeyStringDashScope API 密钥。the DashScope API key
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:178–180

方法详情Method Detail

isEncryptionEnabled

public boolean isEncryptionEnabled()

判断是否 isEncryptionEnabled。

Check if encryption is enabled.

返回Returns boolean
返回布尔值,表示判断结果。true if both publicKeyId and publicKey are set
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:187–192

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.

参数Parameters
名称Name类型Type说明Description
requestDashScopeRequestDashScope 请求。the DashScope request
additionalHeadersMap<String, String>additional 请求头(类型 `Map`)。additional HTTP headers to merge (may be null)
additionalBodyParamsMap<String, Object>additional 正文参数(类型 `Map`)。additional body parameters to merge (may be null)
additionalQueryParamsMap<String, String>additional 查询参数(类型 `Map`)。additional query parameters to append (may be null)
返回Returns DashScopeResponse
DashScope 响应。the DashScope response
抛出Throws
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:204–266

stream

public 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.

参数Parameters
名称Name类型Type说明Description
requestDashScopeRequestDashScope 请求。the DashScope request
additionalHeadersMap<String, String>additional 请求头(类型 `Map`)。additional HTTP headers to merge (may be null)
additionalBodyParamsMap<String, Object>additional 正文参数(类型 `Map`)。additional body parameters to merge (may be null)
additionalQueryParamsMap<String, String>additional 查询参数(类型 `Map`)。additional query parameters to append (may be null)
返回Returns Flux<DashScopeResponse>
返回Flux。a Flux of DashScope responses (one per SSE event)
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:277–349

selectEndpoint

public String selectEndpoint(String modelName)

设置选择端点。

Select the appropriate API endpoint based on model name.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称。the model name
返回Returns String
API 端点路径。the API endpoint path
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:359–361

selectEndpoint

public String selectEndpoint(String modelName, EndpointType endpointType)

执行选择端点相关操作。

Select the appropriate API endpoint based on model name and endpoint type.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称。the model name
endpointTypeEndpointType端点类型(类型 `EndpointType`)。the endpoint type to use (AUTO for automatic detection)
返回Returns String
API 端点路径。the API endpoint path
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:383–402

isMultimodalModel

public static boolean isMultimodalModel(String modelName)
static

判断是否多模态模型。

Check if a model is a multimodal model that requires the multimodal-generation API.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称。the model name
返回Returns boolean
返回布尔值,表示判断结果。true if the model is a multimodal model
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:432–453

requiresMultimodalApi

public boolean requiresMultimodalApi(String modelName)

设置该参数。

Check if a model requires the multimodal API.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称。the model name
返回Returns boolean
返回布尔值,表示判断结果。true if the model requires multimodal API
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:463–465

requiresMultimodalApi

public boolean requiresMultimodalApi(String modelName, EndpointType endpointType)

执行 requiresMultimodalApi 方法。

Check if a model requires the multimodal API based on the specified endpoint type.

参数Parameters
名称Name类型Type说明Description
modelNameString模型名称。the model name
endpointTypeEndpointType端点类型到使用。the endpoint type to use
返回Returns boolean
返回布尔值,表示判断结果。true if the model requires multimodal API
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:474–483

fetchPublicKey

public static PublicKeyResult fetchPublicKey(String apiKey, String baseUrl, HttpTransport transport)
static

执行 fetchPublicKey 方法。

Fetch the latest RSA public key from DashScope API.

参数Parameters
名称Name类型Type说明Description
apiKeyStringDashScope API 密钥。the DashScope API key
baseUrlString基类 URL(类型 `String`)。the base URL (null for default)
transportHttpTransportHTTP 传输层到使用。the HTTP transport to use
返回Returns PublicKeyResult
返回PublicKeyResult。PublicKeyResult containing the public key ID and public key
抛出Throws
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:521–569

getBaseUrl

public String getBaseUrl()

获取基类 URL。

Get the base URL.

返回Returns String
基类 URL。the base URL
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:803–805

builder

public static Builder builder()
static

创建用于DashScopeHttpClient的构建器。

Create a new builder for DashScopeHttpClient.

返回Returns Builder
一种新的构建器实例。a new Builder instance
源码Source io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:812–814

嵌套类详情Nested Class Detail

PublicKeyResult

public record PublicKeyResult(String publicKeyId, String publicKey)

承载 Public 键结果数据的记录类型。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 publicKeyId、publicKey。

Result of fetching a public key from DashScope API.

Builder

public static class Builder

DashScopeHttpClient的构建器。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 transport、apiKey、baseUrl、publicKeyId、publicKey、multimodalModelPatterns。

Builder for DashScopeHttpClient.

DashScopeHttpException

public static class DashScopeHttpException extends RuntimeException

DashScope HTTP 异常,表示执行过程中的错误。位于 io.agentscope.extensions.model.dashscope 包,继承自 RuntimeException。核心成员包括 getStatusCode、getErrorCode、getResponseBody、DashScopeHttpException。

Exception thrown when DashScope HTTP operations fail.

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.